20 HIGHLIGHT_TYPES = { |
20 HIGHLIGHT_TYPES = { |
21 ERROR_HIGHLIGHT: STC_CODE_ERROR, |
21 ERROR_HIGHLIGHT: STC_CODE_ERROR, |
22 SEARCH_RESULT_HIGHLIGHT: STC_CODE_SEARCH_RESULT, |
22 SEARCH_RESULT_HIGHLIGHT: STC_CODE_SEARCH_RESULT, |
23 } |
23 } |
24 |
24 |
|
25 EDGE_COLUMN = 80 |
|
26 |
25 class CodeEditor(CustomStyledTextCtrl): |
27 class CodeEditor(CustomStyledTextCtrl): |
26 |
28 |
27 KEYWORDS = [] |
29 KEYWORDS = [] |
28 COMMENT_HEADER = "" |
30 COMMENT_HEADER = "" |
29 |
31 |
30 def __init__(self, parent, window, controler): |
32 def __init__(self, parent, window, controler): |
31 CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition, |
33 CustomStyledTextCtrl.__init__(self, parent, -1, wx.DefaultPosition, |
32 wx.Size(-1, 300), 0) |
34 wx.Size(-1, 300), 0) |
33 |
35 |
34 self.SetMarginType(1, stc.STC_MARGIN_NUMBER) |
36 self.SetMarginType(1, stc.STC_MARGIN_NUMBER) |
35 self.SetMarginWidth(1, 25) |
37 self.SetMarginWidth(1, 25) |
36 |
|
37 self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) |
|
38 self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) |
|
39 |
38 |
40 self.SetProperty("fold", "1") |
39 self.SetProperty("fold", "1") |
41 self.SetProperty("tab.timmy.whinge.level", "1") |
40 self.SetProperty("tab.timmy.whinge.level", "1") |
42 self.SetMargins(0,0) |
41 self.SetMargins(0,0) |
43 |
42 |
44 self.SetViewWhiteSpace(False) |
43 self.SetViewWhiteSpace(False) |
45 |
44 |
46 self.SetEdgeMode(stc.STC_EDGE_BACKGROUND) |
45 self.SetEdgeMode(stc.STC_EDGE_BACKGROUND) |
47 self.SetEdgeColumn(78) |
46 self.SetEdgeColumn(EDGE_COLUMN) |
48 |
47 |
49 # Setup a margin to hold fold markers |
48 # Setup a margin to hold fold markers |
50 self.SetMarginType(2, stc.STC_MARGIN_SYMBOL) |
49 self.SetMarginType(2, stc.STC_MARGIN_SYMBOL) |
51 self.SetMarginMask(2, stc.STC_MASK_FOLDERS) |
50 self.SetMarginMask(2, stc.STC_MASK_FOLDERS) |
52 self.SetMarginSensitive(2, True) |
51 self.SetMarginSensitive(2, True) |
86 |
85 |
87 # Section style |
86 # Section style |
88 self.StyleSetSpec(STC_CODE_SECTION, 'fore:#808080,size:%(size)d') |
87 self.StyleSetSpec(STC_CODE_SECTION, 'fore:#808080,size:%(size)d') |
89 self.StyleSetChangeable(STC_CODE_SECTION, False) |
88 self.StyleSetChangeable(STC_CODE_SECTION, False) |
90 |
89 |
91 # register some images for use in the AutoComplete box. |
|
92 #self.RegisterImage(1, images.getSmilesBitmap()) |
|
93 self.RegisterImage(1, |
|
94 wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16))) |
|
95 self.RegisterImage(2, |
|
96 wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16))) |
|
97 self.RegisterImage(3, |
|
98 wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16))) |
|
99 |
|
100 # Indentation size |
90 # Indentation size |
101 self.SetTabWidth(2) |
91 self.SetTabWidth(4) |
102 self.SetUseTabs(0) |
92 self.SetUseTabs(0) |
103 |
93 |
104 self.SetCodeLexer() |
94 self.SetCodeLexer() |
105 self.SetKeyWords(0, " ".join(self.KEYWORDS)) |
95 self.SetKeyWords(0, " ".join(self.KEYWORDS)) |
106 |
96 |
119 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
109 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
120 |
110 |
121 self.SectionsComments = {} |
111 self.SectionsComments = {} |
122 for section in self.Controler.SECTIONS_NAMES: |
112 for section in self.Controler.SECTIONS_NAMES: |
123 section_comment = " %s section " % (section) |
113 section_comment = " %s section " % (section) |
124 len_headers = 78 - len(section_comment) |
114 len_headers = EDGE_COLUMN - len(section_comment) |
125 section_comment = self.COMMENT_HEADER * (len_headers / 2) + \ |
115 section_comment = self.COMMENT_HEADER * (len_headers / 2) + \ |
126 section_comment + \ |
116 section_comment + \ |
127 self.COMMENT_HEADER * (len_headers - len_headers / 2) |
117 self.COMMENT_HEADER * (len_headers - len_headers / 2) |
128 |
118 |
129 self.SectionsComments[section] = { |
119 self.SectionsComments[section] = { |
369 self.BraceHighlight(braceAtCaret, braceOpposite) |
359 self.BraceHighlight(braceAtCaret, braceOpposite) |
370 |
360 |
371 selected_text = self.GetSelectedText() |
361 selected_text = self.GetSelectedText() |
372 if selected_text: |
362 if selected_text: |
373 self.ParentWindow.SetCopyBuffer(selected_text, True) |
363 self.ParentWindow.SetCopyBuffer(selected_text, True) |
374 event.Skip() |
364 |
375 |
|
376 def OnMarginClick(self, event): |
365 def OnMarginClick(self, event): |
377 # fold and unfold as needed |
366 # fold and unfold as needed |
378 if evt.GetMargin() == 2: |
367 if evt.GetMargin() == 2: |
379 if evt.GetShift() and evt.GetControl(): |
368 if evt.GetShift() and evt.GetControl(): |
380 self.FoldAll() |
369 self.FoldAll() |
621 class VariablesEditor(wx.Panel): |
610 class VariablesEditor(wx.Panel): |
622 |
611 |
623 def __init__(self, parent, window, controler): |
612 def __init__(self, parent, window, controler): |
624 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
613 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
625 |
614 |
626 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
615 main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=4) |
627 main_sizer.AddGrowableCol(0) |
616 main_sizer.AddGrowableCol(1) |
628 main_sizer.AddGrowableRow(1) |
617 main_sizer.AddGrowableRow(0) |
629 |
618 |
630 controls_sizer = wx.BoxSizer(wx.HORIZONTAL) |
619 controls_sizer = wx.BoxSizer(wx.VERTICAL) |
631 main_sizer.AddSizer(controls_sizer, border=5, flag=wx.TOP|wx.ALIGN_RIGHT) |
620 main_sizer.AddSizer(controls_sizer, border=5, flag=wx.ALL) |
632 |
621 |
633 for name, bitmap, help in [ |
622 for name, bitmap, help in [ |
634 ("AddVariableButton", "add_element", _("Add variable")), |
623 ("AddVariableButton", "add_element", _("Add variable")), |
635 ("DeleteVariableButton", "remove_element", _("Remove variable")), |
624 ("DeleteVariableButton", "remove_element", _("Remove variable")), |
636 ("UpVariableButton", "up", _("Move variable up")), |
625 ("UpVariableButton", "up", _("Move variable up")), |
637 ("DownVariableButton", "down", _("Move variable down"))]: |
626 ("DownVariableButton", "down", _("Move variable down"))]: |
638 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
627 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
639 size=wx.Size(28, 28), style=wx.NO_BORDER) |
628 size=wx.Size(28, 28), style=wx.NO_BORDER) |
640 button.SetToolTipString(help) |
629 button.SetToolTipString(help) |
641 setattr(self, name, button) |
630 setattr(self, name, button) |
642 controls_sizer.AddWindow(button, border=5, flag=wx.RIGHT) |
631 controls_sizer.AddWindow(button, border=5, flag=wx.BOTTOM) |
643 |
632 |
644 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
633 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
645 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
634 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
646 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
635 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
647 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
636 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |