author | laurent |
Tue, 21 Aug 2012 18:40:42 +0200 | |
changeset 799 | 6af48f2e42ca |
parent 753 | 05502e574589 |
child 814 | 5743cbdff669 |
permissions | -rw-r--r-- |
738 | 1 |
import wx |
2 |
import wx.grid |
|
3 |
import wx.stc as stc |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
4 |
import keyword |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
5 |
|
738 | 6 |
from ConfTreeNodeEditor import ConfTreeNodeEditor |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
7 |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
8 |
if wx.Platform == '__WXMSW__': |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
9 |
faces = { 'times': 'Times New Roman', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
10 |
'mono' : 'Courier New', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
11 |
'helv' : 'Arial', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
12 |
'other': 'Comic Sans MS', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
13 |
'size' : 10, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
14 |
'size2': 8, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
15 |
} |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
16 |
elif wx.Platform == '__WXMAC__': |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
17 |
faces = { 'times': 'Times New Roman', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
18 |
'mono' : 'Monaco', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
19 |
'helv' : 'Arial', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
20 |
'other': 'Comic Sans MS', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
21 |
'size' : 12, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
22 |
'size2': 10, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
23 |
} |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
24 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
25 |
faces = { 'times': 'Times', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
26 |
'mono' : 'Courier', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
27 |
'helv' : 'Helvetica', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
28 |
'other': 'new century schoolbook', |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
29 |
'size' : 12, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
30 |
'size2': 10, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
31 |
} |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
32 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
33 |
[ID_PYTHONEDITOR, |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
34 |
] = [wx.NewId() for _init_ctrls in range(1)] |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
35 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
36 |
def GetCursorPos(old, new): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
37 |
old_length = len(old) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
38 |
new_length = len(new) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
39 |
common_length = min(old_length, new_length) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
40 |
i = 0 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
41 |
for i in xrange(common_length): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
42 |
if old[i] != new[i]: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
43 |
break |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
44 |
if old_length < new_length: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
45 |
if common_length > 0 and old[i] != new[i]: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
46 |
return i + new_length - old_length |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
47 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
48 |
return i + new_length - old_length + 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
49 |
elif old_length > new_length or i < min(old_length, new_length) - 1: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
50 |
if common_length > 0 and old[i] != new[i]: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
51 |
return i |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
52 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
53 |
return i + 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
54 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
55 |
return None |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
56 |
|
738 | 57 |
class PythonEditor(ConfTreeNodeEditor): |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
58 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
59 |
fold_symbols = 3 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
60 |
|
738 | 61 |
def _init_ConfNodeEditor(self, prnt): |
62 |
self.ConfNodeEditor = stc.StyledTextCtrl(id=ID_PYTHONEDITOR, parent=prnt, |
|
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
63 |
name="TextViewer", pos=wx.DefaultPosition, |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
64 |
size=wx.DefaultSize, style=0) |
753 | 65 |
self.ConfNodeEditor.ParentWindow = self |
66 |
||
738 | 67 |
self.ConfNodeEditor.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) |
68 |
self.ConfNodeEditor.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) |
|
69 |
||
70 |
self.ConfNodeEditor.SetLexer(stc.STC_LEX_PYTHON) |
|
71 |
self.ConfNodeEditor.SetKeyWords(0, " ".join(keyword.kwlist)) |
|
72 |
||
73 |
self.ConfNodeEditor.SetProperty("fold", "1") |
|
74 |
self.ConfNodeEditor.SetProperty("tab.timmy.whinge.level", "1") |
|
75 |
self.ConfNodeEditor.SetMargins(0,0) |
|
76 |
||
77 |
self.ConfNodeEditor.SetViewWhiteSpace(False) |
|
78 |
||
79 |
self.ConfNodeEditor.SetEdgeMode(stc.STC_EDGE_BACKGROUND) |
|
80 |
self.ConfNodeEditor.SetEdgeColumn(78) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
81 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
82 |
# Set up the numbers in the margin for margin #1 |
738 | 83 |
self.ConfNodeEditor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
84 |
# Reasonable value for, say, 4-5 digits using a mono font (40 pix) |
738 | 85 |
self.ConfNodeEditor.SetMarginWidth(1, 40) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
86 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
87 |
# Setup a margin to hold fold markers |
738 | 88 |
self.ConfNodeEditor.SetMarginType(2, stc.STC_MARGIN_SYMBOL) |
89 |
self.ConfNodeEditor.SetMarginMask(2, stc.STC_MASK_FOLDERS) |
|
90 |
self.ConfNodeEditor.SetMarginSensitive(2, True) |
|
91 |
self.ConfNodeEditor.SetMarginWidth(2, 12) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
92 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
93 |
if self.fold_symbols == 0: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
94 |
# Arrow pointing right for contracted folders, arrow pointing down for expanded |
738 | 95 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black") |
96 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black") |
|
97 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black") |
|
98 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black") |
|
99 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") |
|
100 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") |
|
101 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
102 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
103 |
elif self.fold_symbols == 1: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
104 |
# Plus for contracted folders, minus for expanded |
738 | 105 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black") |
106 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black") |
|
107 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black") |
|
108 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black") |
|
109 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") |
|
110 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") |
|
111 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
112 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
113 |
elif self.fold_symbols == 2: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
114 |
# Like a flattened tree control using circular headers and curved joins |
738 | 115 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040") |
116 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040") |
|
117 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040") |
|
118 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040") |
|
119 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040") |
|
120 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040") |
|
121 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040") |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
122 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
123 |
elif self.fold_symbols == 3: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
124 |
# Like a flattened tree control using square headers |
738 | 125 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080") |
126 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080") |
|
127 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080") |
|
128 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080") |
|
129 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
|
130 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
|
131 |
self.ConfNodeEditor.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080") |
|
132 |
||
133 |
||
134 |
self.ConfNodeEditor.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI) |
|
135 |
self.ConfNodeEditor.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick) |
|
136 |
self.ConfNodeEditor.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
137 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
138 |
# Global default style |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
139 |
if wx.Platform == '__WXMSW__': |
738 | 140 |
self.ConfNodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Courier New') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
141 |
elif wx.Platform == '__WXMAC__': |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
142 |
# TODO: if this looks fine on Linux too, remove the Mac-specific case |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
143 |
# and use this whenever OS != MSW. |
738 | 144 |
self.ConfNodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Monaco') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
145 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
146 |
defsize = wx.SystemSettings.GetFont(wx.SYS_ANSI_FIXED_FONT).GetPointSize() |
738 | 147 |
self.ConfNodeEditor.StyleSetSpec(stc.STC_STYLE_DEFAULT, 'fore:#000000,back:#FFFFFF,face:Courier,size:%d'%defsize) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
148 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
149 |
# Clear styles and revert to default. |
738 | 150 |
self.ConfNodeEditor.StyleClearAll() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
151 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
152 |
# Following style specs only indicate differences from default. |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
153 |
# The rest remains unchanged. |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
154 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
155 |
# Line numbers in margin |
738 | 156 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
157 |
# Highlighted brace |
738 | 158 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
159 |
# Unmatched brace |
738 | 160 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
161 |
# Indentation guide |
738 | 162 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD") |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
163 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
164 |
# Python styles |
738 | 165 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#000000') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
166 |
# Comments |
738 | 167 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_COMMENTLINE, 'fore:#008000,back:#F0FFF0') |
168 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0') |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
169 |
# Numbers |
738 | 170 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#008080') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
171 |
# Strings and characters |
738 | 172 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#800080') |
173 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#800080') |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
174 |
# Keywords |
738 | 175 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#000080,bold') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
176 |
# Triple quotes |
738 | 177 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA') |
178 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA') |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
179 |
# Class names |
738 | 180 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#0000FF,bold') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
181 |
# Function names |
738 | 182 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#008080,bold') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
183 |
# Operators |
738 | 184 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#800000,bold') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
185 |
# Identifiers. I leave this as not bold because everything seems |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
186 |
# to be an identifier if it doesn't match the above criterae |
738 | 187 |
self.ConfNodeEditor.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#000000') |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
188 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
189 |
# Caret color |
738 | 190 |
self.ConfNodeEditor.SetCaretForeground("BLUE") |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
191 |
# Selection background |
738 | 192 |
self.ConfNodeEditor.SetSelBackground(1, '#66CCFF') |
193 |
||
194 |
self.ConfNodeEditor.SetSelBackground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)) |
|
195 |
self.ConfNodeEditor.SetSelForeground(True, wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
196 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
197 |
# register some images for use in the AutoComplete box. |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
198 |
#self.RegisterImage(1, images.getSmilesBitmap()) |
738 | 199 |
self.ConfNodeEditor.RegisterImage(1, |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
200 |
wx.ArtProvider.GetBitmap(wx.ART_DELETE, size=(16,16))) |
738 | 201 |
self.ConfNodeEditor.RegisterImage(2, |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
202 |
wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16))) |
738 | 203 |
self.ConfNodeEditor.RegisterImage(3, |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
204 |
wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16))) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
205 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
206 |
# Indentation and tab stuff |
738 | 207 |
self.ConfNodeEditor.SetIndent(4) # Proscribed indent size for wx |
208 |
self.ConfNodeEditor.SetIndentationGuides(True) # Show indent guides |
|
209 |
self.ConfNodeEditor.SetBackSpaceUnIndents(True)# Backspace unindents rather than delete 1 space |
|
210 |
self.ConfNodeEditor.SetTabIndents(True) # Tab key indents |
|
211 |
self.ConfNodeEditor.SetTabWidth(4) # Proscribed tab size for wx |
|
212 |
self.ConfNodeEditor.SetUseTabs(False) # Use spaces rather than tabs, or |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
213 |
# TabTimmy will complain! |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
214 |
# White space |
738 | 215 |
self.ConfNodeEditor.SetViewWhiteSpace(False) # Don't view white space |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
216 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
217 |
# EOL: Since we are loading/saving ourselves, and the |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
218 |
# strings will always have \n's in them, set the STC to |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
219 |
# edit them that way. |
738 | 220 |
self.ConfNodeEditor.SetEOLMode(wx.stc.STC_EOL_LF) |
221 |
self.ConfNodeEditor.SetViewEOL(False) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
222 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
223 |
# No right-edge mode indicator |
738 | 224 |
self.ConfNodeEditor.SetEdgeMode(stc.STC_EDGE_NONE) |
225 |
||
226 |
self.ConfNodeEditor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
|
227 |
||
228 |
self.ConfNodeEditor.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_PYTHONEDITOR) |
|
229 |
self.ConfNodeEditor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
|
230 |
self.ConfNodeEditor.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_PYTHONEDITOR) |
|
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
231 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
232 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
233 |
def __init__(self, parent, controler, window): |
743 | 234 |
ConfTreeNodeEditor.__init__(self, parent, controler, window) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
235 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
236 |
self.DisableEvents = False |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
237 |
self.CurrentAction = None |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
238 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
239 |
def GetBufferState(self): |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
240 |
return self.Controler.GetBufferState() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
241 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
242 |
def Undo(self): |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
243 |
self.Controler.LoadPrevious() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
244 |
self.RefreshView() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
245 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
246 |
def Redo(self): |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
247 |
self.Controler.LoadNext() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
248 |
self.RefreshView() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
249 |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
250 |
def OnModification(self, event): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
251 |
if not self.DisableEvents: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
252 |
mod_type = event.GetModificationType() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
253 |
if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
254 |
if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
255 |
if self.CurrentAction is None: |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
256 |
self.StartBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
257 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
258 |
self.Controler.EndBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
259 |
self.StartBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
260 |
self.CurrentAction = ("Add", event.GetPosition()) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
261 |
wx.CallAfter(self.RefreshModel) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
262 |
elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
263 |
if self.CurrentAction == None: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
264 |
self.StartBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
265 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
266 |
self.Controler.EndBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
267 |
self.StartBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
268 |
self.CurrentAction = ("Delete", event.GetPosition()) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
269 |
wx.CallAfter(self.RefreshModel) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
270 |
event.Skip() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
271 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
272 |
def OnDoDrop(self, event): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
273 |
self.ResetBuffer() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
274 |
wx.CallAfter(self.RefreshModel) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
275 |
event.Skip() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
276 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
277 |
# Buffer the last model state |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
278 |
def RefreshBuffer(self): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
279 |
self.Controler.BufferPython() |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
280 |
if self.ParentWindow is not None: |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
281 |
self.ParentWindow.RefreshTitle() |
534
80f05b17de1e
Bug on FileMenu not refreshed when modifications fixed
laurent
parents:
427
diff
changeset
|
282 |
self.ParentWindow.RefreshFileMenu() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
283 |
self.ParentWindow.RefreshEditMenu() |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
284 |
self.ParentWindow.RefreshPageTitles() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
285 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
286 |
def StartBuffering(self): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
287 |
self.Controler.StartBuffering() |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
288 |
if self.ParentWindow is not None: |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
289 |
self.ParentWindow.RefreshTitle() |
534
80f05b17de1e
Bug on FileMenu not refreshed when modifications fixed
laurent
parents:
427
diff
changeset
|
290 |
self.ParentWindow.RefreshFileMenu() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
291 |
self.ParentWindow.RefreshEditMenu() |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
292 |
self.ParentWindow.RefreshPageTitles() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
293 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
294 |
def ResetBuffer(self): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
295 |
if self.CurrentAction != None: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
296 |
self.Controler.EndBuffering() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
297 |
self.CurrentAction = None |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
298 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
299 |
def RefreshView(self): |
751 | 300 |
ConfTreeNodeEditor.RefreshView(self) |
301 |
||
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
302 |
self.ResetBuffer() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
303 |
self.DisableEvents = True |
738 | 304 |
old_cursor_pos = self.ConfNodeEditor.GetCurrentPos() |
305 |
old_text = self.ConfNodeEditor.GetText() |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
306 |
new_text = self.Controler.GetPythonCode() |
738 | 307 |
self.ConfNodeEditor.SetText(new_text) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
308 |
new_cursor_pos = GetCursorPos(old_text, new_text) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
309 |
if new_cursor_pos != None: |
738 | 310 |
self.ConfNodeEditor.GotoPos(new_cursor_pos) |
311 |
else: |
|
312 |
self.ConfNodeEditor.GotoPos(old_cursor_pos) |
|
313 |
self.ConfNodeEditor.ScrollToColumn(0) |
|
314 |
self.ConfNodeEditor.EmptyUndoBuffer() |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
315 |
self.DisableEvents = False |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
316 |
|
738 | 317 |
self.ConfNodeEditor.Colourise(0, -1) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
318 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
319 |
def RefreshModel(self): |
738 | 320 |
self.Controler.SetPythonCode(self.ConfNodeEditor.GetText()) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
321 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
322 |
def OnKeyPressed(self, event): |
738 | 323 |
if self.ConfNodeEditor.CallTipActive(): |
324 |
self.ConfNodeEditor.CallTipCancel() |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
325 |
key = event.GetKeyCode() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
326 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
327 |
if key == 32 and event.ControlDown(): |
738 | 328 |
pos = self.ConfNodeEditor.GetCurrentPos() |
329 |
||
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
330 |
# Code completion |
738 | 331 |
if not event.ShiftDown(): |
332 |
self.ConfNodeEditor.AutoCompSetIgnoreCase(False) # so this needs to match |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
333 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
334 |
# Images are specified with a appended "?type" |
738 | 335 |
self.ConfNodeEditor.AutoCompShow(0, " ".join([word + "?1" for word in keyword.kwlist])) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
336 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
337 |
event.Skip() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
338 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
339 |
def OnKillFocus(self, event): |
738 | 340 |
self.ConfNodeEditor.AutoCompCancel() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
341 |
event.Skip() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
342 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
343 |
def OnUpdateUI(self, evt): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
344 |
# check for matching braces |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
345 |
braceAtCaret = -1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
346 |
braceOpposite = -1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
347 |
charBefore = None |
738 | 348 |
caretPos = self.ConfNodeEditor.GetCurrentPos() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
349 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
350 |
if caretPos > 0: |
738 | 351 |
charBefore = self.ConfNodeEditor.GetCharAt(caretPos - 1) |
352 |
styleBefore = self.ConfNodeEditor.GetStyleAt(caretPos - 1) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
353 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
354 |
# check before |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
355 |
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
356 |
braceAtCaret = caretPos - 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
357 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
358 |
# check after |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
359 |
if braceAtCaret < 0: |
738 | 360 |
charAfter = self.ConfNodeEditor.GetCharAt(caretPos) |
361 |
styleAfter = self.ConfNodeEditor.GetStyleAt(caretPos) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
362 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
363 |
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
364 |
braceAtCaret = caretPos |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
365 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
366 |
if braceAtCaret >= 0: |
738 | 367 |
braceOpposite = self.ConfNodeEditor.BraceMatch(braceAtCaret) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
368 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
369 |
if braceAtCaret != -1 and braceOpposite == -1: |
738 | 370 |
self.ConfNodeEditor.BraceBadLight(braceAtCaret) |
371 |
else: |
|
372 |
self.ConfNodeEditor.BraceHighlight(braceAtCaret, braceOpposite) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
373 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
374 |
def OnMarginClick(self, evt): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
375 |
# fold and unfold as needed |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
376 |
if evt.GetMargin() == 2: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
377 |
if evt.GetShift() and evt.GetControl(): |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
378 |
self.FoldAll() |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
379 |
else: |
738 | 380 |
lineClicked = self.ConfNodeEditor.LineFromPosition(evt.GetPosition()) |
381 |
||
382 |
if self.ConfNodeEditor.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG: |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
383 |
if evt.GetShift(): |
738 | 384 |
self.ConfNodeEditor.SetFoldExpanded(lineClicked, True) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
385 |
self.Expand(lineClicked, True, True, 1) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
386 |
elif evt.GetControl(): |
738 | 387 |
if self.ConfNodeEditor.GetFoldExpanded(lineClicked): |
388 |
self.ConfNodeEditor.SetFoldExpanded(lineClicked, False) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
389 |
self.Expand(lineClicked, False, True, 0) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
390 |
else: |
738 | 391 |
self.ConfNodeEditor.SetFoldExpanded(lineClicked, True) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
392 |
self.Expand(lineClicked, True, True, 100) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
393 |
else: |
738 | 394 |
self.ConfNodeEditor.ToggleFold(lineClicked) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
395 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
396 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
397 |
def FoldAll(self): |
738 | 398 |
lineCount = self.ConfNodeEditor.GetLineCount() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
399 |
expanding = True |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
400 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
401 |
# find out if we are folding or unfolding |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
402 |
for lineNum in range(lineCount): |
738 | 403 |
if self.ConfNodeEditor.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG: |
404 |
expanding = not self.ConfNodeEditor.GetFoldExpanded(lineNum) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
405 |
break |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
406 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
407 |
lineNum = 0 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
408 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
409 |
while lineNum < lineCount: |
738 | 410 |
level = self.ConfNodeEditor.GetFoldLevel(lineNum) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
411 |
if level & stc.STC_FOLDLEVELHEADERFLAG and \ |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
412 |
(level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
413 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
414 |
if expanding: |
738 | 415 |
self.ConfNodeEditor.SetFoldExpanded(lineNum, True) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
416 |
lineNum = self.Expand(lineNum, True) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
417 |
lineNum = lineNum - 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
418 |
else: |
738 | 419 |
lastChild = self.ConfNodeEditor.GetLastChild(lineNum, -1) |
420 |
self.ConfNodeEditor.SetFoldExpanded(lineNum, False) |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
421 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
422 |
if lastChild > lineNum: |
738 | 423 |
self.ConfNodeEditor.HideLines(lineNum+1, lastChild) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
424 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
425 |
lineNum = lineNum + 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
426 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
427 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
428 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
429 |
def Expand(self, line, doExpand, force=False, visLevels=0, level=-1): |
738 | 430 |
lastChild = self.ConfNodeEditor.GetLastChild(line, level) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
431 |
line = line + 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
432 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
433 |
while line <= lastChild: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
434 |
if force: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
435 |
if visLevels > 0: |
738 | 436 |
self.ConfNodeEditor.ShowLines(line, line) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
437 |
else: |
738 | 438 |
self.ConfNodeEditor.HideLines(line, line) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
439 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
440 |
if doExpand: |
738 | 441 |
self.ConfNodeEditor.ShowLines(line, line) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
442 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
443 |
if level == -1: |
738 | 444 |
level = self.ConfNodeEditor.GetFoldLevel(line) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
445 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
446 |
if level & stc.STC_FOLDLEVELHEADERFLAG: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
447 |
if force: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
448 |
if visLevels > 1: |
738 | 449 |
self.ConfNodeEditor.SetFoldExpanded(line, True) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
450 |
else: |
738 | 451 |
self.ConfNodeEditor.SetFoldExpanded(line, False) |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
452 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
453 |
line = self.Expand(line, doExpand, force, visLevels-1) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
454 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
455 |
else: |
738 | 456 |
if doExpand and self.ConfNodeEditor.GetFoldExpanded(line): |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
457 |
line = self.Expand(line, True, force, visLevels-1) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
458 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
459 |
line = self.Expand(line, False, force, visLevels-1) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
460 |
else: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
461 |
line = line + 1 |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
462 |
|
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
diff
changeset
|
463 |
return line |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
464 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
465 |
def Cut(self): |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
466 |
self.ResetBuffer() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
467 |
self.DisableEvents = True |
738 | 468 |
self.ConfNodeEditor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
469 |
self.DisableEvents = False |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
470 |
self.RefreshModel() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
471 |
self.RefreshBuffer() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
472 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
473 |
def Copy(self): |
738 | 474 |
self.ConfNodeEditor.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
475 |
|
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
476 |
def Paste(self): |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
477 |
self.ResetBuffer() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
478 |
self.DisableEvents = True |
738 | 479 |
self.ConfNodeEditor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
657
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
480 |
self.DisableEvents = False |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
481 |
self.RefreshModel() |
340c0b9caeca
Adding support for integrating Python code Editor into Beremiz frame.
laurent
parents:
654
diff
changeset
|
482 |
self.RefreshBuffer() |