author | laurent |
Tue, 31 Jan 2012 23:58:16 +0100 | |
changeset 636 | 44978a2b9703 |
parent 619 | fc03645162b5 |
child 654 | f8445d00613d |
permissions | -rw-r--r-- |
27 | 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 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
27 | 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 |
|
58 | 19 |
#General Public License for more details. |
27 | 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 wx |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
26 |
import wx.stc |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
27 |
from types import * |
27 | 28 |
|
29 |
import re |
|
30 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
31 |
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
32 |
from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
33 |
from controls import EditorPanel |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
34 |
|
27 | 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 |
||
543 | 47 |
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, |
546 | 48 |
STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
49 |
STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10) |
543 | 50 |
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT] = range(6) |
27 | 51 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
52 |
[ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
53 |
] = [wx.NewId() for _init_ctrls in range(2)] |
27 | 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) |
|
543 | 75 |
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
27 | 76 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
77 |
HIGHLIGHT_TYPES = { |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
78 |
ERROR_HIGHLIGHT: STC_PLC_ERROR, |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
79 |
SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
80 |
} |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
81 |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
82 |
def GetCursorPos(old, new): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
83 |
old_length = len(old) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
84 |
new_length = len(new) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
85 |
common_length = min(old_length, new_length) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
86 |
i = 0 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
87 |
for i in xrange(common_length): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
88 |
if old[i] != new[i]: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
89 |
break |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
90 |
if old_length < new_length: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
91 |
if common_length > 0 and old[i] != new[i]: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
92 |
return i + new_length - old_length |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
93 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
94 |
return i + new_length - old_length + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
95 |
elif old_length > new_length or i < min(old_length, new_length) - 1: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
96 |
if common_length > 0 and old[i] != new[i]: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
97 |
return i |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
98 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
99 |
return i + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
100 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
101 |
return None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
102 |
|
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
103 |
def LineStartswith(line, symbols): |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
104 |
return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) |
121 | 105 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
106 |
class TextViewer(EditorPanel): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
107 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
108 |
ID = ID_TEXTVIEWER |
27 | 109 |
|
113 | 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 |
||
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
117 |
def _init_Editor(self, prnt): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
118 |
self.Editor = wx.stc.StyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
119 |
parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
120 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
121 |
self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
122 |
self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
123 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
124 |
self.Editor.SetViewWhiteSpace(False) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
125 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
126 |
self.Editor.SetLexer(wx.stc.STC_LEX_CONTAINER) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
127 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
128 |
# Global default styles for all languages |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
129 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
130 |
self.Editor.StyleClearAll() # Reset all to be like the default |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
131 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
132 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
133 |
self.Editor.SetSelBackground(1, "#E0E0E0") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
134 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
135 |
# Highlighting styles |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
136 |
self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
137 |
self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
138 |
self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
139 |
self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
140 |
self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
141 |
self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
142 |
self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
143 |
self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
144 |
self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
145 |
self.Editor.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
146 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
147 |
# Indicators styles |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
148 |
self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
149 |
if self.ParentWindow is not None and self.Controler is not None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
150 |
self.Editor.IndicatorSetForeground(0, wx.RED) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
151 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
152 |
self.Editor.IndicatorSetForeground(0, wx.WHITE) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
153 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
154 |
# Line numbers in the margin |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
155 |
self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
156 |
self.Editor.SetMarginWidth(1, 50) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
157 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
158 |
# Folding |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
159 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
160 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
161 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
162 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
163 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
164 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
165 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL, wx.stc.STC_MARK_TCORNER, "white", "#808080") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
166 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
167 |
# Indentation size |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
168 |
self.Editor.SetTabWidth(2) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
169 |
self.Editor.SetUseTabs(0) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
170 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
171 |
self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT| |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
172 |
wx.stc.STC_MOD_BEFOREDELETE| |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
173 |
wx.stc.STC_PERFORMED_USER) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
174 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
175 |
self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
176 |
self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
177 |
self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
178 |
if self.Controler is not None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
179 |
self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
180 |
self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
181 |
self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
182 |
|
249 | 183 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
184 |
if tagname != "" and controler is not None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
185 |
self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
186 |
|
600
7db729686416
Making variable panel not editable when showing variables of debugging block
laurent
parents:
589
diff
changeset
|
187 |
EditorPanel.__init__(self, parent, tagname, window, controler, debug) |
27 | 188 |
|
189 |
self.Keywords = [] |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
190 |
self.Variables = {} |
543 | 191 |
self.Functions = {} |
192 |
self.TypeNames = [] |
|
27 | 193 |
self.Jumps = [] |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
194 |
self.EnumeratedValues = [] |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
195 |
self.DisableEvents = True |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
196 |
self.TextSyntax = None |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
197 |
self.CurrentAction = None |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
198 |
self.Highlights = [] |
249 | 199 |
self.InstancePath = instancepath |
546 | 200 |
self.ContextStack = [] |
201 |
self.CallStack = [] |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
202 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
203 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
204 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
205 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
206 |
def __del__(self): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
207 |
self.RefreshHighlightsTimer.Stop() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
208 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
209 |
def GetTitle(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
210 |
if self.Debug or self.TagName == "": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
211 |
if len(self.InstancePath) > 15: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
212 |
return "..." + self.InstancePath[-12:] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
213 |
return self.InstancePath |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
214 |
return EditorPanel.GetTitle(self) |
121 | 215 |
|
249 | 216 |
def GetInstancePath(self): |
217 |
return self.InstancePath |
|
218 |
||
121 | 219 |
def IsViewing(self, tagname): |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
220 |
if self.Debug or self.TagName == "": |
249 | 221 |
return self.InstancePath == tagname |
222 |
else: |
|
223 |
return self.TagName == tagname |
|
121 | 224 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
225 |
def GetText(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
226 |
return self.Editor.GetText() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
227 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
228 |
def SetText(self, text): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
229 |
self.Editor.SetText(text) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
230 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
231 |
def SelectAll(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
232 |
self.Editor.SelectAll() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
233 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
234 |
def Colourise(self, start, end): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
235 |
self.Editor.Colourise(start, end) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
236 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
237 |
def StartStyling(self, pos, mask): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
238 |
self.Editor.StartStyling(pos, mask) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
239 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
240 |
def SetStyling(self, length, style): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
241 |
self.Editor.SetStyling(length, style) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
242 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
243 |
def GetCurrentPos(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
244 |
return self.Editor.GetCurrentPos() |
121 | 245 |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
246 |
def OnModification(self, event): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
247 |
if not self.DisableEvents: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
248 |
mod_type = event.GetModificationType() |
411 | 249 |
if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
250 |
if self.CurrentAction == None: |
|
251 |
self.StartBuffering() |
|
252 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
253 |
self.Controler.EndBuffering() |
|
254 |
self.StartBuffering() |
|
255 |
self.CurrentAction = ("Add", event.GetPosition()) |
|
256 |
wx.CallAfter(self.RefreshModel) |
|
257 |
elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
|
258 |
if self.CurrentAction == None: |
|
259 |
self.StartBuffering() |
|
260 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
261 |
self.Controler.EndBuffering() |
|
262 |
self.StartBuffering() |
|
263 |
self.CurrentAction = ("Delete", event.GetPosition()) |
|
264 |
wx.CallAfter(self.RefreshModel) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
265 |
event.Skip() |
27 | 266 |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
267 |
def OnDoDrop(self, event): |
50 | 268 |
try: |
269 |
values = eval(event.GetDragText()) |
|
270 |
except: |
|
271 |
values = event.GetDragText() |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
272 |
if isinstance(values, tuple): |
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
273 |
message = None |
523 | 274 |
if values[1] in ["program", "debug"]: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
275 |
event.SetDragText("") |
523 | 276 |
elif values[1] in ["functionBlock", "function"]: |
277 |
blockname = values[2] |
|
278 |
if len(values) > 3: |
|
279 |
blockinputs = values[3] |
|
280 |
else: |
|
281 |
blockinputs = None |
|
282 |
if values[1] != "function": |
|
283 |
if blockname == "": |
|
284 |
dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) |
|
285 |
if dialog.ShowModal() == wx.ID_OK: |
|
286 |
blockname = dialog.GetValue() |
|
287 |
else: |
|
288 |
return |
|
289 |
dialog.Destroy() |
|
290 |
if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
291 |
message = _("\"%s\" pou already exists!")%blockname |
|
292 |
elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
293 |
message = _("\"%s\" element for this pou already exists!")%blockname |
|
294 |
else: |
|
295 |
self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
296 |
self.RefreshVariablePanel() |
523 | 297 |
self.RefreshVariableTree() |
298 |
blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug) |
|
299 |
hint = ',\n '.join( |
|
300 |
[ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
|
301 |
[ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
|
302 |
event.SetDragText(blockname+"(\n "+hint+")") |
|
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
303 |
elif values[1] == "location": |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
304 |
pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
305 |
if len(values) > 2 and pou_type == "program": |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
306 |
var_name = values[3] |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
307 |
if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
448 | 308 |
message = _("\"%s\" pou already exists!")%var_name |
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
309 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
448 | 310 |
message = _("\"%s\" element for this pou already exists!")%var_name |
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
311 |
else: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
312 |
if values[2] is not None: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
313 |
var_type = values[2] |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
314 |
else: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
315 |
var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0] |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
316 |
self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, values[0], values[4]) |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
317 |
self.RefreshVariablePanel() |
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
318 |
self.RefreshVariableTree() |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
319 |
event.SetDragText(var_name) |
121 | 320 |
else: |
321 |
event.SetDragText("") |
|
616
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
322 |
elif values[1] == "Global": |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
323 |
var_name = values[0] |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
324 |
if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
325 |
message = _("\"%s\" pou already exists!")%var_name |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
326 |
else: |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
327 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
328 |
self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
329 |
self.RefreshVariablePanel() |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
330 |
self.RefreshVariableTree() |
8a60ffcfd70b
Adding support for drag'n dropping variable from global defined in configurations and resources to POU variable panel or body editor for declaring external variables
laurent
parents:
613
diff
changeset
|
331 |
event.SetDragText(var_name) |
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
332 |
elif values[3] == self.TagName: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
333 |
self.ResetBuffer() |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
334 |
event.SetDragText(values[0]) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
335 |
wx.CallAfter(self.RefreshModel) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
336 |
else: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
337 |
message = _("Variable don't belong to this POU!") |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
338 |
if message is not None: |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
339 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
340 |
dialog.ShowModal() |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
341 |
dialog.Destroy() |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
342 |
event.SetDragText("") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
343 |
event.Skip() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
344 |
|
27 | 345 |
def SetTextSyntax(self, syntax): |
346 |
self.TextSyntax = syntax |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
347 |
if syntax in ["ST", "ALL"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
348 |
self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
349 |
self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
350 |
self.Editor.SetMarginSensitive(2, 1) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
351 |
self.Editor.SetMarginWidth(2, 12) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
352 |
if syntax == "ST": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
353 |
self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
354 |
self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
355 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
356 |
self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
357 |
self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
358 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
359 |
self.BlockStartKeywords = [] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
360 |
self.BlockEndKeywords = [] |
27 | 361 |
|
362 |
def SetKeywords(self, keywords): |
|
363 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
364 |
self.Colourise(0, -1) |
|
365 |
||
366 |
def RefreshJumpList(self): |
|
543 | 367 |
if self.TextSyntax != "IL": |
368 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
|
369 |
self.Colourise(0, -1) |
|
27 | 370 |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
371 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
372 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
373 |
self.Controler.BufferProject() |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
374 |
if self.ParentWindow: |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
375 |
self.ParentWindow.RefreshTitle() |
485
d5ebb8eac934
Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents:
448
diff
changeset
|
376 |
self.ParentWindow.RefreshFileMenu() |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
377 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
378 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
379 |
def StartBuffering(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
380 |
self.Controler.StartBuffering() |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
381 |
if self.ParentWindow: |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
382 |
self.ParentWindow.RefreshTitle() |
485
d5ebb8eac934
Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents:
448
diff
changeset
|
383 |
self.ParentWindow.RefreshFileMenu() |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
384 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
385 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
386 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
387 |
if self.CurrentAction != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
388 |
self.Controler.EndBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
389 |
self.CurrentAction = None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
390 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
391 |
def GetBufferState(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
392 |
if not self.Debug and self.TextSyntax != "ALL": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
393 |
return self.Controler.GetBufferState() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
394 |
return False, False |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
395 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
396 |
def Undo(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
397 |
if not self.Debug and self.TextSyntax != "ALL": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
398 |
self.Controler.LoadPrevious() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
399 |
self.ParentWindow.CloseTabsWithoutModel() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
400 |
self.ParentWindow.RefreshEditor() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
401 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
402 |
def Redo(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
403 |
if not self.Debug and self.TextSyntax != "ALL": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
404 |
self.Controler.LoadNext() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
405 |
self.ParentWindow.CloseTabsWithoutModel() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
406 |
self.ParentWindow.RefreshEditor() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
407 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
408 |
def HasNoModel(self): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
409 |
if not self.Debug and self.TextSyntax != "ALL": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
410 |
return self.Controler.GetEditedElement(self.TagName) is None |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
411 |
return False |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
412 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
413 |
def RefreshView(self, variablepanel=True): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
414 |
EditorPanel.RefreshView(self, variablepanel) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
415 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
416 |
if self.Controler is not None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
417 |
self.ResetBuffer() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
418 |
self.DisableEvents = True |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
419 |
old_cursor_pos = self.GetCurrentPos() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
420 |
old_text = self.GetText() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
421 |
new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
422 |
self.SetText(new_text) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
423 |
new_cursor_pos = GetCursorPos(old_text, new_text) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
424 |
if new_cursor_pos != None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
425 |
self.Editor.GotoPos(new_cursor_pos) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
426 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
427 |
self.Editor.GotoPos(old_cursor_pos) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
428 |
self.Editor.ScrollToColumn(0) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
429 |
self.RefreshJumpList() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
430 |
self.Editor.EmptyUndoBuffer() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
431 |
self.DisableEvents = False |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
432 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
433 |
self.RefreshVariableTree() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
434 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
435 |
self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
436 |
self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
437 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
438 |
self.Functions = {} |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
439 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
440 |
for blocktype in category["list"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
441 |
blockname = blocktype["name"].upper() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
442 |
if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
443 |
interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
444 |
for param in ["EN", "ENO"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
445 |
if not interface.has_key(param): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
446 |
interface[param] = {} |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
447 |
if self.Functions.has_key(blockname): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
448 |
self.Functions[blockname]["interface"].update(interface) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
449 |
self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
450 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
451 |
self.Functions[blockname] = {"interface": interface, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
452 |
"extensible": blocktype["extensible"]} |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
453 |
|
121 | 454 |
self.Colourise(0, -1) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
455 |
|
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
456 |
def RefreshVariableTree(self): |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
457 |
words = self.TagName.split("::") |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
458 |
self.Variables = self.GenerateVariableTree([(variable["Name"], variable["Type"], variable["Tree"]) for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)]) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
459 |
if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
546 | 460 |
return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
461 |
if return_type is not None: |
|
462 |
var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug) |
|
463 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
464 |
else: |
|
465 |
self.Variables[words[-1].upper()] = {} |
|
437
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
466 |
|
297
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
467 |
def GenerateVariableTree(self, list): |
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
468 |
tree = {} |
299
15669fe26e56
Adding support for generating real array dimension in variable blocks
lbessard
parents:
297
diff
changeset
|
469 |
for var_name, var_type, (var_tree, var_dimension) in list: |
300 | 470 |
tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
297
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
471 |
return tree |
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
472 |
|
546 | 473 |
def IsValidVariable(self, name, context): |
474 |
return context is not None and context.get(name, None) is not None |
|
475 |
||
476 |
def IsCallParameter(self, name, call): |
|
477 |
if call is not None: |
|
478 |
return (call["interface"].get(name.upper(), None) is not None or |
|
479 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
|
543 | 480 |
return False |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
481 |
|
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
482 |
def RefreshLineFolding(self, line_number): |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
483 |
if self.TextSyntax in ["ST", "ALL"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
484 |
level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
485 |
line = self.Editor.GetLine(line_number).strip() |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
486 |
if line == "": |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
487 |
if line_number > 0: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
488 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
489 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
490 |
else: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
491 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
492 |
if level != wx.stc.STC_FOLDLEVELBASE: |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
493 |
level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
494 |
elif LineStartswith(line, self.BlockStartKeywords): |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
495 |
level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
496 |
elif LineStartswith(line, self.BlockEndKeywords): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
497 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
498 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
499 |
else: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
500 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
501 |
self.Editor.SetFoldLevel(line_number, level) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
502 |
|
27 | 503 |
def OnStyleNeeded(self, event): |
504 |
self.TextChanged = True |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
505 |
line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
506 |
if line_number == 0: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
507 |
start_pos = last_styled_pos = 0 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
508 |
else: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
509 |
start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
510 |
self.RefreshLineFolding(line_number) |
27 | 511 |
end_pos = event.GetPosition() |
512 |
self.StartStyling(start_pos, 0xff) |
|
513 |
||
546 | 514 |
current_context = self.Variables |
515 |
current_call = None |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
516 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
517 |
current_pos = last_styled_pos |
27 | 518 |
state = SPACE |
519 |
line = "" |
|
520 |
word = "" |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
521 |
while current_pos < end_pos: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
522 |
char = chr(self.Editor.GetCharAt(current_pos)).upper() |
27 | 523 |
line += char |
524 |
if char == NEWLINE: |
|
546 | 525 |
self.ContextStack = [] |
526 |
current_context = self.Variables |
|
27 | 527 |
if state == COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
528 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) |
27 | 529 |
elif state == NUMBER: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
530 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 531 |
elif state == WORD: |
543 | 532 |
if word in self.Keywords or word in self.TypeNames: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
533 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 534 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
535 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 536 |
elif self.IsCallParameter(word, current_call): |
537 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
27 | 538 |
elif word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
539 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
543 | 540 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
541 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
542 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
543 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 544 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
545 |
self.SetStyling(current_pos - last_styled_pos, 31) |
546 | 546 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
547 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
548 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
549 |
self.StartStyling(current_pos, 0xff) |
27 | 550 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
551 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
552 |
last_styled_pos = current_pos |
27 | 553 |
state = SPACE |
554 |
line = "" |
|
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
555 |
line_number += 1 |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
556 |
self.RefreshLineFolding(line_number) |
27 | 557 |
elif line.endswith("(*") and state != COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
558 |
self.SetStyling(current_pos - last_styled_pos - 1, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
559 |
last_styled_pos = current_pos |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
560 |
if state == WORD: |
546 | 561 |
current_context = self.Variables |
27 | 562 |
state = COMMENT |
563 |
elif state == COMMENT: |
|
564 |
if line.endswith("*)"): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
565 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
566 |
last_styled_pos = current_pos + 1 |
27 | 567 |
state = SPACE |
543 | 568 |
elif (line.endswith("'") or line.endswith('"')) and state not in [COMMENT, STRING, WSTRING]: |
569 |
self.SetStyling(current_pos - last_styled_pos, 31) |
|
570 |
last_styled_pos = current_pos |
|
571 |
if state == WORD: |
|
546 | 572 |
current_context = self.Variables |
543 | 573 |
if line.endswith("'"): |
574 |
state = STRING |
|
575 |
else: |
|
576 |
state = WSTRING |
|
577 |
elif state == STRING: |
|
578 |
if line.endswith("'") and not line.endswith("$'"): |
|
579 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
580 |
last_styled_pos = current_pos + 1 |
|
581 |
state = SPACE |
|
582 |
elif state == WSTRING: |
|
583 |
if line.endswith('"') and not line.endswith('$"'): |
|
584 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
585 |
last_styled_pos = current_pos + 1 |
|
586 |
state = SPACE |
|
27 | 587 |
elif char in LETTERS: |
588 |
if state == NUMBER: |
|
589 |
word = "#" |
|
590 |
state = WORD |
|
591 |
elif state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
592 |
self.SetStyling(current_pos - last_styled_pos, 31) |
27 | 593 |
word = char |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
594 |
last_styled_pos = current_pos |
27 | 595 |
state = WORD |
596 |
else: |
|
597 |
word += char |
|
598 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
599 |
if state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
600 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
601 |
last_styled_pos = current_pos |
27 | 602 |
state = NUMBER |
603 |
if state == WORD and char != '.': |
|
604 |
word += char |
|
543 | 605 |
elif char == '(' and state == SPACE: |
546 | 606 |
self.CallStack.append(current_call) |
607 |
current_call = None |
|
27 | 608 |
else: |
609 |
if state == WORD: |
|
543 | 610 |
if word in self.Keywords or word in self.TypeNames: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
611 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 612 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
613 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 614 |
elif self.IsCallParameter(word, current_call): |
615 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
27 | 616 |
elif word in self.Functions: |
543 | 617 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
618 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
619 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
620 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
621 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 622 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
623 |
self.SetStyling(current_pos - last_styled_pos, 31) |
546 | 624 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
625 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
626 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
627 |
self.StartStyling(current_pos, 0xff) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
628 |
if char == '.': |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
629 |
if word != "]": |
546 | 630 |
if current_context is not None: |
631 |
current_context = current_context.get(word, None) |
|
632 |
else: |
|
633 |
current_context = None |
|
543 | 634 |
elif char == '(': |
546 | 635 |
self.CallStack.append(current_call) |
636 |
current_call = self.Functions.get(word, None) |
|
637 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
638 |
current_call = {"interface": current_context.get(word, {}), |
|
639 |
"extensible": False} |
|
640 |
current_context = self.Variables |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
641 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
642 |
if char == '[': |
546 | 643 |
self.ContextStack.append(current_context.get(word, None)) |
644 |
current_context = self.Variables |
|
543 | 645 |
|
27 | 646 |
word = "" |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
647 |
last_styled_pos = current_pos |
27 | 648 |
state = SPACE |
649 |
elif state == NUMBER: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
650 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
651 |
last_styled_pos = current_pos |
27 | 652 |
state = SPACE |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
653 |
if char == ']': |
546 | 654 |
if len(self.ContextStack) > 0: |
655 |
current_context = self.ContextStack.pop() |
|
656 |
else: |
|
657 |
current_context = self.Variables |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
658 |
word = char |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
659 |
state = WORD |
543 | 660 |
elif char == ')': |
546 | 661 |
current_context = self.Variables |
662 |
if len(self.CallStack) > 0: |
|
663 |
current_call = self.CallStack.pop() |
|
664 |
else: |
|
665 |
current_call = None |
|
666 |
word = char |
|
667 |
state = WORD |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
668 |
current_pos += 1 |
27 | 669 |
if state == COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
670 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
27 | 671 |
elif state == NUMBER: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
672 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 673 |
elif state == WORD: |
543 | 674 |
if word in self.Keywords or word in self.TypeNames: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
675 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 676 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
677 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 678 |
elif self.IsCallParameter(word, current_call): |
679 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
543 | 680 |
elif self.TextSyntax == "IL" and word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
681 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
27 | 682 |
elif word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
683 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
684 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
685 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
686 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
687 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
688 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
689 |
self.SetStyling(current_pos - start_pos, 31) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
690 |
self.ShowHighlights(start_pos, end_pos) |
27 | 691 |
event.Skip() |
692 |
||
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
693 |
def OnMarginClick(self, event): |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
694 |
if event.GetMargin() == 2: |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
695 |
line = self.Editor.LineFromPosition(event.GetPosition()) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
696 |
if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
697 |
self.Editor.ToggleFold(line) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
698 |
event.Skip() |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
699 |
|
27 | 700 |
def Cut(self): |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
701 |
self.ResetBuffer() |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
702 |
self.DisableEvents = True |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
703 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
704 |
self.DisableEvents = False |
136 | 705 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
706 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
707 |
|
27 | 708 |
def Copy(self): |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
709 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
27 | 710 |
|
711 |
def Paste(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
712 |
self.ResetBuffer() |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
713 |
self.DisableEvents = True |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
714 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
715 |
self.DisableEvents = False |
136 | 716 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
717 |
self.RefreshBuffer() |
27 | 718 |
|
719 |
def RefreshModel(self): |
|
136 | 720 |
self.RefreshJumpList() |
721 |
self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
|
27 | 722 |
|
723 |
def OnKeyDown(self, event): |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
724 |
if self.Controler is not None: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
725 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
726 |
if self.Editor.CallTipActive(): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
727 |
self.Editor.CallTipCancel() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
728 |
key = event.GetKeyCode() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
729 |
key_handled = False |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
730 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
731 |
line = self.Editor.GetCurrentLine() |
27 | 732 |
if line == 0: |
733 |
start_pos = 0 |
|
734 |
else: |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
735 |
start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
27 | 736 |
end_pos = self.GetCurrentPos() |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
737 |
lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ") |
27 | 738 |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
739 |
# Code completion |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
740 |
if key == wx.WXK_SPACE and event.ControlDown(): |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
741 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
742 |
words = lineText.split(" ") |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
743 |
words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
744 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
745 |
kw = [] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
746 |
|
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
747 |
if self.TextSyntax == "IL": |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
748 |
if len(words) == 1: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
749 |
kw = self.Keywords |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
750 |
elif len(words) == 2: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
751 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
752 |
kw = self.Functions |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
753 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
754 |
kw = self.Jumps |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
755 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
756 |
kw = self.Variables.keys() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
757 |
else: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
758 |
kw = self.Keywords + self.Variables.keys() + self.Functions |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
759 |
if len(kw) > 0: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
760 |
if len(words[-1]) > 0: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
761 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
762 |
kw.sort() |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
763 |
self.Editor.AutoCompSetIgnoreCase(True) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
764 |
self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
765 |
key_handled = True |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
766 |
elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
767 |
if self.TextSyntax in ["ST", "ALL"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
768 |
indent = self.Editor.GetLineIndentation(line) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
769 |
if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
619
fc03645162b5
Fixing bug in autoindent when number of spaces at the beginning of line is odd
laurent
parents:
617
diff
changeset
|
770 |
indent = (indent / 2 + 1) * 2 |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
771 |
self.Editor.AddText("\n" + " " * indent) |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
566
diff
changeset
|
772 |
key_handled = True |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
773 |
elif key == wx.WXK_BACK: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
774 |
if self.TextSyntax in ["ST", "ALL"]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
775 |
indent = self.Editor.GetLineIndentation(line) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
776 |
if lineText.strip() == "" and indent > 0: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
777 |
self.Editor.DelLineLeft() |
619
fc03645162b5
Fixing bug in autoindent when number of spaces at the beginning of line is odd
laurent
parents:
617
diff
changeset
|
778 |
self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2)) |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
779 |
key_handled = True |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
780 |
if not key_handled: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
781 |
event.Skip() |
27 | 782 |
|
783 |
def OnKillFocus(self, event): |
|
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
784 |
self.Editor.AutoCompCancel() |
27 | 785 |
event.Skip() |
786 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
787 |
#------------------------------------------------------------------------------- |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
788 |
# Highlights showing functions |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
789 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
790 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
791 |
def OnRefreshHighlightsTimer(self, event): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
792 |
self.RefreshView() |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
793 |
event.Skip() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
794 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
795 |
def ClearHighlights(self, highlight_type=None): |
617 | 796 |
EditorPanel.ClearHighlights(self, highlight_type) |
797 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
798 |
if highlight_type is None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
799 |
self.Highlights = [] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
800 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
801 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
802 |
if highlight_type is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
803 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
804 |
self.RefreshView() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
805 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
806 |
def AddHighlight(self, infos, start, end, highlight_type): |
617 | 807 |
EditorPanel.AddHighlight(self, infos, start, end, highlight_type) |
808 |
||
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
809 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
810 |
if infos[0] == "body" and highlight_type is not None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
811 |
self.Highlights.append((infos[1], start, end, highlight_type)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
812 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
813 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
814 |
def ShowHighlights(self, start_pos, end_pos): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
815 |
for indent, start, end, highlight_type in self.Highlights: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
816 |
if start[0] == 0: |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
817 |
highlight_start_pos = start[1] - indent |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
818 |
else: |
589
e3a1d9a59c97
Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents:
586
diff
changeset
|
819 |
highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
820 |
if end[0] == 0: |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
821 |
highlight_end_pos = end[1] - indent + 1 |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
822 |
else: |
589
e3a1d9a59c97
Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents:
586
diff
changeset
|
823 |
highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
824 |
if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
825 |
self.StartStyling(highlight_start_pos, 0xff) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
549
diff
changeset
|
826 |
self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
589
e3a1d9a59c97
Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents:
586
diff
changeset
|
827 |
self.StartStyling(highlight_start_pos, 0x00) |
e3a1d9a59c97
Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents:
586
diff
changeset
|
828 |
self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) |
e3a1d9a59c97
Fixing bug that calls text styling in a loop while some highlighting is defined
laurent
parents:
586
diff
changeset
|
829 |