491 grid.SetCellEditor(row, col, editor) |
491 grid.SetCellEditor(row, col, editor) |
492 grid.SetCellRenderer(row, col, renderer) |
492 grid.SetCellRenderer(row, col, renderer) |
493 |
493 |
494 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
494 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
495 self.ResizeRow(grid, row) |
495 self.ResizeRow(grid, row) |
496 |
496 |
497 |
|
498 [ID_VARIABLESEDITOR, ID_VARIABLESEDITORVARIABLESGRID, |
|
499 ID_VARIABLESEDITORADDVARIABLEBUTTON, ID_VARIABLESEDITORDELETEVARIABLEBUTTON, |
|
500 ID_VARIABLESEDITORUPVARIABLEBUTTON, ID_VARIABLESEDITORDOWNVARIABLEBUTTON |
|
501 ] = [wx.NewId() for _init_ctrls in range(6)] |
|
502 |
497 |
503 class VariablesEditor(wx.Panel): |
498 class VariablesEditor(wx.Panel): |
504 |
499 |
505 if wx.VERSION < (2, 6, 0): |
|
506 def Bind(self, event, function, id = None): |
|
507 if id is not None: |
|
508 event(self, id, function) |
|
509 else: |
|
510 event(self, function) |
|
511 |
|
512 def _init_coll_MainSizer_Growables(self, parent): |
|
513 parent.AddGrowableCol(0) |
|
514 parent.AddGrowableRow(0) |
|
515 |
|
516 def _init_coll_MainSizer_Items(self, parent): |
|
517 parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
|
518 parent.AddSizer(self.ButtonsSizer, 0, border=0, flag=wx.GROW) |
|
519 |
|
520 def _init_coll_ButtonsSizer_Growables(self, parent): |
|
521 parent.AddGrowableCol(0) |
|
522 parent.AddGrowableRow(0) |
|
523 |
|
524 def _init_coll_ButtonsSizer_Items(self, parent): |
|
525 parent.AddWindow(self.AddVariableButton, 0, border=0, flag=wx.ALIGN_RIGHT) |
|
526 parent.AddWindow(self.DeleteVariableButton, 0, border=0, flag=0) |
|
527 parent.AddWindow(self.UpVariableButton, 0, border=0, flag=0) |
|
528 parent.AddWindow(self.DownVariableButton, 0, border=0, flag=0) |
|
529 |
|
530 def _init_sizers(self): |
|
531 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
|
532 self.ButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
533 |
|
534 self._init_coll_MainSizer_Growables(self.MainSizer) |
|
535 self._init_coll_MainSizer_Items(self.MainSizer) |
|
536 self._init_coll_ButtonsSizer_Growables(self.ButtonsSizer) |
|
537 self._init_coll_ButtonsSizer_Items(self.ButtonsSizer) |
|
538 |
|
539 self.SetSizer(self.MainSizer) |
|
540 |
|
541 def _init_ctrls(self, prnt): |
|
542 wx.Panel.__init__(self, id=ID_VARIABLESEDITOR, name='', parent=prnt, |
|
543 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
544 |
|
545 self.VariablesGrid = CustomGrid(id=ID_VARIABLESEDITORVARIABLESGRID, |
|
546 name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
|
547 size=wx.Size(-1, -1), style=wx.VSCROLL) |
|
548 if wx.VERSION >= (2, 5, 0): |
|
549 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
|
550 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
|
551 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
|
552 else: |
|
553 wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange) |
|
554 wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
|
555 wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown) |
|
556 |
|
557 self.AddVariableButton = wx.Button(id=ID_VARIABLESEDITORADDVARIABLEBUTTON, label='Add Variable', |
|
558 name='AddVariableButton', parent=self, pos=wx.Point(0, 0), |
|
559 size=wx.Size(122, 32), style=0) |
|
560 |
|
561 self.DeleteVariableButton = wx.Button(id=ID_VARIABLESEDITORDELETEVARIABLEBUTTON, label='Delete Variable', |
|
562 name='DeleteVariableButton', parent=self, pos=wx.Point(0, 0), |
|
563 size=wx.Size(122, 32), style=0) |
|
564 |
|
565 self.UpVariableButton = wx.Button(id=ID_VARIABLESEDITORUPVARIABLEBUTTON, label='^', |
|
566 name='UpVariableButton', parent=self, pos=wx.Point(0, 0), |
|
567 size=wx.Size(32, 32), style=0) |
|
568 |
|
569 self.DownVariableButton = wx.Button(id=ID_VARIABLESEDITORDOWNVARIABLEBUTTON, label='v', |
|
570 name='DownVariableButton', parent=self, pos=wx.Point(0, 0), |
|
571 size=wx.Size(32, 32), style=0) |
|
572 |
|
573 self._init_sizers() |
|
574 |
|
575 def __init__(self, parent, window, controler): |
500 def __init__(self, parent, window, controler): |
576 self._init_ctrls(parent) |
501 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
577 |
502 |
|
503 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
|
504 main_sizer.AddGrowableCol(0) |
|
505 main_sizer.AddGrowableRow(0) |
|
506 |
|
507 self.VariablesGrid = CustomGrid(self, size=wx.Size(-1, 300), style=wx.VSCROLL) |
|
508 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
|
509 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
|
510 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
|
511 main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
|
512 |
|
513 controls_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
514 main_sizer.AddSizer(controls_sizer, border=5, flag=wx.TOP|wx.ALIGN_RIGHT) |
|
515 |
|
516 for name, bitmap, help in [ |
|
517 ("AddVariableButton", "add_element", _("Add variable")), |
|
518 ("DeleteVariableButton", "remove_element", _("Remove variable")), |
|
519 ("UpVariableButton", "up", _("Move variable up")), |
|
520 ("DownVariableButton", "down", _("Move variable down"))]: |
|
521 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
|
522 size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
523 button.SetToolTipString(help) |
|
524 setattr(self, name, button) |
|
525 controls_sizer.AddWindow(button, border=5, flag=wx.LEFT) |
|
526 |
|
527 self.SetSizer(main_sizer) |
|
528 |
578 self.ParentWindow = window |
529 self.ParentWindow = window |
579 self.Controler = controler |
530 self.Controler = controler |
580 |
531 |
581 self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""} |
532 self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""} |
582 self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"]) |
533 self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"]) |
771 |
723 |
772 dc.SetPen(wx.Pen(self.GetForegroundColour())) |
724 dc.SetPen(wx.Pen(self.GetForegroundColour())) |
773 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
725 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
774 dc.DrawRectangle(0, 0, width, height) |
726 dc.DrawRectangle(0, 0, width, height) |
775 |
727 |
776 [ID_CFILEEDITOR, ID_CFILEEDITORMAINSPLITTER, |
|
777 ID_CFILEEDITORCFILETREE, ID_CFILEEDITORPARTSOPENED, |
|
778 ] = [wx.NewId() for _init_ctrls in range(4)] |
|
779 |
|
780 class CFileEditor(ConfTreeNodeEditor): |
728 class CFileEditor(ConfTreeNodeEditor): |
781 |
729 |
782 def _init_ConfNodeEditor(self, prnt): |
730 CONFNODEEDITOR_TABS = [ |
783 self.ConfNodeEditor = wx.Panel(id=ID_CFILEEDITOR, parent=prnt, pos=wx.Point(0, 0), |
731 (_("C code"), "_create_CCodeEditor")] |
784 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
732 |
|
733 def _create_CCodeEditor(self, prnt): |
|
734 self.CCodeEditor = wx.ScrolledWindow(prnt, |
|
735 style=wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL) |
|
736 self.CCodeEditor.Bind(wx.EVT_SIZE, self.OnCCodeEditorResize) |
785 |
737 |
786 self.Panels = {} |
738 self.Panels = {} |
787 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2 * len(CFILE_PARTS) + 1, vgap=0) |
739 self.MainSizer = wx.BoxSizer(wx.VERTICAL) |
788 self.MainSizer.AddGrowableCol(0) |
|
789 |
740 |
790 for idx, (name, panel_class) in enumerate(CFILE_PARTS): |
741 for idx, (name, panel_class) in enumerate(CFILE_PARTS): |
791 button_id = wx.NewId() |
742 button_id = wx.NewId() |
792 button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name, |
743 button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name, |
793 label=name, bitmap=GetBitmap("CollapsedIconData"), |
744 label=name, bitmap=GetBitmap("CollapsedIconData"), |
794 parent=self.ConfNodeEditor, pos=wx.Point(0, 0), |
745 parent=self.CCodeEditor, pos=wx.Point(0, 0), |
795 size=wx.Size(0, 20), style=wx.NO_BORDER|wx.ALIGN_LEFT) |
746 size=wx.Size(0, 20), style=wx.NO_BORDER|wx.ALIGN_LEFT) |
796 button.SetBitmapSelected(GetBitmap("ExpandedIconData")) |
747 button.SetBitmapSelected(GetBitmap("ExpandedIconData")) |
797 button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id) |
748 button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id) |
798 self.MainSizer.AddWindow(button, 0, border=0, flag=wx.TOP|wx.GROW) |
749 self.MainSizer.AddWindow(button, 0, border=0, flag=wx.TOP|wx.GROW) |
799 |
750 |
800 if panel_class == VariablesEditor: |
751 if panel_class == VariablesEditor: |
801 panel = VariablesEditor(self.ConfNodeEditor, self.ParentWindow, self.Controler) |
752 panel = VariablesEditor(self.CCodeEditor, self.ParentWindow, self.Controler) |
802 else: |
753 else: |
803 panel = panel_class(self.ConfNodeEditor, name, self.ParentWindow, self.Controler) |
754 panel = panel_class(self.CCodeEditor, name, self.ParentWindow, self.Controler) |
804 self.MainSizer.AddWindow(panel, 0, border=0, flag=wx.BOTTOM|wx.GROW) |
755 self.MainSizer.AddWindow(panel, 0, border=0, flag=wx.BOTTOM|wx.GROW) |
805 panel.Hide() |
756 panel.Hide() |
806 |
757 |
807 self.Panels[name] = {"button": button, "panel": panel, "expanded": False, "row": 2 * idx + 1} |
758 self.Panels[name] = {"button": button, "panel": panel, "expanded": False, "row": 2 * idx + 1} |
808 |
759 |
809 self.Spacer = wx.Panel(self.ConfNodeEditor, -1) |
760 self.CCodeEditor.SetSizer(self.MainSizer) |
810 self.SpacerExpanded = True |
761 |
811 self.MainSizer.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) |
762 return self.CCodeEditor |
812 |
|
813 self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) |
|
814 |
|
815 self.ConfNodeEditor.SetSizer(self.MainSizer) |
|
816 |
763 |
817 def __init__(self, parent, controler, window): |
764 def __init__(self, parent, controler, window): |
818 ConfTreeNodeEditor.__init__(self, parent, controler, window) |
765 ConfTreeNodeEditor.__init__(self, parent, controler, window) |
819 |
766 |
820 def GetBufferState(self): |
767 def GetBufferState(self): |
843 infos = self.Panels.get(name, None) |
792 infos = self.Panels.get(name, None) |
844 if infos is not None and not infos["expanded"]: |
793 if infos is not None and not infos["expanded"]: |
845 infos["expanded"] = True |
794 infos["expanded"] = True |
846 infos["button"].SetToggle(True) |
795 infos["button"].SetToggle(True) |
847 infos["panel"].Show() |
796 infos["panel"].Show() |
848 self.MainSizer.AddGrowableRow(infos["row"]) |
797 |
849 |
|
850 self.RefreshSizerLayout() |
798 self.RefreshSizerLayout() |
851 |
799 |
852 def CollapsePanel(self, name): |
800 def CollapsePanel(self, name): |
853 infos = self.Panels.get(name, None) |
801 infos = self.Panels.get(name, None) |
854 if infos is not None and infos["expanded"]: |
802 if infos is not None and infos["expanded"]: |
855 infos["expanded"] = False |
803 infos["expanded"] = False |
856 infos["button"].SetToggle(False) |
804 infos["button"].SetToggle(False) |
857 infos["panel"].Hide() |
805 infos["panel"].Hide() |
858 self.MainSizer.RemoveGrowableRow(infos["row"]) |
806 |
859 |
|
860 self.RefreshSizerLayout() |
807 self.RefreshSizerLayout() |
861 |
808 |
862 def TogglePanel(self, name): |
809 def TogglePanel(self, name): |
863 infos = self.Panels.get(name, None) |
810 infos = self.Panels.get(name, None) |
864 if infos is not None: |
811 if infos is not None: |
865 infos["expanded"] = not infos["expanded"] |
812 infos["expanded"] = not infos["expanded"] |
866 infos["button"].SetToggle(infos["expanded"]) |
813 infos["button"].SetToggle(infos["expanded"]) |
867 if infos["expanded"]: |
814 if infos["expanded"]: |
868 infos["panel"].Show() |
815 infos["panel"].Show() |
869 self.MainSizer.AddGrowableRow(infos["row"]) |
|
870 else: |
816 else: |
871 infos["panel"].Hide() |
817 infos["panel"].Hide() |
872 self.MainSizer.RemoveGrowableRow(infos["row"]) |
|
873 |
818 |
874 self.RefreshSizerLayout() |
819 self.RefreshSizerLayout() |
875 |
820 |
876 def RefreshSizerLayout(self): |
821 def RefreshSizerLayout(self): |
877 expand_spacer = True |
|
878 for infos in self.Panels.itervalues(): |
|
879 expand_spacer = expand_spacer and not infos["expanded"] |
|
880 |
|
881 if self.SpacerExpanded != expand_spacer: |
|
882 self.SpacerExpanded = expand_spacer |
|
883 if expand_spacer: |
|
884 self.Spacer.Show() |
|
885 self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) |
|
886 else: |
|
887 self.Spacer.Hide() |
|
888 self.MainSizer.RemoveGrowableRow(2 * len(CFILE_PARTS)) |
|
889 |
|
890 self.MainSizer.Layout() |
822 self.MainSizer.Layout() |
891 |
823 self.RefreshCCodeEditorScrollbars() |
|
824 |
|
825 def RefreshCCodeEditorScrollbars(self): |
|
826 self.CCodeEditor.GetBestSize() |
|
827 xstart, ystart = self.CCodeEditor.GetViewStart() |
|
828 window_size = self.CCodeEditor.GetClientSize() |
|
829 maxx, maxy = self.MainSizer.GetMinSize() |
|
830 posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
|
831 posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
|
832 self.CCodeEditor.Scroll(posx, posy) |
|
833 self.CCodeEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
834 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
|
835 |
|
836 def OnCCodeEditorResize(self, event): |
|
837 self.RefreshCCodeEditorScrollbars() |
|
838 event.Skip() |
|
839 |