editors/CodeFileEditor.py
changeset 2226 addb6eff8d94
parent 1969 0607c382d73f
child 2249 602fdd08dfab
equal deleted inserted replaced
2225:2a9549e4380e 2226:addb6eff8d94
   596 
   596 
   597 # -------------------------------------------------------------------------------
   597 # -------------------------------------------------------------------------------
   598 #                         Helper for VariablesGrid values
   598 #                         Helper for VariablesGrid values
   599 # -------------------------------------------------------------------------------
   599 # -------------------------------------------------------------------------------
   600 
   600 
       
   601 class AllGridCellEditor(wx.grid.GridCellTextEditor):
       
   602     def __init__(self, table, row, col):
       
   603         wx.grid.GridCellTextEditor.__init__(self)
       
   604 
       
   605 class ClassGridCellEditor(wx.grid.GridCellChoiceEditor):
       
   606     def __init__(self, table, row, col):
       
   607         wx.grid.GridCellChoiceEditor.__init__(self)
       
   608         self.SetParameters("input,memory,output")
       
   609 
       
   610 
   601 class VariablesTable(CustomTable):
   611 class VariablesTable(CustomTable):
       
   612     __defaultColumnType = dict(
       
   613             [(name, AllGridCellEditor) for name in
       
   614              ["Name", "Initial", "Description", "OnChange", "Options"]] +
       
   615             [('Class', ClassGridCellEditor), ('Type', None)])
       
   616 
       
   617     def __init__(self, *args, **kwargs):
       
   618         my_columns = kwargs.pop("additional_columns")
       
   619         super(VariablesTable, self).__init__(*args, **kwargs)
       
   620         self.columnTypes = dict(self.__defaultColumnType)
       
   621         if my_columns is not None:
       
   622             for key in my_columns.keys():
       
   623                 if key in self.columnTypes.keys():
       
   624                     self.columnTypes[key] = my_columns[key]
   602 
   625 
   603     def GetValue(self, row, col):
   626     def GetValue(self, row, col):
   604         if row < self.GetNumberRows():
   627         if row < self.GetNumberRows():
   605             if col == 0:
   628             if col == 0:
   606                 return row + 1
   629                 return row + 1
   619             for col in range(self.GetNumberCols()):
   642             for col in range(self.GetNumberCols()):
   620                 editor = None
   643                 editor = None
   621                 renderer = None
   644                 renderer = None
   622                 colname = self.GetColLabelValue(col, False)
   645                 colname = self.GetColLabelValue(col, False)
   623 
   646 
   624                 if colname in ["Name", "Initial", "Description", "OnChange", "Options"]:
   647                 editortype = self.columnTypes.get(colname, None)
   625                     editor = wx.grid.GridCellTextEditor()
   648                 if editortype is not None:
   626                 elif colname == "Class":
   649                     editor = editortype(self, row, col)
   627                     editor = wx.grid.GridCellChoiceEditor()
       
   628                     editor.SetParameters("input,memory,output")
       
   629                 elif colname == "Type":
       
   630                     pass
       
   631                 else:
       
   632                     grid.SetReadOnly(row, col, True)
       
   633 
   650 
   634                 grid.SetCellEditor(row, col, editor)
   651                 grid.SetCellEditor(row, col, editor)
   635                 grid.SetCellRenderer(row, col, renderer)
   652                 grid.SetCellRenderer(row, col, renderer)
   636 
   653 
   637                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
   654                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
   638             self.ResizeRow(grid, row)
   655             self.ResizeRow(grid, row)
   639 
   656 
   640 
   657 
   641 class VariablesEditor(wx.Panel):
   658 class VariablesEditor(wx.Panel):
   642 
   659 
   643     def __init__(self, parent, window, controler):
   660     def __init__(self, parent, window, controler, additional_columns=None):
   644         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   661         wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
   645 
   662 
   646         main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
   663         main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4)
   647         main_sizer.AddGrowableCol(1)
   664         main_sizer.AddGrowableCol(1)
   648         main_sizer.AddGrowableRow(0)
   665         main_sizer.AddGrowableRow(0)
   678             "Initial":     "",
   695             "Initial":     "",
   679             "Description": "",
   696             "Description": "",
   680             "OnChange":    "",
   697             "OnChange":    "",
   681             "Options":     ""
   698             "Options":     ""
   682         }
   699         }
   683         self.Table = VariablesTable(self, [], self.GetVariableTableColnames())
   700 
       
   701         self.Table = VariablesTable(self, [], self.GetVariableTableColnames(), additional_columns=additional_columns)
   684         self.ColAlignements = [wx.ALIGN_RIGHT] +  \
   702         self.ColAlignements = [wx.ALIGN_RIGHT] +  \
   685                               [wx.ALIGN_LEFT]*(len(self.VariablesDefaultValue))
   703                               [wx.ALIGN_LEFT]*(len(self.VariablesDefaultValue))
   686         self.ColSizes = [20, 150] + [130]*(len(self.VariablesDefaultValue)-1)
   704         self.ColSizes = [20, 150] + [130]*(len(self.VariablesDefaultValue)-1)
   687         self.VariablesGrid.SetTable(self.Table)
   705         self.VariablesGrid.SetTable(self.Table)
   688         self.VariablesGrid.SetButtons({"Add": self.AddVariableButton,
   706         self.VariablesGrid.SetButtons({"Add": self.AddVariableButton,
   843 
   861 
   844 class CodeFileEditor(ConfTreeNodeEditor):
   862 class CodeFileEditor(ConfTreeNodeEditor):
   845 
   863 
   846     CONFNODEEDITOR_TABS = []
   864     CONFNODEEDITOR_TABS = []
   847     CODE_EDITOR = None
   865     CODE_EDITOR = None
       
   866     COLUMNS_TYPE = None
   848 
   867 
   849     def _create_CodePanel(self, prnt):
   868     def _create_CodePanel(self, prnt):
   850         self.CodeEditorPanel = wx.SplitterWindow(prnt)
   869         self.CodeEditorPanel = wx.SplitterWindow(prnt)
   851         self.CodeEditorPanel.SetMinimumPaneSize(1)
   870         self.CodeEditorPanel.SetMinimumPaneSize(1)
   852 
   871 
   853         self.VariablesPanel = VariablesEditor(self.CodeEditorPanel,
   872         self.VariablesPanel = VariablesEditor(self.CodeEditorPanel,
   854                                               self.ParentWindow,
   873                                               self.ParentWindow,
   855                                               self.Controler)
   874                                               self.Controler,
       
   875                                               self.COLUMNS_TYPE)
   856 
   876 
   857         if self.CODE_EDITOR is not None:
   877         if self.CODE_EDITOR is not None:
   858             self.CodeEditor = self.CODE_EDITOR(self.CodeEditorPanel,
   878             self.CodeEditor = self.CODE_EDITOR(self.CodeEditorPanel,
   859                                                self.ParentWindow, self.Controler)
   879                                                self.ParentWindow, self.Controler)
   860 
   880