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