editors/CodeFileEditor.py
branchwxPython4
changeset 3303 0ffb41625592
parent 2739 7278186a2083
child 3590 09dad7f00c36
equal deleted inserted replaced
3302:c89fc366bebd 3303:0ffb41625592
   289             self.SetLineState(line, 0)
   289             self.SetLineState(line, 0)
   290 
   290 
   291         doc_end_pos = self.GetLength()
   291         doc_end_pos = self.GetLength()
   292         for section in self.Controler.SECTIONS_NAMES:
   292         for section in self.Controler.SECTIONS_NAMES:
   293             section_comments = self.SectionsComments[section]
   293             section_comments = self.SectionsComments[section]
   294             start_pos = self.FindText(0, doc_end_pos, section_comments["comment"])
   294             start_pos, end_pos = self.FindText(0, doc_end_pos, section_comments["comment"])
   295             end_pos = start_pos + len(section_comments["comment"])
   295             self.StartStyling(start_pos)
   296             self.StartStyling(start_pos, 0xff)
       
   297             self.SetStyling(end_pos - start_pos, STC_CODE_SECTION)
   296             self.SetStyling(end_pos - start_pos, STC_CODE_SECTION)
   298             self.SetLineState(self.LineFromPosition(start_pos), 1)
   297             self.SetLineState(self.LineFromPosition(start_pos), 1)
   299 
   298 
   300         self.StartStyling(end_pos, 0x00)
   299         self.StartStyling(end_pos)
   301         self.SetStyling(doc_end_pos - end_pos, stc.STC_STYLE_DEFAULT)
   300         self.SetStyling(doc_end_pos - end_pos, stc.STC_STYLE_DEFAULT)
   302 
   301 
   303     def DoGetBestSize(self):
   302     def DoGetBestSize(self):
   304         return self.ParentWindow.GetPanelBestSize()
   303         return self.ParentWindow.GetBestSize()
   305 
   304 
   306     def RefreshModel(self):
   305     def RefreshModel(self):
   307         text = self.GetText()
   306         text = self.GetText()
   308         parts = {}
   307         parts = {}
   309         for section in self.Controler.SECTIONS_NAMES:
   308         for section in self.Controler.SECTIONS_NAMES:
   595                 highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
   594                 highlight_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] + 1
   596             if end[0] == 0:
   595             if end[0] == 0:
   597                 highlight_end_pos = end[1] + 1
   596                 highlight_end_pos = end[1] + 1
   598             else:
   597             else:
   599                 highlight_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] + 2
   598                 highlight_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] + 2
   600             self.StartStyling(highlight_start_pos, 0xff)
   599             self.StartStyling(highlight_start_pos)
   601             self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
   600             self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
   602             self.StartStyling(highlight_end_pos, 0x00)
   601             self.StartStyling(highlight_end_pos)
   603             self.SetStyling(len(self.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)
   602             self.SetStyling(len(self.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)
   604 
   603 
   605 
   604 
   606 # -------------------------------------------------------------------------------
   605 # -------------------------------------------------------------------------------
   607 #                         Helper for VariablesGrid values
   606 #                         Helper for VariablesGrid values
   612         wx.grid.GridCellTextEditor.__init__(self)
   611         wx.grid.GridCellTextEditor.__init__(self)
   613 
   612 
   614 
   613 
   615 class ClassGridCellEditor(wx.grid.GridCellChoiceEditor):
   614 class ClassGridCellEditor(wx.grid.GridCellChoiceEditor):
   616     def __init__(self, table, row, col):
   615     def __init__(self, table, row, col):
   617         wx.grid.GridCellChoiceEditor.__init__(self)
   616         wx.grid.GridCellChoiceEditor.__init__(self,["input","memory","output"])
   618         self.SetParameters("input,memory,output")
       
   619 
   617 
   620 
   618 
   621 class VariablesTable(CustomTable):
   619 class VariablesTable(CustomTable):
   622     __defaultColumnType = dict(
   620     __defaultColumnType = dict(
   623         [(name, AllGridCellEditor) for name in
   621         [(name, AllGridCellEditor) for name in
   676         main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
   674         main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
   677         main_sizer.AddGrowableCol(1)
   675         main_sizer.AddGrowableCol(1)
   678         main_sizer.AddGrowableRow(0)
   676         main_sizer.AddGrowableRow(0)
   679 
   677 
   680         controls_sizer = wx.BoxSizer(wx.VERTICAL)
   678         controls_sizer = wx.BoxSizer(wx.VERTICAL)
   681         main_sizer.AddSizer(controls_sizer, border=5, flag=wx.ALL)
   679         main_sizer.Add(controls_sizer, border=5, flag=wx.ALL)
   682 
   680 
   683         for name, bitmap, help in [
   681         for name, bitmap, help in [
   684                 ("AddVariableButton", "add_element", _("Add variable")),
   682                 ("AddVariableButton", "add_element", _("Add variable")),
   685                 ("DeleteVariableButton", "remove_element", _("Remove variable")),
   683                 ("DeleteVariableButton", "remove_element", _("Remove variable")),
   686                 ("UpVariableButton", "up", _("Move variable up")),
   684                 ("UpVariableButton", "up", _("Move variable up")),
   687                 ("DownVariableButton", "down", _("Move variable down"))]:
   685                 ("DownVariableButton", "down", _("Move variable down"))]:
   688             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   686             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
   689                                                     size=wx.Size(28, 28), style=wx.NO_BORDER)
   687                                                     size=wx.Size(28, 28), style=wx.NO_BORDER)
   690             button.SetToolTipString(help)
   688             button.SetToolTip(help)
   691             setattr(self, name, button)
   689             setattr(self, name, button)
   692             controls_sizer.AddWindow(button, border=5, flag=wx.BOTTOM)
   690             controls_sizer.Add(button, border=5, flag=wx.BOTTOM)
   693 
   691 
   694         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
   692         self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
   695         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
   693         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGING, self.OnVariablesGridCellChange)
   696         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
   694         self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
   697         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
   695         self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
   698         main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
   696         main_sizer.Add(self.VariablesGrid, flag=wx.GROW)
   699 
   697 
   700         self.SetSizer(main_sizer)
   698         self.SetSizer(main_sizer)
   701 
   699 
   702         self.ParentWindow = window
   700         self.ParentWindow = window
   703         self.Controler = controler
   701         self.Controler = controler
   783         self.Table.SetData(self.Controler.GetVariables())
   781         self.Table.SetData(self.Controler.GetVariables())
   784         self.Table.ResetView(self.VariablesGrid)
   782         self.Table.ResetView(self.VariablesGrid)
   785         self.VariablesGrid.RefreshButtons()
   783         self.VariablesGrid.RefreshButtons()
   786 
   784 
   787     def DoGetBestSize(self):
   785     def DoGetBestSize(self):
   788         return self.ParentWindow.GetPanelBestSize()
   786         return self.ParentWindow.GetBestSize()
   789 
   787 
   790     def ShowErrorMessage(self, message):
   788     def ShowErrorMessage(self, message):
   791         dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
   789         dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
   792         dialog.ShowModal()
   790         dialog.ShowModal()
   793         dialog.Destroy()
   791         dialog.Destroy()
   834                 new_entry = datatype_menu.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL, text=datatype)
   832                 new_entry = datatype_menu.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL, text=datatype)
   835                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), new_entry)
   833                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), new_entry)
   836             type_menu.AppendMenu(wx.ID_ANY, "User Data Types", datatype_menu)
   834             type_menu.AppendMenu(wx.ID_ANY, "User Data Types", datatype_menu)
   837             rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
   835             rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
   838 
   836 
   839             self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
   837             self.VariablesGrid.PopupMenu(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
   840             type_menu.Destroy()
   838             type_menu.Destroy()
   841             event.Veto()
   839             event.Veto()
   842         else:
   840         else:
   843             event.Skip()
   841             event.Skip()
   844 
   842