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