72 |
72 |
73 fold_symbols = 3 |
73 fold_symbols = 3 |
74 |
74 |
75 def __init__(self, parent, name, window, controler): |
75 def __init__(self, parent, name, window, controler): |
76 stc.StyledTextCtrl.__init__(self, parent, ID_CPPEDITOR, wx.DefaultPosition, |
76 stc.StyledTextCtrl.__init__(self, parent, ID_CPPEDITOR, wx.DefaultPosition, |
77 wx.Size(0, 0), 0) |
77 wx.Size(-1, 300), 0) |
78 |
78 |
79 self.SetMarginType(1, stc.STC_MARGIN_NUMBER) |
79 self.SetMarginType(1, stc.STC_MARGIN_NUMBER) |
80 self.SetMarginWidth(1, 25) |
80 self.SetMarginWidth(1, 25) |
81 |
81 |
82 self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) |
82 self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) |
502 |
502 |
503 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
503 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
504 main_sizer.AddGrowableCol(0) |
504 main_sizer.AddGrowableCol(0) |
505 main_sizer.AddGrowableRow(0) |
505 main_sizer.AddGrowableRow(0) |
506 |
506 |
507 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
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) |
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) |
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) |
510 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
511 main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
511 main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
512 |
512 |
725 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
725 dc.SetBrush(wx.TRANSPARENT_BRUSH) |
726 dc.DrawRectangle(0, 0, width, height) |
726 dc.DrawRectangle(0, 0, width, height) |
727 |
727 |
728 class CFileEditor(ConfTreeNodeEditor): |
728 class CFileEditor(ConfTreeNodeEditor): |
729 |
729 |
730 def _init_ConfNodeEditor(self, prnt): |
730 CONFNODEEDITOR_TABS = [ |
731 self.ConfNodeEditor = wx.Panel(prnt, style=wx.TAB_TRAVERSAL) |
731 (_("C code"), "_create_CCodeEditor")] |
|
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) |
732 |
737 |
733 self.Panels = {} |
738 self.Panels = {} |
734 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2 * len(CFILE_PARTS) + 1, vgap=0) |
739 self.MainSizer = wx.BoxSizer(wx.VERTICAL) |
735 self.MainSizer.AddGrowableCol(0) |
|
736 |
740 |
737 for idx, (name, panel_class) in enumerate(CFILE_PARTS): |
741 for idx, (name, panel_class) in enumerate(CFILE_PARTS): |
738 button_id = wx.NewId() |
742 button_id = wx.NewId() |
739 button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name, |
743 button = FoldPanelCaption(id=button_id, name='FoldPanelCaption_%s' % name, |
740 label=name, bitmap=GetBitmap("CollapsedIconData"), |
744 label=name, bitmap=GetBitmap("CollapsedIconData"), |
741 parent=self.ConfNodeEditor, pos=wx.Point(0, 0), |
745 parent=self.CCodeEditor, pos=wx.Point(0, 0), |
742 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) |
743 button.SetBitmapSelected(GetBitmap("ExpandedIconData")) |
747 button.SetBitmapSelected(GetBitmap("ExpandedIconData")) |
744 button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id) |
748 button.Bind(wx.EVT_BUTTON, self.GenPanelButtonCallback(name), id=button_id) |
745 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) |
746 |
750 |
747 if panel_class == VariablesEditor: |
751 if panel_class == VariablesEditor: |
748 panel = VariablesEditor(self.ConfNodeEditor, self.ParentWindow, self.Controler) |
752 panel = VariablesEditor(self.CCodeEditor, self.ParentWindow, self.Controler) |
749 else: |
753 else: |
750 panel = panel_class(self.ConfNodeEditor, name, self.ParentWindow, self.Controler) |
754 panel = panel_class(self.CCodeEditor, name, self.ParentWindow, self.Controler) |
751 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) |
752 panel.Hide() |
756 panel.Hide() |
753 |
757 |
754 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} |
755 |
759 |
756 self.Spacer = wx.Panel(self.ConfNodeEditor, -1) |
760 self.CCodeEditor.SetSizer(self.MainSizer) |
757 self.SpacerExpanded = True |
761 |
758 self.MainSizer.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) |
762 return self.CCodeEditor |
759 |
|
760 self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) |
|
761 |
|
762 self.ConfNodeEditor.SetSizer(self.MainSizer) |
|
763 |
763 |
764 def __init__(self, parent, controler, window): |
764 def __init__(self, parent, controler, window): |
765 ConfTreeNodeEditor.__init__(self, parent, controler, window) |
765 ConfTreeNodeEditor.__init__(self, parent, controler, window) |
766 |
766 |
767 def GetBufferState(self): |
767 def GetBufferState(self): |
790 infos = self.Panels.get(name, None) |
792 infos = self.Panels.get(name, None) |
791 if infos is not None and not infos["expanded"]: |
793 if infos is not None and not infos["expanded"]: |
792 infos["expanded"] = True |
794 infos["expanded"] = True |
793 infos["button"].SetToggle(True) |
795 infos["button"].SetToggle(True) |
794 infos["panel"].Show() |
796 infos["panel"].Show() |
795 self.MainSizer.AddGrowableRow(infos["row"]) |
797 |
796 |
|
797 self.RefreshSizerLayout() |
798 self.RefreshSizerLayout() |
798 |
799 |
799 def CollapsePanel(self, name): |
800 def CollapsePanel(self, name): |
800 infos = self.Panels.get(name, None) |
801 infos = self.Panels.get(name, None) |
801 if infos is not None and infos["expanded"]: |
802 if infos is not None and infos["expanded"]: |
802 infos["expanded"] = False |
803 infos["expanded"] = False |
803 infos["button"].SetToggle(False) |
804 infos["button"].SetToggle(False) |
804 infos["panel"].Hide() |
805 infos["panel"].Hide() |
805 self.MainSizer.RemoveGrowableRow(infos["row"]) |
806 |
806 |
|
807 self.RefreshSizerLayout() |
807 self.RefreshSizerLayout() |
808 |
808 |
809 def TogglePanel(self, name): |
809 def TogglePanel(self, name): |
810 infos = self.Panels.get(name, None) |
810 infos = self.Panels.get(name, None) |
811 if infos is not None: |
811 if infos is not None: |
812 infos["expanded"] = not infos["expanded"] |
812 infos["expanded"] = not infos["expanded"] |
813 infos["button"].SetToggle(infos["expanded"]) |
813 infos["button"].SetToggle(infos["expanded"]) |
814 if infos["expanded"]: |
814 if infos["expanded"]: |
815 infos["panel"].Show() |
815 infos["panel"].Show() |
816 self.MainSizer.AddGrowableRow(infos["row"]) |
|
817 else: |
816 else: |
818 infos["panel"].Hide() |
817 infos["panel"].Hide() |
819 self.MainSizer.RemoveGrowableRow(infos["row"]) |
|
820 |
818 |
821 self.RefreshSizerLayout() |
819 self.RefreshSizerLayout() |
822 |
820 |
823 def RefreshSizerLayout(self): |
821 def RefreshSizerLayout(self): |
824 expand_spacer = True |
|
825 for infos in self.Panels.itervalues(): |
|
826 expand_spacer = expand_spacer and not infos["expanded"] |
|
827 |
|
828 if self.SpacerExpanded != expand_spacer: |
|
829 self.SpacerExpanded = expand_spacer |
|
830 if expand_spacer: |
|
831 self.Spacer.Show() |
|
832 self.MainSizer.AddGrowableRow(2 * len(CFILE_PARTS)) |
|
833 else: |
|
834 self.Spacer.Hide() |
|
835 self.MainSizer.RemoveGrowableRow(2 * len(CFILE_PARTS)) |
|
836 |
|
837 self.MainSizer.Layout() |
822 self.MainSizer.Layout() |
838 |
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 |