author | lbessard |
Fri, 19 Dec 2008 15:07:54 +0100 | |
changeset 295 | c6ef6d92ce16 |
parent 249 | d8425712acef |
child 297 | e837b67cb184 |
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 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
43 |
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_VARIABLE, |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
44 |
STC_PLC_FUNCTION, STC_PLC_JUMP, STC_PLC_ERROR] = range(7) |
27 | 45 |
[SPACE, WORD, NUMBER, COMMENT] = range(4) |
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) |
|
70 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
71 |
def GetCursorPos(old, new): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
72 |
old_length = len(old) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
73 |
new_length = len(new) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
74 |
common_length = min(old_length, new_length) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
75 |
i = 0 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
76 |
for i in xrange(common_length): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
77 |
if old[i] != new[i]: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
78 |
break |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
79 |
if old_length < new_length: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
80 |
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
|
81 |
return i + new_length - old_length |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
82 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
83 |
return i + new_length - old_length + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
return i |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
87 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
88 |
return i + 1 |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
89 |
else: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
90 |
return None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
91 |
|
121 | 92 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
93 |
class TextViewer(wx.stc.StyledTextCtrl): |
27 | 94 |
|
113 | 95 |
if wx.VERSION < (2, 6, 0): |
96 |
def Bind(self, event, function, id = None): |
|
97 |
if id is not None: |
|
98 |
event(self, id, function) |
|
99 |
else: |
|
100 |
event(self, function) |
|
101 |
||
249 | 102 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
80 | 103 |
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
|
104 |
|
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
105 |
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
|
106 |
self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
27 | 107 |
|
108 |
self.SetViewWhiteSpace(False) |
|
109 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
110 |
self.SetLexer(wx.stc.STC_LEX_CONTAINER) |
27 | 111 |
|
112 |
# Global default styles for all languages |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
113 |
self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
27 | 114 |
self.StyleClearAll() # Reset all to be like the default |
115 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
116 |
self.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
27 | 117 |
self.SetSelBackground(1, "#E0E0E0") |
118 |
||
119 |
# Highlighting styles |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
self.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,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_JUMP, "fore:#007F00,size:%(size)d" % faces) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
126 |
self.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
27 | 127 |
|
128 |
# Indicators styles |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
129 |
self.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
130 |
if window and controler: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
131 |
self.IndicatorSetForeground(0, wx.RED) |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
132 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
133 |
self.IndicatorSetForeground(0, wx.WHITE) |
27 | 134 |
|
135 |
# Line numbers in the margin |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
136 |
self.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
27 | 137 |
self.SetMarginWidth(1, 50) |
138 |
||
139 |
# Indentation size |
|
140 |
self.SetTabWidth(2) |
|
141 |
self.SetUseTabs(0) |
|
142 |
||
143 |
self.Keywords = [] |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
144 |
self.Variables = {} |
27 | 145 |
self.Functions = [] |
146 |
self.Jumps = [] |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
147 |
self.EnumeratedValues = [] |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
148 |
self.DisableEvents = True |
27 | 149 |
self.TextSyntax = "ST" |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
150 |
self.CurrentAction = None |
121 | 151 |
self.TagName = tagname |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
152 |
self.Errors = [] |
249 | 153 |
self.Debug = debug |
154 |
self.InstancePath = instancepath |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
155 |
self.StructElementsStack = [] |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
156 |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
157 |
self.ParentWindow = window |
27 | 158 |
self.Controler = controler |
159 |
||
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
160 |
self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
161 |
|
79 | 162 |
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
|
163 |
if controler: |
73
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
164 |
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
165 |
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
|
166 |
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
f2529e34e4b7
Prevent problems showing ST code after failed build
etisserant
parents:
68
diff
changeset
|
167 |
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
|
168 |
|
121 | 169 |
def SetTagName(self, tagname): |
170 |
self.TagName = tagname |
|
171 |
||
172 |
def GetTagName(self): |
|
173 |
return self.TagName |
|
174 |
||
249 | 175 |
def GetInstancePath(self): |
176 |
return self.InstancePath |
|
177 |
||
121 | 178 |
def IsViewing(self, tagname): |
249 | 179 |
if self.Debug: |
180 |
return self.InstancePath == tagname |
|
181 |
else: |
|
182 |
return self.TagName == tagname |
|
121 | 183 |
|
184 |
def SetMode(self, mode): |
|
185 |
pass |
|
186 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
187 |
def OnModification(self, event): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
188 |
if not self.DisableEvents: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
189 |
mod_type = event.GetModificationType() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
190 |
if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
191 |
if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
192 |
if self.CurrentAction == None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
193 |
self.StartBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
194 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
195 |
self.Controler.EndBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
196 |
self.StartBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
197 |
self.CurrentAction = ("Add", event.GetPosition()) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
198 |
elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
199 |
if self.CurrentAction == None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
200 |
self.StartBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
201 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
202 |
self.Controler.EndBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
203 |
self.StartBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
204 |
self.CurrentAction = ("Delete", event.GetPosition()) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
205 |
event.Skip() |
27 | 206 |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
207 |
def OnDoDrop(self, event): |
50 | 208 |
try: |
209 |
values = eval(event.GetDragText()) |
|
210 |
except: |
|
211 |
values = event.GetDragText() |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
212 |
if isinstance(values, tuple): |
249 | 213 |
if values[1] in ["functionBlock", "program", "location", "debug"]: |
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
214 |
event.SetDragText("") |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
215 |
elif values[1] == "function": |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
216 |
event.SetDragText(values[0]) |
121 | 217 |
elif values[1] != "location": |
218 |
if values[3] == self.TagName: |
|
136 | 219 |
self.ResetBuffer() |
121 | 220 |
event.SetDragText(values[0]) |
136 | 221 |
wx.CallAfter(self.RefreshModel) |
121 | 222 |
else: |
223 |
event.SetDragText("") |
|
224 |
message = wx.MessageDialog(self.ParentWindow, "Variable don't belong to this POU!", "Error", wx.OK|wx.ICON_ERROR) |
|
225 |
message.ShowModal() |
|
226 |
message.Destroy() |
|
47
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
227 |
event.Skip() |
2b2f8d88e6d3
Interface changed to show pou interface at the bottom of the window
lbessard
parents:
27
diff
changeset
|
228 |
|
27 | 229 |
def SetTextSyntax(self, syntax): |
230 |
self.TextSyntax = syntax |
|
231 |
||
232 |
def SetKeywords(self, keywords): |
|
233 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
234 |
self.Colourise(0, -1) |
|
235 |
||
236 |
def RefreshJumpList(self): |
|
237 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
|
238 |
self.Colourise(0, -1) |
|
239 |
||
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
240 |
# Buffer the last model state |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
241 |
def RefreshBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
self.ParentWindow.RefreshTitle() |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
245 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
246 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
247 |
def StartBuffering(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
self.ParentWindow.RefreshTitle() |
58b9b84e385f
Adding support in xmlclass for timezone in datetime and for not paying attention to xml comments
lbessard
parents:
113
diff
changeset
|
251 |
self.ParentWindow.RefreshEditMenu() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
252 |
|
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
253 |
def ResetBuffer(self): |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
254 |
if self.CurrentAction != None: |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
255 |
self.Controler.EndBuffering() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
256 |
self.CurrentAction = None |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
257 |
|
27 | 258 |
def RefreshView(self): |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
259 |
self.ResetBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
260 |
self.DisableEvents = True |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
261 |
old_cursor_pos = self.GetCurrentPos() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
262 |
old_text = self.GetText() |
249 | 263 |
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
|
264 |
self.SetText(new_text) |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
265 |
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
|
266 |
if new_cursor_pos != None: |
80 | 267 |
self.GotoPos(new_cursor_pos) |
268 |
else: |
|
269 |
self.GotoPos(old_cursor_pos) |
|
270 |
self.ScrollToColumn(0) |
|
27 | 271 |
self.RefreshJumpList() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
272 |
self.EmptyUndoBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
273 |
self.DisableEvents = False |
121 | 274 |
|
275 |
words = self.TagName.split("::") |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
276 |
|
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
277 |
self.Variables = dict([(variable["Name"], variable["Tree"]) for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)]) |
249 | 278 |
if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
279 |
self.Variables[words[-1]] = {} |
121 | 280 |
|
281 |
self.Functions = [] |
|
249 | 282 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
121 | 283 |
for blocktype in category["list"]: |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
284 |
if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables.keys(): |
121 | 285 |
self.Functions.append(blocktype["name"].upper()) |
286 |
||
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
287 |
self.EnumeratedValues = [] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
288 |
for value in self.Controler.GetEnumeratedDataValues(): |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
289 |
self.EnumeratedValues.append(value.upper()) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
290 |
|
121 | 291 |
self.Colourise(0, -1) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
292 |
|
145 | 293 |
def RefreshScaling(self, refresh=True): |
294 |
pass |
|
295 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
296 |
def IsValidVariable(self, name_list, var_tree): |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
297 |
if len(name_list) == 0: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
298 |
return True |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
299 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
300 |
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
|
301 |
if sub_tree is not None: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
302 |
return self.IsValidVariable(name_list[1:], sub_tree) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
303 |
return False |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
304 |
|
27 | 305 |
def OnStyleNeeded(self, event): |
306 |
self.TextChanged = True |
|
307 |
line = self.LineFromPosition(self.GetEndStyled()) |
|
308 |
if line == 0: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
309 |
start_pos = last_styled_pos = 0 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
310 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
311 |
start_pos = last_styled_pos = self.GetLineEndPosition(line - 1) + 1 |
27 | 312 |
end_pos = event.GetPosition() |
313 |
self.StartStyling(start_pos, 0xff) |
|
314 |
||
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
315 |
struct_elements = [] |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
316 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
317 |
current_pos = last_styled_pos |
27 | 318 |
state = SPACE |
319 |
line = "" |
|
320 |
word = "" |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
321 |
while current_pos < end_pos: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
322 |
char = chr(self.GetCharAt(current_pos)).upper() |
27 | 323 |
line += char |
324 |
if char == NEWLINE: |
|
325 |
if state == COMMENT: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
326 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) |
27 | 327 |
elif state == NUMBER: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
328 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 329 |
elif state == WORD: |
330 |
if word in self.Keywords: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
331 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
332 |
elif self.IsValidVariable(struct_elements + [word], self.Variables): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
333 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
27 | 334 |
elif word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
335 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
27 | 336 |
elif word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
337 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
338 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
339 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 340 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
341 |
self.SetStyling(current_pos - last_styled_pos, 31) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
342 |
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
|
343 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
344 |
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
|
345 |
self.StartStyling(current_pos, 0xff) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
346 |
struct_elements = [] |
27 | 347 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
348 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
349 |
last_styled_pos = current_pos |
27 | 350 |
state = SPACE |
351 |
line = "" |
|
352 |
elif line.endswith("(*") and state != COMMENT: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
353 |
self.SetStyling(current_pos - last_styled_pos - 1, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
354 |
last_styled_pos = current_pos |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
355 |
if state == WORD: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
356 |
struct_elements = [] |
27 | 357 |
state = COMMENT |
358 |
elif state == COMMENT: |
|
359 |
if line.endswith("*)"): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
360 |
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
|
361 |
last_styled_pos = current_pos + 1 |
27 | 362 |
state = SPACE |
363 |
elif char in LETTERS: |
|
364 |
if state == NUMBER: |
|
365 |
word = "#" |
|
366 |
state = WORD |
|
367 |
elif state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
368 |
self.SetStyling(current_pos - last_styled_pos, 31) |
27 | 369 |
word = char |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
370 |
last_styled_pos = current_pos |
27 | 371 |
state = WORD |
372 |
else: |
|
373 |
word += char |
|
374 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
375 |
if state == SPACE: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
376 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
377 |
last_styled_pos = current_pos |
27 | 378 |
state = NUMBER |
379 |
if state == WORD and char != '.': |
|
380 |
word += char |
|
381 |
else: |
|
382 |
if state == WORD: |
|
383 |
if word in self.Keywords: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
384 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
385 |
elif self.IsValidVariable(struct_elements + [word], self.Variables): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
386 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
27 | 387 |
elif word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
388 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
27 | 389 |
elif word in self.Jumps: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
390 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
391 |
elif word in self.EnumeratedValues: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
392 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
27 | 393 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
394 |
self.SetStyling(current_pos - last_styled_pos, 31) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
395 |
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
|
396 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
397 |
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
|
398 |
self.StartStyling(current_pos, 0xff) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
399 |
if char == '.': |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
400 |
if word != "]": |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
401 |
struct_elements.append(word) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
402 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
403 |
if char == '[': |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
404 |
self.StructElementsStack.append(struct_elements + [word]) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
405 |
struct_elements = [] |
27 | 406 |
word = "" |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
407 |
last_styled_pos = current_pos |
27 | 408 |
state = SPACE |
409 |
elif state == NUMBER: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
410 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
411 |
last_styled_pos = current_pos |
27 | 412 |
state = SPACE |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
413 |
if char == ']': |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
414 |
struct_elements = self.StructElementsStack.pop(-1) |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
415 |
word = char |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
416 |
state = WORD |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
417 |
current_pos += 1 |
27 | 418 |
if state == COMMENT: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
419 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
27 | 420 |
elif state == NUMBER: |
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_NUMBER) |
27 | 422 |
elif state == WORD: |
423 |
if word in self.Keywords: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
424 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
425 |
elif self.IsValidVariable(struct_elements + [word], self.Variables): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
426 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
27 | 427 |
elif word in self.Functions: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
428 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
27 | 429 |
elif word in self.Jumps: |
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_JUMP) |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
122
diff
changeset
|
431 |
elif word in self.EnumeratedValues: |
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_NUMBER) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
433 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
434 |
self.SetStyling(current_pos - last_styled_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
435 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
436 |
self.SetStyling(current_pos - start_pos, 31) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
437 |
self.ShowErrors(start_pos, end_pos) |
27 | 438 |
event.Skip() |
439 |
||
440 |
def Cut(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
441 |
self.ResetBuffer() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
442 |
self.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
136 | 443 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
444 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
445 |
|
27 | 446 |
def Copy(self): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
447 |
self.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
27 | 448 |
|
449 |
def Paste(self): |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
450 |
self.ResetBuffer() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
451 |
self.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
136 | 452 |
self.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
53
diff
changeset
|
453 |
self.RefreshBuffer() |
27 | 454 |
|
455 |
def RefreshModel(self): |
|
136 | 456 |
self.RefreshJumpList() |
457 |
self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
|
27 | 458 |
|
459 |
def OnKeyDown(self, event): |
|
460 |
if self.CallTipActive(): |
|
461 |
self.CallTipCancel() |
|
121 | 462 |
key = event.GetKeyCode() |
27 | 463 |
|
464 |
# Code completion |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
465 |
if key == wx.WXK_SPACE and event.ControlDown(): |
27 | 466 |
|
467 |
line = self.GetCurrentLine() |
|
468 |
if line == 0: |
|
469 |
start_pos = 0 |
|
470 |
else: |
|
471 |
start_pos = self.GetLineEndPosition(line - 1) + 1 |
|
472 |
end_pos = self.GetCurrentPos() |
|
473 |
||
474 |
lineText = self.GetTextRange(start_pos, end_pos).replace("\t", " ") |
|
475 |
words = lineText.split(" ") |
|
476 |
words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] |
|
477 |
||
478 |
kw = [] |
|
479 |
||
480 |
if self.TextSyntax == "IL": |
|
481 |
if len(words) == 1: |
|
482 |
kw = self.Keywords |
|
483 |
elif len(words) == 2: |
|
484 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
485 |
kw = self.Functions |
|
486 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
487 |
kw = self.Jumps |
|
488 |
else: |
|
295
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
489 |
kw = self.Variables.keys() |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
490 |
else: |
c6ef6d92ce16
Adding support for editing and using struct data types
lbessard
parents:
249
diff
changeset
|
491 |
kw = self.Keywords + self.Variables.keys() + self.Functions |
27 | 492 |
if len(kw) > 0: |
493 |
kw.sort() |
|
494 |
self.AutoCompSetIgnoreCase(True) |
|
495 |
self.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
496 |
else: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
497 |
wx.CallAfter(self.RefreshModel) |
27 | 498 |
event.Skip() |
499 |
||
500 |
def OnKillFocus(self, event): |
|
501 |
self.AutoCompCancel() |
|
502 |
event.Skip() |
|
503 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
504 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
505 |
# Errors showing functions |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
506 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
507 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
508 |
def ClearErrors(self): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
509 |
self.Errors = [] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
510 |
self.RefreshView() |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
511 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
512 |
def AddShownError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
513 |
if infos[0] == "body": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
514 |
self.Errors.append((infos[1], start, end)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
515 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
516 |
def ShowErrors(self, start_pos, end_pos): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
517 |
for indent, start, end in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
518 |
if start[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
519 |
error_start_pos = start[1] - indent |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
520 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
521 |
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
|
522 |
if end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
523 |
error_end_pos = end[1] - indent + 1 |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
524 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
525 |
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
|
526 |
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
|
527 |
self.StartStyling(error_start_pos, 0xff) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
145
diff
changeset
|
528 |
self.SetStyling(error_end_pos - error_start_pos, STC_PLC_ERROR) |