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