|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 #based on the plcopen standard. |
|
6 # |
|
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 # |
|
9 #See COPYING file for copyrights details. |
|
10 # |
|
11 #This library is free software; you can redistribute it and/or |
|
12 #modify it under the terms of the GNU General Public |
|
13 #License as published by the Free Software Foundation; either |
|
14 #version 2.1 of the License, or (at your option) any later version. |
|
15 # |
|
16 #This library is distributed in the hope that it will be useful, |
|
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 #General Public License for more details. |
|
20 # |
|
21 #You should have received a copy of the GNU General Public |
|
22 #License along with this library; if not, write to the Free Software |
|
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
|
25 import re |
|
26 from types import * |
|
27 |
|
28 import wx |
|
29 import wx.stc |
|
30 |
|
31 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
|
32 from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES |
|
33 from EditorPanel import EditorPanel |
|
34 |
|
35 #------------------------------------------------------------------------------- |
|
36 # Textual programs Viewer class |
|
37 #------------------------------------------------------------------------------- |
|
38 |
|
39 |
|
40 NEWLINE = "\n" |
|
41 NUMBERS = [str(i) for i in xrange(10)] |
|
42 LETTERS = ['_'] |
|
43 for i in xrange(26): |
|
44 LETTERS.append(chr(ord('a') + i)) |
|
45 LETTERS.append(chr(ord('A') + i)) |
|
46 |
|
47 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, |
|
48 STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, |
|
49 STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10) |
|
50 [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
|
51 |
|
52 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
|
53 ] = [wx.NewId() for _init_ctrls in range(2)] |
|
54 |
|
55 if wx.Platform == '__WXMSW__': |
|
56 faces = { 'times': 'Times New Roman', |
|
57 'mono' : 'Courier New', |
|
58 'helv' : 'Arial', |
|
59 'other': 'Comic Sans MS', |
|
60 'size' : 10, |
|
61 } |
|
62 else: |
|
63 faces = { 'times': 'Times', |
|
64 'mono' : 'Courier', |
|
65 'helv' : 'Helvetica', |
|
66 'other': 'new century schoolbook', |
|
67 'size' : 12, |
|
68 } |
|
69 re_texts = {} |
|
70 re_texts["letter"] = "[A-Za-z]" |
|
71 re_texts["digit"] = "[0-9]" |
|
72 re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts |
|
73 IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
|
74 LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]"%re_texts) |
|
75 EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
|
76 |
|
77 HIGHLIGHT_TYPES = { |
|
78 ERROR_HIGHLIGHT: STC_PLC_ERROR, |
|
79 SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
|
80 } |
|
81 |
|
82 def GetCursorPos(old, new): |
|
83 old_length = len(old) |
|
84 new_length = len(new) |
|
85 common_length = min(old_length, new_length) |
|
86 i = 0 |
|
87 for i in xrange(common_length): |
|
88 if old[i] != new[i]: |
|
89 break |
|
90 if old_length < new_length: |
|
91 if common_length > 0 and old[i] != new[i]: |
|
92 return i + new_length - old_length |
|
93 else: |
|
94 return i + new_length - old_length + 1 |
|
95 elif old_length > new_length or i < min(old_length, new_length) - 1: |
|
96 if common_length > 0 and old[i] != new[i]: |
|
97 return i |
|
98 else: |
|
99 return i + 1 |
|
100 else: |
|
101 return None |
|
102 |
|
103 def LineStartswith(line, symbols): |
|
104 return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) |
|
105 |
|
106 class TextViewer(EditorPanel): |
|
107 |
|
108 ID = ID_TEXTVIEWER |
|
109 |
|
110 if wx.VERSION < (2, 6, 0): |
|
111 def Bind(self, event, function, id = None): |
|
112 if id is not None: |
|
113 event(self, id, function) |
|
114 else: |
|
115 event(self, function) |
|
116 |
|
117 def _init_Editor(self, prnt): |
|
118 self.Editor = wx.stc.StyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
|
119 parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
|
120 self.Editor.ParentWindow = self |
|
121 |
|
122 self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
|
123 self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
|
124 |
|
125 self.Editor.SetViewWhiteSpace(False) |
|
126 |
|
127 self.Editor.SetLexer(wx.stc.STC_LEX_CONTAINER) |
|
128 |
|
129 # Global default styles for all languages |
|
130 self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
|
131 self.Editor.StyleClearAll() # Reset all to be like the default |
|
132 |
|
133 self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
|
134 self.Editor.SetSelBackground(1, "#E0E0E0") |
|
135 |
|
136 # Highlighting styles |
|
137 self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
|
138 self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
|
139 self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
|
140 self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
|
141 self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
|
142 self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
|
143 self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
|
144 self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
|
145 self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
|
146 self.Editor.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces) |
|
147 |
|
148 # Indicators styles |
|
149 self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
|
150 if self.ParentWindow is not None and self.Controler is not None: |
|
151 self.Editor.IndicatorSetForeground(0, wx.RED) |
|
152 else: |
|
153 self.Editor.IndicatorSetForeground(0, wx.WHITE) |
|
154 |
|
155 # Line numbers in the margin |
|
156 self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
|
157 self.Editor.SetMarginWidth(1, 50) |
|
158 |
|
159 # Folding |
|
160 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") |
|
161 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") |
|
162 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") |
|
163 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") |
|
164 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
|
165 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
|
166 self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL, wx.stc.STC_MARK_TCORNER, "white", "#808080") |
|
167 |
|
168 # Indentation size |
|
169 self.Editor.SetTabWidth(2) |
|
170 self.Editor.SetUseTabs(0) |
|
171 |
|
172 self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT| |
|
173 wx.stc.STC_MOD_BEFOREDELETE| |
|
174 wx.stc.STC_PERFORMED_USER) |
|
175 |
|
176 self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) |
|
177 self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick) |
|
178 self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
|
179 if self.Controler is not None: |
|
180 self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
|
181 self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) |
|
182 self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL) |
|
183 |
|
184 def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
|
185 if tagname != "" and controler is not None: |
|
186 self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) |
|
187 |
|
188 EditorPanel.__init__(self, parent, tagname, window, controler, debug) |
|
189 |
|
190 self.Keywords = [] |
|
191 self.Variables = {} |
|
192 self.Functions = {} |
|
193 self.TypeNames = [] |
|
194 self.Jumps = [] |
|
195 self.EnumeratedValues = [] |
|
196 self.DisableEvents = True |
|
197 self.TextSyntax = None |
|
198 self.CurrentAction = None |
|
199 self.Highlights = [] |
|
200 self.SearchParams = None |
|
201 self.SearchResults = None |
|
202 self.CurrentFindHighlight = None |
|
203 self.InstancePath = instancepath |
|
204 self.ContextStack = [] |
|
205 self.CallStack = [] |
|
206 |
|
207 self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
208 self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
209 |
|
210 def __del__(self): |
|
211 self.RefreshHighlightsTimer.Stop() |
|
212 |
|
213 def GetTitle(self): |
|
214 if self.Debug or self.TagName == "": |
|
215 if len(self.InstancePath) > 15: |
|
216 return "..." + self.InstancePath[-12:] |
|
217 return self.InstancePath |
|
218 return EditorPanel.GetTitle(self) |
|
219 |
|
220 def GetInstancePath(self): |
|
221 return self.InstancePath |
|
222 |
|
223 def IsViewing(self, tagname): |
|
224 if self.Debug or self.TagName == "": |
|
225 return self.InstancePath == tagname |
|
226 else: |
|
227 return self.TagName == tagname |
|
228 |
|
229 def GetText(self): |
|
230 return self.Editor.GetText() |
|
231 |
|
232 def SetText(self, text): |
|
233 self.Editor.SetText(text) |
|
234 |
|
235 def SelectAll(self): |
|
236 self.Editor.SelectAll() |
|
237 |
|
238 def Colourise(self, start, end): |
|
239 self.Editor.Colourise(start, end) |
|
240 |
|
241 def StartStyling(self, pos, mask): |
|
242 self.Editor.StartStyling(pos, mask) |
|
243 |
|
244 def SetStyling(self, length, style): |
|
245 self.Editor.SetStyling(length, style) |
|
246 |
|
247 def GetCurrentPos(self): |
|
248 return self.Editor.GetCurrentPos() |
|
249 |
|
250 def GetState(self): |
|
251 return {"cursor_pos": self.Editor.GetCurrentPos()} |
|
252 |
|
253 def SetState(self, state): |
|
254 if self and state.has_key("cursor_pos"): |
|
255 self.Editor.GotoPos(state.get("cursor_pos", 0)) |
|
256 |
|
257 def OnModification(self, event): |
|
258 if not self.DisableEvents: |
|
259 mod_type = event.GetModificationType() |
|
260 if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
|
261 if self.CurrentAction == None: |
|
262 self.StartBuffering() |
|
263 elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
264 self.Controler.EndBuffering() |
|
265 self.StartBuffering() |
|
266 self.CurrentAction = ("Add", event.GetPosition()) |
|
267 wx.CallAfter(self.RefreshModel) |
|
268 elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
|
269 if self.CurrentAction == None: |
|
270 self.StartBuffering() |
|
271 elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
272 self.Controler.EndBuffering() |
|
273 self.StartBuffering() |
|
274 self.CurrentAction = ("Delete", event.GetPosition()) |
|
275 wx.CallAfter(self.RefreshModel) |
|
276 event.Skip() |
|
277 |
|
278 def OnDoDrop(self, event): |
|
279 try: |
|
280 values = eval(event.GetDragText()) |
|
281 except: |
|
282 values = event.GetDragText() |
|
283 if isinstance(values, tuple): |
|
284 message = None |
|
285 if values[1] in ["program", "debug"]: |
|
286 event.SetDragText("") |
|
287 elif values[1] in ["functionBlock", "function"]: |
|
288 blocktype = values[0] |
|
289 blockname = values[2] |
|
290 if len(values) > 3: |
|
291 blockinputs = values[3] |
|
292 else: |
|
293 blockinputs = None |
|
294 if values[1] != "function": |
|
295 if blockname == "": |
|
296 dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) |
|
297 if dialog.ShowModal() == wx.ID_OK: |
|
298 blockname = dialog.GetValue() |
|
299 else: |
|
300 return |
|
301 dialog.Destroy() |
|
302 if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
303 message = _("\"%s\" pou already exists!")%blockname |
|
304 elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
305 message = _("\"%s\" element for this pou already exists!")%blockname |
|
306 else: |
|
307 self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
308 self.RefreshVariablePanel() |
|
309 self.RefreshVariableTree() |
|
310 blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug) |
|
311 hint = ',\n '.join( |
|
312 [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
|
313 [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
|
314 if values[1] == "function": |
|
315 event.SetDragText(blocktype+"(\n "+hint+")") |
|
316 else: |
|
317 event.SetDragText(blockname+"(\n "+hint+")") |
|
318 elif values[1] == "location": |
|
319 pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
|
320 if len(values) > 2 and pou_type == "program": |
|
321 var_name = values[3] |
|
322 if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
323 message = _("\"%s\" pou already exists!")%var_name |
|
324 elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
325 message = _("\"%s\" element for this pou already exists!")%var_name |
|
326 else: |
|
327 location = values[0] |
|
328 if not location.startswith("%"): |
|
329 dialog = wx.SingleChoiceDialog(self.ParentWindow, |
|
330 _("Select a variable class:"), _("Variable class"), |
|
331 ["Input", "Output", "Memory"], |
|
332 wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
333 if dialog.ShowModal() == wx.ID_OK: |
|
334 selected = dialog.GetSelection() |
|
335 else: |
|
336 selected = None |
|
337 dialog.Destroy() |
|
338 if selected is None: |
|
339 event.SetDragText("") |
|
340 return |
|
341 if selected == 0: |
|
342 location = "%I" + location |
|
343 elif selected == 1: |
|
344 location = "%Q" + location |
|
345 else: |
|
346 location = "%M" + location |
|
347 if values[2] is not None: |
|
348 var_type = values[2] |
|
349 else: |
|
350 var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0] |
|
351 self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, location, values[4]) |
|
352 self.RefreshVariablePanel() |
|
353 self.RefreshVariableTree() |
|
354 event.SetDragText(var_name) |
|
355 else: |
|
356 event.SetDragText("") |
|
357 elif values[1] == "Global": |
|
358 var_name = values[0] |
|
359 if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
360 message = _("\"%s\" pou already exists!")%var_name |
|
361 else: |
|
362 if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
363 self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
|
364 self.RefreshVariablePanel() |
|
365 self.RefreshVariableTree() |
|
366 event.SetDragText(var_name) |
|
367 elif values[1] == "Constant": |
|
368 event.SetDragText(values[0]) |
|
369 elif values[3] == self.TagName: |
|
370 self.ResetBuffer() |
|
371 event.SetDragText(values[0]) |
|
372 wx.CallAfter(self.RefreshModel) |
|
373 else: |
|
374 message = _("Variable don't belong to this POU!") |
|
375 if message is not None: |
|
376 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
377 dialog.ShowModal() |
|
378 dialog.Destroy() |
|
379 event.SetDragText("") |
|
380 event.Skip() |
|
381 |
|
382 def SetTextSyntax(self, syntax): |
|
383 self.TextSyntax = syntax |
|
384 if syntax in ["ST", "ALL"]: |
|
385 self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
|
386 self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
|
387 self.Editor.SetMarginSensitive(2, 1) |
|
388 self.Editor.SetMarginWidth(2, 12) |
|
389 if syntax == "ST": |
|
390 self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
|
391 self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
|
392 else: |
|
393 self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
|
394 self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
|
395 else: |
|
396 self.BlockStartKeywords = [] |
|
397 self.BlockEndKeywords = [] |
|
398 |
|
399 def SetKeywords(self, keywords): |
|
400 self.Keywords = [keyword.upper() for keyword in keywords] |
|
401 self.Colourise(0, -1) |
|
402 |
|
403 def RefreshJumpList(self): |
|
404 if self.TextSyntax != "IL": |
|
405 self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
|
406 self.Colourise(0, -1) |
|
407 |
|
408 # Buffer the last model state |
|
409 def RefreshBuffer(self): |
|
410 self.Controler.BufferProject() |
|
411 if self.ParentWindow: |
|
412 self.ParentWindow.RefreshTitle() |
|
413 self.ParentWindow.RefreshFileMenu() |
|
414 self.ParentWindow.RefreshEditMenu() |
|
415 |
|
416 def StartBuffering(self): |
|
417 self.Controler.StartBuffering() |
|
418 if self.ParentWindow: |
|
419 self.ParentWindow.RefreshTitle() |
|
420 self.ParentWindow.RefreshFileMenu() |
|
421 self.ParentWindow.RefreshEditMenu() |
|
422 |
|
423 def ResetBuffer(self): |
|
424 if self.CurrentAction != None: |
|
425 self.Controler.EndBuffering() |
|
426 self.CurrentAction = None |
|
427 |
|
428 def GetBufferState(self): |
|
429 if not self.Debug and self.TextSyntax != "ALL": |
|
430 return self.Controler.GetBufferState() |
|
431 return False, False |
|
432 |
|
433 def Undo(self): |
|
434 if not self.Debug and self.TextSyntax != "ALL": |
|
435 self.Controler.LoadPrevious() |
|
436 self.ParentWindow.CloseTabsWithoutModel() |
|
437 |
|
438 def Redo(self): |
|
439 if not self.Debug and self.TextSyntax != "ALL": |
|
440 self.Controler.LoadNext() |
|
441 self.ParentWindow.CloseTabsWithoutModel() |
|
442 |
|
443 def HasNoModel(self): |
|
444 if not self.Debug and self.TextSyntax != "ALL": |
|
445 return self.Controler.GetEditedElement(self.TagName) is None |
|
446 return False |
|
447 |
|
448 def RefreshView(self, variablepanel=True): |
|
449 EditorPanel.RefreshView(self, variablepanel) |
|
450 |
|
451 if self.Controler is not None: |
|
452 self.ResetBuffer() |
|
453 self.DisableEvents = True |
|
454 old_cursor_pos = self.GetCurrentPos() |
|
455 old_text = self.GetText() |
|
456 new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) |
|
457 self.SetText(new_text) |
|
458 new_cursor_pos = GetCursorPos(old_text, new_text) |
|
459 if new_cursor_pos != None: |
|
460 self.Editor.GotoPos(new_cursor_pos) |
|
461 else: |
|
462 self.Editor.GotoPos(old_cursor_pos) |
|
463 self.Editor.ScrollToColumn(0) |
|
464 self.RefreshJumpList() |
|
465 self.Editor.EmptyUndoBuffer() |
|
466 self.DisableEvents = False |
|
467 |
|
468 self.RefreshVariableTree() |
|
469 |
|
470 self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
|
471 self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] |
|
472 |
|
473 self.Functions = {} |
|
474 for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
|
475 for blocktype in category["list"]: |
|
476 blockname = blocktype["name"].upper() |
|
477 if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): |
|
478 interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
|
479 for param in ["EN", "ENO"]: |
|
480 if not interface.has_key(param): |
|
481 interface[param] = {} |
|
482 if self.Functions.has_key(blockname): |
|
483 self.Functions[blockname]["interface"].update(interface) |
|
484 self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
|
485 else: |
|
486 self.Functions[blockname] = {"interface": interface, |
|
487 "extensible": blocktype["extensible"]} |
|
488 |
|
489 self.Colourise(0, -1) |
|
490 |
|
491 def RefreshVariableTree(self): |
|
492 words = self.TagName.split("::") |
|
493 self.Variables = self.GenerateVariableTree([(variable["Name"], variable["Type"], variable["Tree"]) for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)]) |
|
494 if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
|
495 return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
496 if return_type is not None: |
|
497 var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug) |
|
498 self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
499 else: |
|
500 self.Variables[words[-1].upper()] = {} |
|
501 |
|
502 def GenerateVariableTree(self, list): |
|
503 tree = {} |
|
504 for var_name, var_type, (var_tree, var_dimension) in list: |
|
505 tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
|
506 return tree |
|
507 |
|
508 def IsValidVariable(self, name, context): |
|
509 return context is not None and context.get(name, None) is not None |
|
510 |
|
511 def IsCallParameter(self, name, call): |
|
512 if call is not None: |
|
513 return (call["interface"].get(name.upper(), None) is not None or |
|
514 call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
|
515 return False |
|
516 |
|
517 def RefreshLineFolding(self, line_number): |
|
518 if self.TextSyntax in ["ST", "ALL"]: |
|
519 level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
|
520 line = self.Editor.GetLine(line_number).strip() |
|
521 if line == "": |
|
522 if line_number > 0: |
|
523 if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
524 level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
525 else: |
|
526 level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
527 if level != wx.stc.STC_FOLDLEVELBASE: |
|
528 level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
|
529 elif LineStartswith(line, self.BlockStartKeywords): |
|
530 level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
|
531 elif LineStartswith(line, self.BlockEndKeywords): |
|
532 if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
533 level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
534 else: |
|
535 level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
536 self.Editor.SetFoldLevel(line_number, level) |
|
537 |
|
538 def OnStyleNeeded(self, event): |
|
539 self.TextChanged = True |
|
540 line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
|
541 if line_number == 0: |
|
542 start_pos = last_styled_pos = 0 |
|
543 else: |
|
544 start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
|
545 self.RefreshLineFolding(line_number) |
|
546 end_pos = event.GetPosition() |
|
547 self.StartStyling(start_pos, 0xff) |
|
548 |
|
549 current_context = self.Variables |
|
550 current_call = None |
|
551 |
|
552 current_pos = last_styled_pos |
|
553 state = SPACE |
|
554 line = "" |
|
555 word = "" |
|
556 while current_pos < end_pos: |
|
557 char = chr(self.Editor.GetCharAt(current_pos)).upper() |
|
558 line += char |
|
559 if char == NEWLINE: |
|
560 self.ContextStack = [] |
|
561 current_context = self.Variables |
|
562 if state == COMMENT: |
|
563 self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) |
|
564 elif state == NUMBER: |
|
565 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
566 elif state == WORD: |
|
567 if word in self.Keywords or word in self.TypeNames: |
|
568 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
569 elif self.IsValidVariable(word, current_context): |
|
570 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
571 elif self.IsCallParameter(word, current_call): |
|
572 self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
573 elif word in self.Functions: |
|
574 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
575 elif self.TextSyntax == "IL" and word in self.Jumps: |
|
576 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
577 elif word in self.EnumeratedValues: |
|
578 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
579 else: |
|
580 self.SetStyling(current_pos - last_styled_pos, 31) |
|
581 if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
|
582 self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
583 self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
584 self.StartStyling(current_pos, 0xff) |
|
585 else: |
|
586 self.SetStyling(current_pos - last_styled_pos, 31) |
|
587 last_styled_pos = current_pos |
|
588 state = SPACE |
|
589 line = "" |
|
590 line_number += 1 |
|
591 self.RefreshLineFolding(line_number) |
|
592 elif line.endswith("(*") and state != COMMENT: |
|
593 self.SetStyling(current_pos - last_styled_pos - 1, 31) |
|
594 last_styled_pos = current_pos |
|
595 if state == WORD: |
|
596 current_context = self.Variables |
|
597 state = COMMENT |
|
598 elif line.endswith("{") and state not in [PRAGMA, DPRAGMA]: |
|
599 self.SetStyling(current_pos - last_styled_pos, 31) |
|
600 last_styled_pos = current_pos |
|
601 if state == WORD: |
|
602 current_context = self.Variables |
|
603 state = PRAGMA |
|
604 elif line.endswith("{{") and state == PRAGMA: |
|
605 self.SetStyling(current_pos - last_styled_pos, 31) |
|
606 last_styled_pos = current_pos |
|
607 state = DPRAGMA |
|
608 elif state == COMMENT: |
|
609 if line.endswith("*)"): |
|
610 self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
611 last_styled_pos = current_pos + 1 |
|
612 state = SPACE |
|
613 elif state == PRAGMA: |
|
614 if line.endswith("}"): |
|
615 self.SetStyling(current_pos - last_styled_pos, 31) |
|
616 last_styled_pos = current_pos |
|
617 state = SPACE |
|
618 elif state == DPRAGMA: |
|
619 if line.endswith("}}"): |
|
620 self.SetStyling(current_pos - last_styled_pos + 2, 31) |
|
621 last_styled_pos = current_pos + 1 |
|
622 state = SPACE |
|
623 elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]: |
|
624 self.SetStyling(current_pos - last_styled_pos, 31) |
|
625 last_styled_pos = current_pos |
|
626 if state == WORD: |
|
627 current_context = self.Variables |
|
628 if line.endswith("'"): |
|
629 state = STRING |
|
630 else: |
|
631 state = WSTRING |
|
632 elif state == STRING: |
|
633 if line.endswith("'") and not line.endswith("$'"): |
|
634 self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
635 last_styled_pos = current_pos + 1 |
|
636 state = SPACE |
|
637 elif state == WSTRING: |
|
638 if line.endswith('"') and not line.endswith('$"'): |
|
639 self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
640 last_styled_pos = current_pos + 1 |
|
641 state = SPACE |
|
642 elif char in LETTERS: |
|
643 if state == NUMBER: |
|
644 word = "#" |
|
645 state = WORD |
|
646 elif state == SPACE: |
|
647 self.SetStyling(current_pos - last_styled_pos, 31) |
|
648 word = char |
|
649 last_styled_pos = current_pos |
|
650 state = WORD |
|
651 else: |
|
652 word += char |
|
653 elif char in NUMBERS or char == '.' and state != WORD: |
|
654 if state == SPACE: |
|
655 self.SetStyling(current_pos - last_styled_pos, 31) |
|
656 last_styled_pos = current_pos |
|
657 state = NUMBER |
|
658 elif state == WORD and char != '.': |
|
659 word += char |
|
660 elif char == '(' and state == SPACE: |
|
661 self.CallStack.append(current_call) |
|
662 current_call = None |
|
663 else: |
|
664 if state == WORD: |
|
665 if word in self.Keywords or word in self.TypeNames: |
|
666 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
667 elif self.IsValidVariable(word, current_context): |
|
668 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
669 elif self.IsCallParameter(word, current_call): |
|
670 self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
671 elif word in self.Functions: |
|
672 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
673 elif self.TextSyntax == "IL" and word in self.Jumps: |
|
674 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
675 elif word in self.EnumeratedValues: |
|
676 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
677 else: |
|
678 self.SetStyling(current_pos - last_styled_pos, 31) |
|
679 if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
|
680 self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
681 self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
682 self.StartStyling(current_pos, 0xff) |
|
683 if char == '.': |
|
684 if word != "]": |
|
685 if current_context is not None: |
|
686 current_context = current_context.get(word, None) |
|
687 else: |
|
688 current_context = None |
|
689 elif char == '(': |
|
690 self.CallStack.append(current_call) |
|
691 current_call = self.Functions.get(word, None) |
|
692 if current_call is None and self.IsValidVariable(word, current_context): |
|
693 current_call = {"interface": current_context.get(word, {}), |
|
694 "extensible": False} |
|
695 current_context = self.Variables |
|
696 else: |
|
697 if char == '[' and current_context is not None: |
|
698 self.ContextStack.append(current_context.get(word, None)) |
|
699 current_context = self.Variables |
|
700 |
|
701 word = "" |
|
702 last_styled_pos = current_pos |
|
703 state = SPACE |
|
704 elif state == NUMBER: |
|
705 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
706 last_styled_pos = current_pos |
|
707 state = SPACE |
|
708 if char == ']': |
|
709 if len(self.ContextStack) > 0: |
|
710 current_context = self.ContextStack.pop() |
|
711 else: |
|
712 current_context = self.Variables |
|
713 word = char |
|
714 state = WORD |
|
715 elif char == ')': |
|
716 current_context = self.Variables |
|
717 if len(self.CallStack) > 0: |
|
718 current_call = self.CallStack.pop() |
|
719 else: |
|
720 current_call = None |
|
721 word = char |
|
722 state = WORD |
|
723 current_pos += 1 |
|
724 if state == COMMENT: |
|
725 self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
726 elif state == NUMBER: |
|
727 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
728 elif state == WORD: |
|
729 if word in self.Keywords or word in self.TypeNames: |
|
730 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
731 elif self.IsValidVariable(word, current_context): |
|
732 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
733 elif self.IsCallParameter(word, current_call): |
|
734 self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
735 elif self.TextSyntax == "IL" and word in self.Functions: |
|
736 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
737 elif word in self.Jumps: |
|
738 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
739 elif word in self.EnumeratedValues: |
|
740 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
741 else: |
|
742 self.SetStyling(current_pos - last_styled_pos, 31) |
|
743 else: |
|
744 self.SetStyling(current_pos - start_pos, 31) |
|
745 self.ShowHighlights(start_pos, end_pos) |
|
746 event.Skip() |
|
747 |
|
748 def OnMarginClick(self, event): |
|
749 if event.GetMargin() == 2: |
|
750 line = self.Editor.LineFromPosition(event.GetPosition()) |
|
751 if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
|
752 self.Editor.ToggleFold(line) |
|
753 event.Skip() |
|
754 |
|
755 def Cut(self): |
|
756 self.ResetBuffer() |
|
757 self.DisableEvents = True |
|
758 self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
|
759 self.DisableEvents = False |
|
760 self.RefreshModel() |
|
761 self.RefreshBuffer() |
|
762 |
|
763 def Copy(self): |
|
764 self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
|
765 |
|
766 def Paste(self): |
|
767 self.ResetBuffer() |
|
768 self.DisableEvents = True |
|
769 self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
|
770 self.DisableEvents = False |
|
771 self.RefreshModel() |
|
772 self.RefreshBuffer() |
|
773 |
|
774 def Find(self, direction, search_params): |
|
775 if self.SearchParams != search_params: |
|
776 self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
|
777 |
|
778 self.SearchParams = search_params |
|
779 criteria = { |
|
780 "raw_pattern": search_params["find_pattern"], |
|
781 "pattern": re.compile(search_params["find_pattern"]), |
|
782 "case_sensitive": search_params["case_sensitive"], |
|
783 "regular_expression": search_params["regular_expression"], |
|
784 "filter": "all"} |
|
785 |
|
786 self.SearchResults = [ |
|
787 (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT) |
|
788 for infos, start, end, text in |
|
789 self.Controler.SearchInPou(self.TagName, criteria, self.Debug)] |
|
790 |
|
791 if len(self.SearchResults) > 0: |
|
792 if self.CurrentFindHighlight is not None: |
|
793 old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
794 if self.SearchParams["wrap"]: |
|
795 idx = (old_idx + direction) % len(self.SearchResults) |
|
796 else: |
|
797 idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
798 if idx != old_idx: |
|
799 self.RemoveHighlight(*self.CurrentFindHighlight) |
|
800 self.CurrentFindHighlight = self.SearchResults[idx] |
|
801 self.AddHighlight(*self.CurrentFindHighlight) |
|
802 else: |
|
803 self.CurrentFindHighlight = self.SearchResults[0] |
|
804 self.AddHighlight(*self.CurrentFindHighlight) |
|
805 |
|
806 else: |
|
807 if self.CurrentFindHighlight is not None: |
|
808 self.RemoveHighlight(*self.CurrentFindHighlight) |
|
809 self.CurrentFindHighlight = None |
|
810 |
|
811 def RefreshModel(self): |
|
812 self.RefreshJumpList() |
|
813 self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
|
814 |
|
815 def OnKeyDown(self, event): |
|
816 if self.Controler is not None: |
|
817 |
|
818 if self.Editor.CallTipActive(): |
|
819 self.Editor.CallTipCancel() |
|
820 key = event.GetKeyCode() |
|
821 key_handled = False |
|
822 |
|
823 line = self.Editor.GetCurrentLine() |
|
824 if line == 0: |
|
825 start_pos = 0 |
|
826 else: |
|
827 start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
|
828 end_pos = self.GetCurrentPos() |
|
829 lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ") |
|
830 |
|
831 # Code completion |
|
832 if key == wx.WXK_SPACE and event.ControlDown(): |
|
833 |
|
834 words = lineText.split(" ") |
|
835 words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] |
|
836 |
|
837 kw = [] |
|
838 |
|
839 if self.TextSyntax == "IL": |
|
840 if len(words) == 1: |
|
841 kw = self.Keywords |
|
842 elif len(words) == 2: |
|
843 if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
844 kw = self.Functions |
|
845 elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
846 kw = self.Jumps |
|
847 else: |
|
848 kw = self.Variables.keys() |
|
849 else: |
|
850 kw = self.Keywords + self.Variables.keys() + self.Functions.keys() |
|
851 if len(kw) > 0: |
|
852 if len(words[-1]) > 0: |
|
853 kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
854 kw.sort() |
|
855 self.Editor.AutoCompSetIgnoreCase(True) |
|
856 self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
857 key_handled = True |
|
858 elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
|
859 if self.TextSyntax in ["ST", "ALL"]: |
|
860 indent = self.Editor.GetLineIndentation(line) |
|
861 if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
|
862 indent = (indent / 2 + 1) * 2 |
|
863 self.Editor.AddText("\n" + " " * indent) |
|
864 key_handled = True |
|
865 elif key == wx.WXK_BACK: |
|
866 if self.TextSyntax in ["ST", "ALL"]: |
|
867 indent = self.Editor.GetLineIndentation(line) |
|
868 if lineText.strip() == "" and indent > 0: |
|
869 self.Editor.DelLineLeft() |
|
870 self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2)) |
|
871 key_handled = True |
|
872 if not key_handled: |
|
873 event.Skip() |
|
874 |
|
875 def OnKillFocus(self, event): |
|
876 self.Editor.AutoCompCancel() |
|
877 event.Skip() |
|
878 |
|
879 #------------------------------------------------------------------------------- |
|
880 # Highlights showing functions |
|
881 #------------------------------------------------------------------------------- |
|
882 |
|
883 def OnRefreshHighlightsTimer(self, event): |
|
884 self.RefreshView() |
|
885 event.Skip() |
|
886 |
|
887 def ClearHighlights(self, highlight_type=None): |
|
888 EditorPanel.ClearHighlights(self, highlight_type) |
|
889 |
|
890 if highlight_type is None: |
|
891 self.Highlights = [] |
|
892 else: |
|
893 highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
894 if highlight_type is not None: |
|
895 self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
896 self.RefreshView() |
|
897 |
|
898 def AddHighlight(self, infos, start, end, highlight_type): |
|
899 EditorPanel.AddHighlight(self, infos, start, end, highlight_type) |
|
900 |
|
901 highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
902 if infos[0] == "body" and highlight_type is not None: |
|
903 self.Highlights.append((infos[1], start, end, highlight_type)) |
|
904 self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) |
|
905 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
906 |
|
907 def RemoveHighlight(self, infos, start, end, highlight_type): |
|
908 EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type) |
|
909 |
|
910 highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
911 if (infos[0] == "body" and highlight_type is not None and |
|
912 (infos[1], start, end, highlight_type) in self.Highlights): |
|
913 self.Highlights.remove((infos[1], start, end, highlight_type)) |
|
914 self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
915 |
|
916 def ShowHighlights(self, start_pos, end_pos): |
|
917 for indent, start, end, highlight_type in self.Highlights: |
|
918 if start[0] == 0: |
|
919 highlight_start_pos = start[1] - indent |
|
920 else: |
|
921 highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
|
922 if end[0] == 0: |
|
923 highlight_end_pos = end[1] - indent + 1 |
|
924 else: |
|
925 highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
|
926 if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
|
927 self.StartStyling(highlight_start_pos, 0xff) |
|
928 self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
|
929 self.StartStyling(highlight_start_pos, 0x00) |
|
930 self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) |
|
931 |