author | pizza |
Fri, 12 Aug 2011 17:04:55 +0200 | |
changeset 550 | cfa295862d55 |
parent 549 | b0d6819119c3 |
child 566 | 6014ef82a98a |
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 |
||
31 |
#------------------------------------------------------------------------------- |
|
32 |
# Textual programs Viewer class |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
||
35 |
||
36 |
NEWLINE = "\n" |
|
37 |
NUMBERS = [str(i) for i in xrange(10)] |
|
38 |
LETTERS = ['_'] |
|
39 |
for i in xrange(26): |
|
40 |
LETTERS.append(chr(ord('a') + i)) |
|
41 |
LETTERS.append(chr(ord('A') + i)) |
|
42 |
||
543 | 43 |
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, |
546 | 44 |
STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, |
45 |
STC_PLC_ERROR] = range(9) |
|
543 | 46 |
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT] = range(6) |
27 | 47 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
48 |
[ID_TEXTVIEWER, |
27 | 49 |
] = [wx.NewId() for _init_ctrls in range(1)] |
50 |
||
51 |
if wx.Platform == '__WXMSW__': |
|
52 |
faces = { 'times': 'Times New Roman', |
|
53 |
'mono' : 'Courier New', |
|
54 |
'helv' : 'Arial', |
|
55 |
'other': 'Comic Sans MS', |
|
56 |
'size' : 10, |
|
57 |
} |
|
58 |
else: |
|
59 |
faces = { 'times': 'Times', |
|
60 |
'mono' : 'Courier', |
|
61 |
'helv' : 'Helvetica', |
|
62 |
'other': 'new century schoolbook', |
|
63 |
'size' : 12, |
|
64 |
} |
|
65 |
re_texts = {} |
|
66 |
re_texts["letter"] = "[A-Za-z]" |
|
67 |
re_texts["digit"] = "[0-9]" |
|
68 |
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts |
|
69 |
IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
|
70 |
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]"%re_texts) |
|
543 | 71 |
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
27 | 72 |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
73 |
def GetCursorPos(old, new): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
74 |
old_length = len(old) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
75 |
new_length = len(new) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
76 |
common_length = min(old_length, new_length) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
77 |
i = 0 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
78 |
for i in xrange(common_length): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
79 |
if old[i] != new[i]: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
80 |
break |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
81 |
if old_length < new_length: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
82 |
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
|
83 |
return i + new_length - old_length |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
84 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
85 |
return i + new_length - old_length + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
return i |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
89 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
90 |
return i + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
91 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
92 |
return None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
93 |
|
121 | 94 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
95 |
class TextViewer(wx.stc.StyledTextCtrl): |
27 | 96 |
|
113 | 97 |
if wx.VERSION < (2, 6, 0): |
98 |
def Bind(self, event, function, id = None): |
|
99 |
if id is not None: |
|
100 |
event(self, id, function) |
|
101 |
else: |
|
102 |
event(self, function) |
|
103 |
||
249 | 104 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
80 | 105 |
wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
106 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
107 |
self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
108 |
self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
27 | 109 |
|
110 |
self.SetViewWhiteSpace(False) |
|
111 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
112 |
self.SetLexer(wx.stc.STC_LEX_CONTAINER) |
27 | 113 |
|
114 |
# Global default styles for all languages |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
115 |
self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
27 | 116 |
self.StyleClearAll() # Reset all to be like the default |
117 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
118 |
self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
27 | 119 |
self.SetSelBackground(1, "#E0E0E0") |
120 |
||
121 |
# Highlighting styles |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
122 |
self.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
123 |
self.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
546 | 124 |
self.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
125 |
self.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
126 |
self.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
127 |
self.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
546 | 128 |
self.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
129 |
self.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
130 |
self.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
27 | 131 |
|
132 |
# Indicators styles |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
133 |
self.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
134 |
if window and controler: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
135 |
self.IndicatorSetForeground(0, wx.RED) |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
136 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
137 |
self.IndicatorSetForeground(0, wx.WHITE) |
27 | 138 |
|
139 |
# Line numbers in the margin |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
140 |
self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
27 | 141 |
self.SetMarginWidth(1, 50) |
142 |
||
143 |
# Indentation size |
|
144 |
self.SetTabWidth(2) |
|
145 |
self.SetUseTabs(0) |
|
146 |
||
147 |
self.Keywords = [] |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
148 |
self.Variables = {} |
543 | 149 |
self.Functions = {} |
150 |
self.TypeNames = [] |
|
27 | 151 |
self.Jumps = [] |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
152 |
self.EnumeratedValues = [] |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
153 |
self.DisableEvents = True |
27 | 154 |
self.TextSyntax = "ST" |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
155 |
self.CurrentAction = None |
121 | 156 |
self.TagName = tagname |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
157 |
self.Errors = [] |
249 | 158 |
self.Debug = debug |
159 |
self.InstancePath = instancepath |
|
546 | 160 |
self.ContextStack = [] |
161 |
self.CallStack = [] |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
162 |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
163 |
self.ParentWindow = window |
27 | 164 |
self.Controler = controler |
165 |
||
411 | 166 |
self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT| |
167 |
wx.stc.STC_MOD_BEFOREDELETE| |
|
168 |
wx.stc.STC_PERFORMED_USER) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
169 |
|
79 | 170 |
self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWER) |
116
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
171 |
if controler: |
73
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
172 |
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
173 |
self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWER) |
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
174 |
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
175 |
self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
176 |
|
121 | 177 |
def SetTagName(self, tagname): |
178 |
self.TagName = tagname |
|
179 |
||
180 |
def GetTagName(self): |
|
181 |
return self.TagName |
|
182 |
||
249 | 183 |
def GetInstancePath(self): |
184 |
return self.InstancePath |
|
185 |
||
121 | 186 |
def IsViewing(self, tagname): |
249 | 187 |
if self.Debug: |
188 |
return self.InstancePath == tagname |
|
189 |
else: |
|
190 |
return self.TagName == tagname |
|
121 | 191 |
|
407
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
192 |
def IsDebugging(self): |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
193 |
return self.Debug |
0a324a874981
Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents:
391
diff
changeset
|
194 |
|
121 | 195 |
def SetMode(self, mode): |
196 |
pass |
|
197 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
198 |
def OnModification(self, event): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
199 |
if not self.DisableEvents: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
200 |
mod_type = event.GetModificationType() |
411 | 201 |
if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
202 |
if self.CurrentAction == None: |
|
203 |
self.StartBuffering() |
|
204 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
205 |
self.Controler.EndBuffering() |
|
206 |
self.StartBuffering() |
|
207 |
self.CurrentAction = ("Add", event.GetPosition()) |
|
208 |
wx.CallAfter(self.RefreshModel) |
|
209 |
elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
|
210 |
if self.CurrentAction == None: |
|
211 |
self.StartBuffering() |
|
212 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
213 |
self.Controler.EndBuffering() |
|
214 |
self.StartBuffering() |
|
215 |
self.CurrentAction = ("Delete", event.GetPosition()) |
|
216 |
wx.CallAfter(self.RefreshModel) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
217 |
event.Skip() |
27 | 218 |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
219 |
def OnDoDrop(self, event): |
50 | 220 |
try: |
221 |
values = eval(event.GetDragText()) |
|
222 |
except: |
|
223 |
values = event.GetDragText() |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
224 |
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
|
225 |
message = None |
523 | 226 |
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
|
227 |
event.SetDragText("") |
523 | 228 |
elif values[1] in ["functionBlock", "function"]: |
229 |
blockname = values[2] |
|
230 |
if len(values) > 3: |
|
231 |
blockinputs = values[3] |
|
232 |
else: |
|
233 |
blockinputs = None |
|
234 |
if values[1] != "function": |
|
235 |
if blockname == "": |
|
236 |
dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) |
|
237 |
if dialog.ShowModal() == wx.ID_OK: |
|
238 |
blockname = dialog.GetValue() |
|
239 |
else: |
|
240 |
return |
|
241 |
dialog.Destroy() |
|
242 |
if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
243 |
message = _("\"%s\" pou already exists!")%blockname |
|
244 |
elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
245 |
message = _("\"%s\" element for this pou already exists!")%blockname |
|
246 |
else: |
|
247 |
self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
248 |
self.ParentWindow.RefreshVariablePanel(self.TagName) |
|
249 |
self.RefreshVariableTree() |
|
250 |
blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug) |
|
251 |
hint = ',\n '.join( |
|
252 |
[ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
|
253 |
[ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
if var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
448 | 260 |
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
|
261 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
448 | 262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, values[0], values[4]) |
59e33406eea8
Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents:
411
diff
changeset
|
269 |
self.ParentWindow.RefreshVariablePanel(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
|
270 |
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
|
271 |
event.SetDragText(var_name) |
121 | 272 |
else: |
273 |
event.SetDragText("") |
|
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
event.SetDragText("") |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
285 |
event.Skip() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
286 |
|
27 | 287 |
def SetTextSyntax(self, syntax): |
288 |
self.TextSyntax = syntax |
|
289 |
||
290 |
def SetKeywords(self, keywords): |
|
291 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
292 |
self.Colourise(0, -1) |
|
293 |
||
294 |
def RefreshJumpList(self): |
|
543 | 295 |
if self.TextSyntax != "IL": |
296 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
|
297 |
self.Colourise(0, -1) |
|
27 | 298 |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
299 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
300 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
self.ParentWindow.RefreshTitle() |
485
d5ebb8eac934
Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents:
448
diff
changeset
|
304 |
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
|
305 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
306 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
307 |
def StartBuffering(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
self.ParentWindow.RefreshTitle() |
485
d5ebb8eac934
Bug on TextViewer fixed : FileMenu not refreshed when text modified
laurent
parents:
448
diff
changeset
|
311 |
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
|
312 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
313 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
314 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
315 |
if self.CurrentAction != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
316 |
self.Controler.EndBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
317 |
self.CurrentAction = None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
318 |
|
27 | 319 |
def RefreshView(self): |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
320 |
self.ResetBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
321 |
self.DisableEvents = True |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
322 |
old_cursor_pos = self.GetCurrentPos() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
323 |
old_text = self.GetText() |
249 | 324 |
new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
325 |
self.SetText(new_text) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
326 |
new_cursor_pos = GetCursorPos(old_text, new_text) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
327 |
if new_cursor_pos != None: |
80 | 328 |
self.GotoPos(new_cursor_pos) |
329 |
else: |
|
330 |
self.GotoPos(old_cursor_pos) |
|
331 |
self.ScrollToColumn(0) |
|
27 | 332 |
self.RefreshJumpList() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
333 |
self.EmptyUndoBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
334 |
self.DisableEvents = False |
121 | 335 |
|
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
|
336 |
self.RefreshVariableTree() |
121 | 337 |
|
543 | 338 |
self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
339 |
self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] |
|
340 |
||
341 |
self.Functions = {} |
|
249 | 342 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
121 | 343 |
for blocktype in category["list"]: |
546 | 344 |
blockname = blocktype["name"].upper() |
345 |
if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): |
|
346 |
interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
|
549
b0d6819119c3
Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents:
546
diff
changeset
|
347 |
for param in ["EN", "ENO"]: |
b0d6819119c3
Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents:
546
diff
changeset
|
348 |
if not interface.has_key(param): |
b0d6819119c3
Adding support for syntax highlighting for EN and ENO parameters in formal function and function blocs in textual editor
laurent
parents:
546
diff
changeset
|
349 |
interface[param] = {} |
546 | 350 |
if self.Functions.has_key(blockname): |
351 |
self.Functions[blockname]["interface"].update(interface) |
|
352 |
self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
|
353 |
else: |
|
354 |
self.Functions[blockname] = {"interface": interface, |
|
355 |
"extensible": blocktype["extensible"]} |
|
121 | 356 |
self.Colourise(0, -1) |
297
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
357 |
|
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
546 | 362 |
return_type = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
363 |
if return_type is not None: |
|
364 |
var_tree, var_dimension = self.Controler.GenerateVarTree(return_type, self.Debug) |
|
365 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
366 |
else: |
|
367 |
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
|
368 |
|
297
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
369 |
def GenerateVariableTree(self, list): |
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
370 |
tree = {} |
299
15669fe26e56
Adding support for generating real array dimension in variable blocks
lbessard
parents:
297
diff
changeset
|
371 |
for var_name, var_type, (var_tree, var_dimension) in list: |
300 | 372 |
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
|
373 |
return tree |
e837b67cb184
Adding help menu for inserting complex variable in graphical viewer
lbessard
parents:
295
diff
changeset
|
374 |
|
145 | 375 |
def RefreshScaling(self, refresh=True): |
376 |
pass |
|
377 |
||
546 | 378 |
def IsValidVariable(self, name, context): |
379 |
return context is not None and context.get(name, None) is not None |
|
380 |
||
381 |
def IsCallParameter(self, name, call): |
|
382 |
if call is not None: |
|
383 |
return (call["interface"].get(name.upper(), None) is not None or |
|
384 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
|
543 | 385 |
return False |
386 |
||
27 | 387 |
def OnStyleNeeded(self, event): |
388 |
self.TextChanged = True |
|
389 |
line = self.LineFromPosition(self.GetEndStyled()) |
|
390 |
if line == 0: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
391 |
start_pos = last_styled_pos = 0 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
392 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
393 |
start_pos = last_styled_pos = self.GetLineEndPosition(line - 1) + 1 |
27 | 394 |
end_pos = event.GetPosition() |
395 |
self.StartStyling(start_pos, 0xff) |
|
396 |
||
546 | 397 |
current_context = self.Variables |
398 |
current_call = None |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
399 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
400 |
current_pos = last_styled_pos |
27 | 401 |
state = SPACE |
402 |
line = "" |
|
403 |
word = "" |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
404 |
while current_pos < end_pos: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
405 |
char = chr(self.GetCharAt(current_pos)).upper() |
27 | 406 |
line += char |
407 |
if char == NEWLINE: |
|
546 | 408 |
self.ContextStack = [] |
409 |
current_context = self.Variables |
|
27 | 410 |
if state == COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
411 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) |
27 | 412 |
elif state == NUMBER: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
413 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 414 |
elif state == WORD: |
543 | 415 |
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
|
416 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 417 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
418 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 419 |
elif self.IsCallParameter(word, current_call): |
420 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
27 | 421 |
elif word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
422 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
543 | 423 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
424 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
425 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
426 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 427 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
428 |
self.SetStyling(current_pos - last_styled_pos, 31) |
546 | 429 |
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
|
430 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
431 |
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
|
432 |
self.StartStyling(current_pos, 0xff) |
27 | 433 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
434 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
435 |
last_styled_pos = current_pos |
27 | 436 |
state = SPACE |
437 |
line = "" |
|
438 |
elif line.endswith("(*") and state != COMMENT: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
439 |
self.SetStyling(current_pos - last_styled_pos - 1, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
440 |
last_styled_pos = current_pos |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
441 |
if state == WORD: |
546 | 442 |
current_context = self.Variables |
27 | 443 |
state = COMMENT |
444 |
elif state == COMMENT: |
|
445 |
if line.endswith("*)"): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
446 |
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
|
447 |
last_styled_pos = current_pos + 1 |
27 | 448 |
state = SPACE |
543 | 449 |
elif (line.endswith("'") or line.endswith('"')) and state not in [COMMENT, STRING, WSTRING]: |
450 |
self.SetStyling(current_pos - last_styled_pos, 31) |
|
451 |
last_styled_pos = current_pos |
|
452 |
if state == WORD: |
|
546 | 453 |
current_context = self.Variables |
543 | 454 |
if line.endswith("'"): |
455 |
state = STRING |
|
456 |
else: |
|
457 |
state = WSTRING |
|
458 |
elif state == STRING: |
|
459 |
if line.endswith("'") and not line.endswith("$'"): |
|
460 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
461 |
last_styled_pos = current_pos + 1 |
|
462 |
state = SPACE |
|
463 |
elif state == WSTRING: |
|
464 |
if line.endswith('"') and not line.endswith('$"'): |
|
465 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
466 |
last_styled_pos = current_pos + 1 |
|
467 |
state = SPACE |
|
27 | 468 |
elif char in LETTERS: |
469 |
if state == NUMBER: |
|
470 |
word = "#" |
|
471 |
state = WORD |
|
472 |
elif state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
473 |
self.SetStyling(current_pos - last_styled_pos, 31) |
27 | 474 |
word = char |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
475 |
last_styled_pos = current_pos |
27 | 476 |
state = WORD |
477 |
else: |
|
478 |
word += char |
|
479 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
480 |
if state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
481 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
482 |
last_styled_pos = current_pos |
27 | 483 |
state = NUMBER |
484 |
if state == WORD and char != '.': |
|
485 |
word += char |
|
543 | 486 |
elif char == '(' and state == SPACE: |
546 | 487 |
self.CallStack.append(current_call) |
488 |
current_call = None |
|
27 | 489 |
else: |
490 |
if state == WORD: |
|
543 | 491 |
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
|
492 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 493 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
494 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 495 |
elif self.IsCallParameter(word, current_call): |
496 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
27 | 497 |
elif word in self.Functions: |
543 | 498 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
499 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
500 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
501 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
502 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 503 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
504 |
self.SetStyling(current_pos - last_styled_pos, 31) |
546 | 505 |
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
|
506 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
507 |
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
|
508 |
self.StartStyling(current_pos, 0xff) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
509 |
if char == '.': |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
510 |
if word != "]": |
546 | 511 |
if current_context is not None: |
512 |
current_context = current_context.get(word, None) |
|
513 |
else: |
|
514 |
current_context = None |
|
543 | 515 |
elif char == '(': |
546 | 516 |
self.CallStack.append(current_call) |
517 |
current_call = self.Functions.get(word, None) |
|
518 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
519 |
current_call = {"interface": current_context.get(word, {}), |
|
520 |
"extensible": False} |
|
521 |
current_context = self.Variables |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
522 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
523 |
if char == '[': |
546 | 524 |
self.ContextStack.append(current_context.get(word, None)) |
525 |
current_context = self.Variables |
|
543 | 526 |
|
27 | 527 |
word = "" |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
528 |
last_styled_pos = current_pos |
27 | 529 |
state = SPACE |
530 |
elif state == NUMBER: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
531 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
532 |
last_styled_pos = current_pos |
27 | 533 |
state = SPACE |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
534 |
if char == ']': |
546 | 535 |
if len(self.ContextStack) > 0: |
536 |
current_context = self.ContextStack.pop() |
|
537 |
else: |
|
538 |
current_context = self.Variables |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
539 |
word = char |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
540 |
state = WORD |
543 | 541 |
elif char == ')': |
546 | 542 |
current_context = self.Variables |
543 |
if len(self.CallStack) > 0: |
|
544 |
current_call = self.CallStack.pop() |
|
545 |
else: |
|
546 |
current_call = None |
|
547 |
word = char |
|
548 |
state = WORD |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
549 |
current_pos += 1 |
27 | 550 |
if state == COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
551 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
27 | 552 |
elif state == NUMBER: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
553 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 554 |
elif state == WORD: |
543 | 555 |
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
|
556 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
546 | 557 |
elif self.IsValidVariable(word, current_context): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
558 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
546 | 559 |
elif self.IsCallParameter(word, current_call): |
560 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
543 | 561 |
elif self.TextSyntax == "IL" and word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
562 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
27 | 563 |
elif word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
564 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
565 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
566 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
567 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
568 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
569 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
570 |
self.SetStyling(current_pos - start_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
571 |
self.ShowErrors(start_pos, end_pos) |
27 | 572 |
event.Skip() |
573 |
||
574 |
def Cut(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
575 |
self.ResetBuffer() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
576 |
self.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
136 | 577 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
578 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
579 |
|
27 | 580 |
def Copy(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
581 |
self.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
27 | 582 |
|
583 |
def Paste(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
584 |
self.ResetBuffer() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
585 |
self.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
136 | 586 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
587 |
self.RefreshBuffer() |
27 | 588 |
|
589 |
def RefreshModel(self): |
|
136 | 590 |
self.RefreshJumpList() |
591 |
self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
|
27 | 592 |
|
593 |
def OnKeyDown(self, event): |
|
594 |
if self.CallTipActive(): |
|
595 |
self.CallTipCancel() |
|
121 | 596 |
key = event.GetKeyCode() |
27 | 597 |
|
598 |
# Code completion |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
599 |
if key == wx.WXK_SPACE and event.ControlDown(): |
27 | 600 |
|
601 |
line = self.GetCurrentLine() |
|
602 |
if line == 0: |
|
603 |
start_pos = 0 |
|
604 |
else: |
|
605 |
start_pos = self.GetLineEndPosition(line - 1) + 1 |
|
606 |
end_pos = self.GetCurrentPos() |
|
607 |
||
608 |
lineText = self.GetTextRange(start_pos, end_pos).replace("\t", " ") |
|
609 |
words = lineText.split(" ") |
|
610 |
words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] |
|
611 |
||
612 |
kw = [] |
|
613 |
||
614 |
if self.TextSyntax == "IL": |
|
615 |
if len(words) == 1: |
|
616 |
kw = self.Keywords |
|
617 |
elif len(words) == 2: |
|
618 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
619 |
kw = self.Functions |
|
620 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
621 |
kw = self.Jumps |
|
622 |
else: |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
623 |
kw = self.Variables.keys() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
624 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
625 |
kw = self.Keywords + self.Variables.keys() + self.Functions |
27 | 626 |
if len(kw) > 0: |
312 | 627 |
if len(words[-1]) > 0: |
628 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
27 | 629 |
kw.sort() |
630 |
self.AutoCompSetIgnoreCase(True) |
|
631 |
self.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
632 |
else: |
|
633 |
event.Skip() |
|
634 |
||
635 |
def OnKillFocus(self, event): |
|
636 |
self.AutoCompCancel() |
|
637 |
event.Skip() |
|
638 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
639 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
640 |
# Errors showing functions |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
641 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
642 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
643 |
def ClearErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
644 |
self.Errors = [] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
645 |
self.RefreshView() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
646 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
647 |
def AddShownError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
648 |
if infos[0] == "body": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
649 |
self.Errors.append((infos[1], start, end)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
650 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
651 |
def ShowErrors(self, start_pos, end_pos): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
652 |
for indent, start, end in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
653 |
if start[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
654 |
error_start_pos = start[1] - indent |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
655 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
656 |
error_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
657 |
if end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
658 |
error_end_pos = end[1] - indent + 1 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
659 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
660 |
error_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
661 |
if start_pos <= error_start_pos <= end_pos or start_pos <= error_end_pos <= end_pos: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
662 |
self.StartStyling(error_start_pos, 0xff) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
663 |
self.SetStyling(error_end_pos - error_start_pos, STC_PLC_ERROR) |