lbessard@27: #!/usr/bin/env python lbessard@27: # -*- coding: utf-8 -*- lbessard@27: lbessard@27: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor lbessard@27: #based on the plcopen standard. lbessard@27: # lbessard@58: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD lbessard@27: # lbessard@27: #See COPYING file for copyrights details. lbessard@27: # lbessard@27: #This library is free software; you can redistribute it and/or lbessard@27: #modify it under the terms of the GNU General Public lbessard@27: #License as published by the Free Software Foundation; either lbessard@27: #version 2.1 of the License, or (at your option) any later version. lbessard@27: # lbessard@27: #This library is distributed in the hope that it will be useful, lbessard@27: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@27: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@58: #General Public License for more details. lbessard@27: # lbessard@27: #You should have received a copy of the GNU General Public lbessard@27: #License along with this library; if not, write to the Free Software lbessard@27: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@27: lbessard@27: import wx lbessard@64: import wx.stc lbessard@56: from types import * lbessard@27: lbessard@27: import re lbessard@27: laurent@566: from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD laurent@586: from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS laurent@586: from controls import EditorPanel laurent@566: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Textual programs Viewer class lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: lbessard@27: NEWLINE = "\n" lbessard@27: NUMBERS = [str(i) for i in xrange(10)] lbessard@27: LETTERS = ['_'] lbessard@27: for i in xrange(26): lbessard@27: LETTERS.append(chr(ord('a') + i)) lbessard@27: LETTERS.append(chr(ord('A') + i)) lbessard@27: laurent@543: [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, laurent@546: STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, laurent@566: STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10) laurent@671: [SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA] = range(7) lbessard@27: laurent@586: [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, laurent@586: ] = [wx.NewId() for _init_ctrls in range(2)] lbessard@27: lbessard@27: if wx.Platform == '__WXMSW__': lbessard@27: faces = { 'times': 'Times New Roman', lbessard@27: 'mono' : 'Courier New', lbessard@27: 'helv' : 'Arial', lbessard@27: 'other': 'Comic Sans MS', lbessard@27: 'size' : 10, lbessard@27: } lbessard@27: else: lbessard@27: faces = { 'times': 'Times', lbessard@27: 'mono' : 'Courier', lbessard@27: 'helv' : 'Helvetica', lbessard@27: 'other': 'new century schoolbook', lbessard@27: 'size' : 12, lbessard@27: } lbessard@27: re_texts = {} lbessard@27: re_texts["letter"] = "[A-Za-z]" lbessard@27: re_texts["digit"] = "[0-9]" lbessard@27: re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts lbessard@27: IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) lbessard@27: LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]"%re_texts) laurent@543: EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") lbessard@27: laurent@566: HIGHLIGHT_TYPES = { laurent@566: ERROR_HIGHLIGHT: STC_PLC_ERROR, laurent@566: SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, laurent@566: } laurent@566: lbessard@56: def GetCursorPos(old, new): lbessard@56: old_length = len(old) lbessard@56: new_length = len(new) lbessard@56: common_length = min(old_length, new_length) lbessard@56: i = 0 lbessard@56: for i in xrange(common_length): lbessard@56: if old[i] != new[i]: lbessard@56: break lbessard@56: if old_length < new_length: lbessard@56: if common_length > 0 and old[i] != new[i]: lbessard@56: return i + new_length - old_length lbessard@56: else: lbessard@56: return i + new_length - old_length + 1 lbessard@56: elif old_length > new_length or i < min(old_length, new_length) - 1: lbessard@56: if common_length > 0 and old[i] != new[i]: lbessard@56: return i lbessard@56: else: lbessard@56: return i + 1 lbessard@56: else: lbessard@56: return None lbessard@56: laurent@582: def LineStartswith(line, symbols): laurent@582: return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) lbessard@121: laurent@586: class TextViewer(EditorPanel): laurent@586: laurent@586: ID = ID_TEXTVIEWER lbessard@27: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: laurent@586: def _init_Editor(self, prnt): laurent@586: self.Editor = wx.stc.StyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, laurent@586: parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) Laurent@699: self.Editor.ParentWindow = self laurent@586: laurent@586: self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) laurent@586: self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) laurent@586: laurent@586: self.Editor.SetViewWhiteSpace(False) laurent@586: laurent@586: self.Editor.SetLexer(wx.stc.STC_LEX_CONTAINER) laurent@586: laurent@586: # Global default styles for all languages laurent@586: self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) laurent@586: self.Editor.StyleClearAll() # Reset all to be like the default laurent@586: laurent@586: self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) laurent@586: self.Editor.SetSelBackground(1, "#E0E0E0") laurent@586: laurent@586: # Highlighting styles laurent@586: self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) laurent@586: self.Editor.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces) laurent@586: laurent@586: # Indicators styles laurent@586: self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) laurent@586: if self.ParentWindow is not None and self.Controler is not None: laurent@586: self.Editor.IndicatorSetForeground(0, wx.RED) laurent@586: else: laurent@586: self.Editor.IndicatorSetForeground(0, wx.WHITE) laurent@586: laurent@586: # Line numbers in the margin laurent@586: self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) laurent@586: self.Editor.SetMarginWidth(1, 50) laurent@586: laurent@586: # Folding laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") laurent@586: self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL, wx.stc.STC_MARK_TCORNER, "white", "#808080") laurent@586: laurent@586: # Indentation size laurent@586: self.Editor.SetTabWidth(2) laurent@586: self.Editor.SetUseTabs(0) laurent@586: laurent@586: self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT| laurent@586: wx.stc.STC_MOD_BEFOREDELETE| laurent@586: wx.stc.STC_PERFORMED_USER) laurent@586: laurent@586: self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) laurent@586: self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick) laurent@586: self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) laurent@586: if self.Controler is not None: laurent@586: self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) laurent@586: self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) laurent@586: self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL) laurent@586: lbessard@249: def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): laurent@586: if tagname != "" and controler is not None: laurent@586: self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) laurent@586: laurent@600: EditorPanel.__init__(self, parent, tagname, window, controler, debug) lbessard@27: lbessard@27: self.Keywords = [] lbessard@295: self.Variables = {} laurent@543: self.Functions = {} laurent@543: self.TypeNames = [] lbessard@27: self.Jumps = [] lbessard@125: self.EnumeratedValues = [] lbessard@56: self.DisableEvents = True laurent@586: self.TextSyntax = None lbessard@56: self.CurrentAction = None laurent@566: self.Highlights = [] Laurent@738: self.SearchParams = None Laurent@738: self.SearchResults = None Laurent@738: self.CurrentFindHighlight = None lbessard@249: self.InstancePath = instancepath laurent@546: self.ContextStack = [] laurent@546: self.CallStack = [] lbessard@56: laurent@566: self.RefreshHighlightsTimer = wx.Timer(self, -1) laurent@566: self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) Laurent@696: laurent@566: def __del__(self): laurent@566: self.RefreshHighlightsTimer.Stop() laurent@566: laurent@586: def GetTitle(self): laurent@586: if self.Debug or self.TagName == "": laurent@586: if len(self.InstancePath) > 15: laurent@586: return "..." + self.InstancePath[-12:] laurent@586: return self.InstancePath laurent@586: return EditorPanel.GetTitle(self) lbessard@121: lbessard@249: def GetInstancePath(self): lbessard@249: return self.InstancePath lbessard@249: lbessard@121: def IsViewing(self, tagname): laurent@586: if self.Debug or self.TagName == "": lbessard@249: return self.InstancePath == tagname lbessard@249: else: lbessard@249: return self.TagName == tagname lbessard@121: laurent@586: def GetText(self): laurent@586: return self.Editor.GetText() laurent@586: laurent@586: def SetText(self, text): laurent@586: self.Editor.SetText(text) laurent@586: laurent@586: def SelectAll(self): laurent@586: self.Editor.SelectAll() laurent@586: laurent@586: def Colourise(self, start, end): laurent@586: self.Editor.Colourise(start, end) laurent@586: laurent@586: def StartStyling(self, pos, mask): laurent@586: self.Editor.StartStyling(pos, mask) laurent@586: laurent@586: def SetStyling(self, length, style): laurent@586: self.Editor.SetStyling(length, style) laurent@586: laurent@586: def GetCurrentPos(self): laurent@586: return self.Editor.GetCurrentPos() lbessard@121: laurent@675: def GetState(self): laurent@675: return {"cursor_pos": self.Editor.GetCurrentPos()} laurent@675: laurent@675: def SetState(self, state): Laurent@704: if self and state.has_key("cursor_pos"): laurent@687: self.Editor.GotoPos(state.get("cursor_pos", 0)) laurent@675: lbessard@56: def OnModification(self, event): lbessard@56: if not self.DisableEvents: lbessard@56: mod_type = event.GetModificationType() laurent@411: if mod_type&wx.stc.STC_MOD_BEFOREINSERT: laurent@411: if self.CurrentAction == None: laurent@411: self.StartBuffering() laurent@411: elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: laurent@411: self.Controler.EndBuffering() laurent@411: self.StartBuffering() laurent@411: self.CurrentAction = ("Add", event.GetPosition()) laurent@411: wx.CallAfter(self.RefreshModel) laurent@411: elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: laurent@411: if self.CurrentAction == None: laurent@411: self.StartBuffering() laurent@411: elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: laurent@411: self.Controler.EndBuffering() laurent@411: self.StartBuffering() laurent@411: self.CurrentAction = ("Delete", event.GetPosition()) laurent@411: wx.CallAfter(self.RefreshModel) lbessard@56: event.Skip() lbessard@27: lbessard@47: def OnDoDrop(self, event): lbessard@50: try: lbessard@50: values = eval(event.GetDragText()) lbessard@50: except: lbessard@50: values = event.GetDragText() lbessard@47: if isinstance(values, tuple): laurent@437: message = None edouard@523: if values[1] in ["program", "debug"]: lbessard@47: event.SetDragText("") edouard@523: elif values[1] in ["functionBlock", "function"]: laurent@671: blocktype = values[0] edouard@523: blockname = values[2] edouard@523: if len(values) > 3: edouard@523: blockinputs = values[3] edouard@523: else: edouard@523: blockinputs = None edouard@523: if values[1] != "function": laurent@671: if blockname == "": edouard@523: dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) edouard@523: if dialog.ShowModal() == wx.ID_OK: edouard@523: blockname = dialog.GetValue() edouard@523: else: edouard@523: return edouard@523: dialog.Destroy() edouard@523: if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: edouard@523: message = _("\"%s\" pou already exists!")%blockname edouard@523: elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: edouard@523: message = _("\"%s\" element for this pou already exists!")%blockname edouard@523: else: edouard@523: self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) laurent@586: self.RefreshVariablePanel() edouard@523: self.RefreshVariableTree() laurent@671: blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug) edouard@523: hint = ',\n '.join( edouard@523: [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + edouard@523: [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) laurent@671: if values[1] == "function": laurent@671: event.SetDragText(blocktype+"(\n "+hint+")") laurent@671: else: laurent@671: event.SetDragText(blockname+"(\n "+hint+")") laurent@437: elif values[1] == "location": laurent@437: pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) laurent@437: if len(values) > 2 and pou_type == "program": laurent@437: var_name = values[3] laurent@437: if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: laurent@448: message = _("\"%s\" pou already exists!")%var_name laurent@437: elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: laurent@448: message = _("\"%s\" element for this pou already exists!")%var_name laurent@437: else: laurent@437: if values[2] is not None: laurent@437: var_type = values[2] laurent@437: else: laurent@437: var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] laurent@437: self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, values[0], values[4]) laurent@586: self.RefreshVariablePanel() laurent@437: self.RefreshVariableTree() laurent@437: event.SetDragText(var_name) lbessard@121: else: lbessard@121: event.SetDragText("") laurent@616: elif values[1] == "Global": laurent@616: var_name = values[0] laurent@616: if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: laurent@616: message = _("\"%s\" pou already exists!")%var_name laurent@616: else: laurent@616: if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: laurent@616: self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) laurent@616: self.RefreshVariablePanel() laurent@616: self.RefreshVariableTree() laurent@616: event.SetDragText(var_name) Laurent@716: elif values[1] == "Constant": Laurent@716: event.SetDragText(values[0]) laurent@437: elif values[3] == self.TagName: laurent@437: self.ResetBuffer() laurent@437: event.SetDragText(values[0]) laurent@437: wx.CallAfter(self.RefreshModel) laurent@437: else: laurent@437: message = _("Variable don't belong to this POU!") laurent@437: if message is not None: laurent@437: dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) laurent@437: dialog.ShowModal() laurent@437: dialog.Destroy() laurent@437: event.SetDragText("") lbessard@47: event.Skip() lbessard@47: lbessard@27: def SetTextSyntax(self, syntax): lbessard@27: self.TextSyntax = syntax laurent@586: if syntax in ["ST", "ALL"]: laurent@586: self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) laurent@586: self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) laurent@586: self.Editor.SetMarginSensitive(2, 1) laurent@586: self.Editor.SetMarginWidth(2, 12) laurent@586: if syntax == "ST": laurent@586: self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS laurent@586: self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS laurent@586: else: laurent@586: self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS laurent@586: self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS laurent@586: else: laurent@586: self.BlockStartKeywords = [] laurent@586: self.BlockEndKeywords = [] lbessard@27: lbessard@27: def SetKeywords(self, keywords): lbessard@27: self.Keywords = [keyword.upper() for keyword in keywords] lbessard@27: self.Colourise(0, -1) lbessard@27: lbessard@27: def RefreshJumpList(self): laurent@543: if self.TextSyntax != "IL": laurent@543: self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] laurent@543: self.Colourise(0, -1) lbessard@27: lbessard@56: # Buffer the last model state lbessard@56: def RefreshBuffer(self): lbessard@56: self.Controler.BufferProject() lbessard@116: if self.ParentWindow: lbessard@116: self.ParentWindow.RefreshTitle() laurent@485: self.ParentWindow.RefreshFileMenu() lbessard@116: self.ParentWindow.RefreshEditMenu() lbessard@56: lbessard@56: def StartBuffering(self): lbessard@56: self.Controler.StartBuffering() lbessard@116: if self.ParentWindow: lbessard@116: self.ParentWindow.RefreshTitle() laurent@485: self.ParentWindow.RefreshFileMenu() lbessard@116: self.ParentWindow.RefreshEditMenu() lbessard@56: lbessard@56: def ResetBuffer(self): lbessard@56: if self.CurrentAction != None: lbessard@56: self.Controler.EndBuffering() lbessard@56: self.CurrentAction = None lbessard@56: laurent@586: def GetBufferState(self): laurent@586: if not self.Debug and self.TextSyntax != "ALL": laurent@586: return self.Controler.GetBufferState() laurent@586: return False, False laurent@586: laurent@586: def Undo(self): laurent@586: if not self.Debug and self.TextSyntax != "ALL": laurent@586: self.Controler.LoadPrevious() laurent@586: self.ParentWindow.CloseTabsWithoutModel() laurent@586: laurent@586: def Redo(self): laurent@586: if not self.Debug and self.TextSyntax != "ALL": laurent@586: self.Controler.LoadNext() laurent@586: self.ParentWindow.CloseTabsWithoutModel() laurent@654: laurent@586: def HasNoModel(self): laurent@586: if not self.Debug and self.TextSyntax != "ALL": laurent@586: return self.Controler.GetEditedElement(self.TagName) is None laurent@586: return False laurent@586: laurent@586: def RefreshView(self, variablepanel=True): laurent@586: EditorPanel.RefreshView(self, variablepanel) laurent@586: laurent@586: if self.Controler is not None: laurent@586: self.ResetBuffer() laurent@586: self.DisableEvents = True laurent@586: old_cursor_pos = self.GetCurrentPos() laurent@586: old_text = self.GetText() laurent@586: new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) laurent@586: self.SetText(new_text) laurent@586: new_cursor_pos = GetCursorPos(old_text, new_text) laurent@586: if new_cursor_pos != None: laurent@586: self.Editor.GotoPos(new_cursor_pos) laurent@586: else: laurent@586: self.Editor.GotoPos(old_cursor_pos) laurent@586: self.Editor.ScrollToColumn(0) laurent@586: self.RefreshJumpList() laurent@586: self.Editor.EmptyUndoBuffer() laurent@586: self.DisableEvents = False laurent@586: laurent@586: self.RefreshVariableTree() laurent@586: laurent@586: self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] laurent@586: self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] laurent@586: laurent@586: self.Functions = {} laurent@586: for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): laurent@586: for blocktype in category["list"]: laurent@586: blockname = blocktype["name"].upper() laurent@586: if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): laurent@586: interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) laurent@586: for param in ["EN", "ENO"]: laurent@586: if not interface.has_key(param): laurent@586: interface[param] = {} laurent@586: if self.Functions.has_key(blockname): laurent@586: self.Functions[blockname]["interface"].update(interface) laurent@586: self.Functions[blockname]["extensible"] |= blocktype["extensible"] laurent@586: else: laurent@586: self.Functions[blockname] = {"interface": interface, laurent@586: "extensible": blocktype["extensible"]} laurent@586: lbessard@121: self.Colourise(0, -1) laurent@582: laurent@437: def RefreshVariableTree(self): laurent@437: words = self.TagName.split("::") laurent@437: self.Variables = self.GenerateVariableTree([(variable["Name"], variable["Type"], variable["Tree"]) for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)]) laurent@437: if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": laurent@546: return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) laurent@546: if return_type is not None: laurent@546: var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug) laurent@546: self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) laurent@546: else: laurent@546: self.Variables[words[-1].upper()] = {} laurent@437: lbessard@297: def GenerateVariableTree(self, list): lbessard@297: tree = {} lbessard@299: for var_name, var_type, (var_tree, var_dimension) in list: lbessard@300: tree[var_name.upper()] = self.GenerateVariableTree(var_tree) lbessard@297: return tree lbessard@297: laurent@546: def IsValidVariable(self, name, context): laurent@546: return context is not None and context.get(name, None) is not None laurent@546: laurent@546: def IsCallParameter(self, name, call): laurent@546: if call is not None: laurent@546: return (call["interface"].get(name.upper(), None) is not None or laurent@546: call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) laurent@543: return False laurent@582: laurent@582: def RefreshLineFolding(self, line_number): laurent@586: if self.TextSyntax in ["ST", "ALL"]: laurent@586: level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) laurent@586: line = self.Editor.GetLine(line_number).strip() laurent@582: if line == "": laurent@582: if line_number > 0: laurent@586: if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): laurent@586: level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK laurent@582: else: laurent@586: level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK laurent@582: if level != wx.stc.STC_FOLDLEVELBASE: laurent@582: level |= wx.stc.STC_FOLDLEVELWHITEFLAG laurent@586: elif LineStartswith(line, self.BlockStartKeywords): laurent@582: level |= wx.stc.STC_FOLDLEVELHEADERFLAG laurent@586: elif LineStartswith(line, self.BlockEndKeywords): laurent@586: if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): laurent@586: level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK laurent@582: else: laurent@586: level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK laurent@586: self.Editor.SetFoldLevel(line_number, level) laurent@582: lbessard@27: def OnStyleNeeded(self, event): lbessard@27: self.TextChanged = True laurent@586: line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) laurent@582: if line_number == 0: lbessard@231: start_pos = last_styled_pos = 0 lbessard@231: else: laurent@586: start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 laurent@582: self.RefreshLineFolding(line_number) lbessard@27: end_pos = event.GetPosition() lbessard@27: self.StartStyling(start_pos, 0xff) lbessard@27: laurent@546: current_context = self.Variables laurent@546: current_call = None lbessard@295: lbessard@231: current_pos = last_styled_pos lbessard@27: state = SPACE lbessard@27: line = "" lbessard@27: word = "" lbessard@231: while current_pos < end_pos: laurent@586: char = chr(self.Editor.GetCharAt(current_pos)).upper() lbessard@27: line += char lbessard@27: if char == NEWLINE: laurent@546: self.ContextStack = [] laurent@546: current_context = self.Variables lbessard@27: if state == COMMENT: lbessard@231: self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) lbessard@27: elif state == NUMBER: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@27: elif state == WORD: laurent@543: if word in self.Keywords or word in self.TypeNames: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) laurent@546: elif self.IsValidVariable(word, current_context): lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) laurent@546: elif self.IsCallParameter(word, current_call): laurent@546: self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) lbessard@27: elif word in self.Functions: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) laurent@543: elif self.TextSyntax == "IL" and word in self.Jumps: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) lbessard@125: elif word in self.EnumeratedValues: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@27: else: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) laurent@546: if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): lbessard@231: self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) lbessard@231: self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) lbessard@231: self.StartStyling(current_pos, 0xff) lbessard@27: else: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) lbessard@231: last_styled_pos = current_pos lbessard@27: state = SPACE lbessard@27: line = "" laurent@582: line_number += 1 laurent@582: self.RefreshLineFolding(line_number) lbessard@27: elif line.endswith("(*") and state != COMMENT: lbessard@231: self.SetStyling(current_pos - last_styled_pos - 1, 31) lbessard@231: last_styled_pos = current_pos lbessard@295: if state == WORD: laurent@546: current_context = self.Variables lbessard@27: state = COMMENT laurent@671: elif line.endswith("{") and state != PRAGMA: laurent@671: self.SetStyling(current_pos - last_styled_pos - 1, 31) laurent@671: last_styled_pos = current_pos laurent@671: if state == WORD: laurent@671: current_context = self.Variables laurent@671: state = PRAGMA lbessard@27: elif state == COMMENT: lbessard@27: if line.endswith("*)"): lbessard@231: self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) lbessard@231: last_styled_pos = current_pos + 1 lbessard@27: state = SPACE laurent@671: elif state == PRAGMA: laurent@671: if line.endswith("}"): laurent@671: self.SetStyling(current_pos - last_styled_pos + 2, 31) laurent@671: last_styled_pos = current_pos + 1 laurent@671: state = SPACE laurent@671: elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]: laurent@543: self.SetStyling(current_pos - last_styled_pos, 31) laurent@543: last_styled_pos = current_pos laurent@543: if state == WORD: laurent@546: current_context = self.Variables laurent@543: if line.endswith("'"): laurent@543: state = STRING laurent@543: else: laurent@543: state = WSTRING laurent@543: elif state == STRING: laurent@543: if line.endswith("'") and not line.endswith("$'"): laurent@543: self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) laurent@543: last_styled_pos = current_pos + 1 laurent@543: state = SPACE laurent@543: elif state == WSTRING: laurent@543: if line.endswith('"') and not line.endswith('$"'): laurent@543: self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) laurent@543: last_styled_pos = current_pos + 1 laurent@543: state = SPACE lbessard@27: elif char in LETTERS: lbessard@27: if state == NUMBER: lbessard@27: word = "#" lbessard@27: state = WORD lbessard@27: elif state == SPACE: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) lbessard@27: word = char lbessard@231: last_styled_pos = current_pos lbessard@27: state = WORD lbessard@27: else: lbessard@27: word += char lbessard@27: elif char in NUMBERS or char == '.' and state != WORD: lbessard@27: if state == SPACE: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) lbessard@231: last_styled_pos = current_pos lbessard@27: state = NUMBER laurent@654: elif state == WORD and char != '.': lbessard@27: word += char laurent@543: elif char == '(' and state == SPACE: laurent@546: self.CallStack.append(current_call) laurent@546: current_call = None lbessard@27: else: lbessard@27: if state == WORD: laurent@543: if word in self.Keywords or word in self.TypeNames: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) laurent@546: elif self.IsValidVariable(word, current_context): lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) laurent@546: elif self.IsCallParameter(word, current_call): laurent@546: self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) lbessard@27: elif word in self.Functions: laurent@543: self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) laurent@543: elif self.TextSyntax == "IL" and word in self.Jumps: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) lbessard@125: elif word in self.EnumeratedValues: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@27: else: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) laurent@546: if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): lbessard@231: self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) lbessard@231: self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) lbessard@231: self.StartStyling(current_pos, 0xff) lbessard@295: if char == '.': lbessard@295: if word != "]": laurent@546: if current_context is not None: laurent@546: current_context = current_context.get(word, None) laurent@546: else: laurent@546: current_context = None laurent@543: elif char == '(': laurent@546: self.CallStack.append(current_call) laurent@546: current_call = self.Functions.get(word, None) laurent@546: if current_call is None and self.IsValidVariable(word, current_context): laurent@546: current_call = {"interface": current_context.get(word, {}), laurent@546: "extensible": False} laurent@546: current_context = self.Variables lbessard@295: else: lbessard@295: if char == '[': laurent@546: self.ContextStack.append(current_context.get(word, None)) laurent@546: current_context = self.Variables laurent@543: lbessard@27: word = "" lbessard@231: last_styled_pos = current_pos lbessard@27: state = SPACE lbessard@27: elif state == NUMBER: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@231: last_styled_pos = current_pos lbessard@27: state = SPACE lbessard@295: if char == ']': laurent@546: if len(self.ContextStack) > 0: laurent@546: current_context = self.ContextStack.pop() laurent@546: else: laurent@546: current_context = self.Variables lbessard@295: word = char lbessard@295: state = WORD laurent@543: elif char == ')': laurent@546: current_context = self.Variables laurent@546: if len(self.CallStack) > 0: laurent@546: current_call = self.CallStack.pop() laurent@546: else: laurent@546: current_call = None laurent@546: word = char laurent@546: state = WORD lbessard@231: current_pos += 1 lbessard@27: if state == COMMENT: lbessard@231: self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) lbessard@27: elif state == NUMBER: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@27: elif state == WORD: laurent@543: if word in self.Keywords or word in self.TypeNames: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) laurent@546: elif self.IsValidVariable(word, current_context): lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) laurent@546: elif self.IsCallParameter(word, current_call): laurent@546: self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) laurent@543: elif self.TextSyntax == "IL" and word in self.Functions: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) lbessard@27: elif word in self.Jumps: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) lbessard@125: elif word in self.EnumeratedValues: lbessard@231: self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) lbessard@231: else: lbessard@231: self.SetStyling(current_pos - last_styled_pos, 31) lbessard@231: else: lbessard@231: self.SetStyling(current_pos - start_pos, 31) laurent@566: self.ShowHighlights(start_pos, end_pos) lbessard@27: event.Skip() lbessard@27: laurent@582: def OnMarginClick(self, event): laurent@582: if event.GetMargin() == 2: laurent@586: line = self.Editor.LineFromPosition(event.GetPosition()) laurent@586: if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: laurent@586: self.Editor.ToggleFold(line) laurent@582: event.Skip() laurent@582: lbessard@27: def Cut(self): lbessard@56: self.ResetBuffer() laurent@586: self.DisableEvents = True laurent@586: self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) laurent@586: self.DisableEvents = False lbessard@136: self.RefreshModel() lbessard@56: self.RefreshBuffer() lbessard@56: lbessard@27: def Copy(self): laurent@586: self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY) lbessard@27: lbessard@27: def Paste(self): lbessard@56: self.ResetBuffer() laurent@586: self.DisableEvents = True laurent@586: self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) laurent@586: self.DisableEvents = False lbessard@136: self.RefreshModel() lbessard@56: self.RefreshBuffer() lbessard@27: Laurent@738: def Find(self, direction, search_params): Laurent@738: if self.SearchParams != search_params: Laurent@738: self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) Laurent@738: Laurent@738: self.SearchParams = search_params Laurent@738: criteria = { Laurent@738: "raw_pattern": search_params["find_pattern"], Laurent@738: "pattern": re.compile(search_params["find_pattern"]), Laurent@738: "case_sensitive": search_params["case_sensitive"], Laurent@738: "regular_expression": search_params["regular_expression"], Laurent@738: "filter": "all"} Laurent@738: Laurent@738: self.SearchResults = [ Laurent@738: (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT) Laurent@738: for infos, start, end, text in Laurent@738: self.Controler.SearchInPou(self.TagName, criteria, self.Debug)] Laurent@738: Laurent@738: if len(self.SearchResults) > 0: Laurent@738: if self.CurrentFindHighlight is not None: Laurent@738: old_idx = self.SearchResults.index(self.CurrentFindHighlight) Laurent@738: if self.SearchParams["wrap"]: Laurent@738: idx = (old_idx + direction) % len(self.SearchResults) Laurent@738: else: Laurent@738: idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) Laurent@738: if idx != old_idx: Laurent@738: self.RemoveHighlight(*self.CurrentFindHighlight) Laurent@738: self.CurrentFindHighlight = self.SearchResults[idx] Laurent@738: self.AddHighlight(*self.CurrentFindHighlight) Laurent@738: else: Laurent@738: self.CurrentFindHighlight = self.SearchResults[0] Laurent@738: self.AddHighlight(*self.CurrentFindHighlight) Laurent@738: Laurent@738: else: Laurent@738: if self.CurrentFindHighlight is not None: Laurent@738: self.RemoveHighlight(*self.CurrentFindHighlight) Laurent@738: self.CurrentFindHighlight = None Laurent@738: lbessard@27: def RefreshModel(self): lbessard@136: self.RefreshJumpList() lbessard@136: self.Controler.SetEditedElementText(self.TagName, self.GetText()) lbessard@27: lbessard@27: def OnKeyDown(self, event): laurent@586: if self.Controler is not None: laurent@586: laurent@586: if self.Editor.CallTipActive(): laurent@586: self.Editor.CallTipCancel() laurent@586: key = event.GetKeyCode() laurent@586: key_handled = False laurent@586: laurent@586: line = self.Editor.GetCurrentLine() lbessard@27: if line == 0: lbessard@27: start_pos = 0 lbessard@27: else: laurent@586: start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 lbessard@27: end_pos = self.GetCurrentPos() laurent@586: lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ") lbessard@27: laurent@586: # Code completion laurent@586: if key == wx.WXK_SPACE and event.ControlDown(): laurent@586: laurent@586: words = lineText.split(" ") laurent@586: words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] laurent@586: laurent@586: kw = [] laurent@586: laurent@586: if self.TextSyntax == "IL": laurent@586: if len(words) == 1: laurent@586: kw = self.Keywords laurent@586: elif len(words) == 2: laurent@586: if words[0].upper() in ["CAL", "CALC", "CALNC"]: laurent@586: kw = self.Functions laurent@586: elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: laurent@586: kw = self.Jumps laurent@586: else: laurent@586: kw = self.Variables.keys() laurent@586: else: laurent@586: kw = self.Keywords + self.Variables.keys() + self.Functions laurent@586: if len(kw) > 0: laurent@586: if len(words[-1]) > 0: laurent@586: kw = [keyword for keyword in kw if keyword.startswith(words[-1])] laurent@586: kw.sort() laurent@586: self.Editor.AutoCompSetIgnoreCase(True) laurent@586: self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) laurent@582: key_handled = True laurent@586: elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: laurent@586: if self.TextSyntax in ["ST", "ALL"]: laurent@586: indent = self.Editor.GetLineIndentation(line) laurent@586: if LineStartswith(lineText.strip(), self.BlockStartKeywords): laurent@619: indent = (indent / 2 + 1) * 2 laurent@586: self.Editor.AddText("\n" + " " * indent) laurent@582: key_handled = True laurent@586: elif key == wx.WXK_BACK: laurent@586: if self.TextSyntax in ["ST", "ALL"]: laurent@586: indent = self.Editor.GetLineIndentation(line) laurent@586: if lineText.strip() == "" and indent > 0: laurent@586: self.Editor.DelLineLeft() laurent@619: self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2)) laurent@586: key_handled = True laurent@586: if not key_handled: laurent@586: event.Skip() lbessard@27: lbessard@27: def OnKillFocus(self, event): laurent@586: self.Editor.AutoCompCancel() lbessard@27: event.Skip() lbessard@27: lbessard@231: #------------------------------------------------------------------------------- laurent@566: # Highlights showing functions lbessard@231: #------------------------------------------------------------------------------- lbessard@231: laurent@566: def OnRefreshHighlightsTimer(self, event): lbessard@231: self.RefreshView() laurent@566: event.Skip() laurent@566: laurent@566: def ClearHighlights(self, highlight_type=None): laurent@617: EditorPanel.ClearHighlights(self, highlight_type) laurent@617: laurent@566: if highlight_type is None: laurent@566: self.Highlights = [] laurent@566: else: laurent@566: highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) laurent@566: if highlight_type is not None: laurent@566: self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] laurent@566: self.RefreshView() laurent@566: laurent@566: def AddHighlight(self, infos, start, end, highlight_type): laurent@617: EditorPanel.AddHighlight(self, infos, start, end, highlight_type) laurent@617: laurent@566: highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) laurent@566: if infos[0] == "body" and highlight_type is not None: laurent@566: self.Highlights.append((infos[1], start, end, highlight_type)) Laurent@738: self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) laurent@566: self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) laurent@566: Laurent@738: def RemoveHighlight(self, infos, start, end, highlight_type): Laurent@738: EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type) Laurent@738: Laurent@738: highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) Laurent@738: if (infos[0] == "body" and highlight_type is not None and Laurent@738: (infos[1], start, end, highlight_type) in self.Highlights): Laurent@738: self.Highlights.remove((infos[1], start, end, highlight_type)) Laurent@738: self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) Laurent@738: laurent@566: def ShowHighlights(self, start_pos, end_pos): laurent@566: for indent, start, end, highlight_type in self.Highlights: lbessard@231: if start[0] == 0: laurent@566: highlight_start_pos = start[1] - indent laurent@566: else: laurent@589: highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 lbessard@231: if end[0] == 0: laurent@566: highlight_end_pos = end[1] - indent + 1 laurent@566: else: laurent@589: highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 laurent@566: if highlight_start_pos < end_pos and highlight_end_pos > start_pos: laurent@566: self.StartStyling(highlight_start_pos, 0xff) laurent@566: self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) laurent@589: self.StartStyling(highlight_start_pos, 0x00) laurent@589: self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) laurent@589: