87 else: |
87 else: |
88 return i + 1 |
88 return i + 1 |
89 else: |
89 else: |
90 return None |
90 return None |
91 |
91 |
|
92 if wx.VERSION >= (2, 8, 0): |
|
93 import wx.aui |
|
94 |
|
95 class TextMDIViewer(wx.aui.AuiMDIChildFrame): |
|
96 def __init__(self, parent, tagname, window, controler): |
|
97 wx.aui.AuiMDIChildFrame.__init__(self, parent, -1, title = "") |
|
98 |
|
99 sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
100 |
|
101 self.Viewer = TextViewer(self, tagname, window, controler) |
|
102 |
|
103 sizer.AddWindow(self.Viewer, 1, border=0, flag=wx.GROW) |
|
104 |
|
105 self.SetSizer(sizer) |
|
106 |
|
107 def GetViewer(self): |
|
108 return self.Viewer |
|
109 |
92 class TextViewer(wx.stc.StyledTextCtrl): |
110 class TextViewer(wx.stc.StyledTextCtrl): |
93 |
111 |
94 if wx.VERSION < (2, 6, 0): |
112 if wx.VERSION < (2, 6, 0): |
95 def Bind(self, event, function, id = None): |
113 def Bind(self, event, function, id = None): |
96 if id is not None: |
114 if id is not None: |
97 event(self, id, function) |
115 event(self, id, function) |
98 else: |
116 else: |
99 event(self, function) |
117 event(self, function) |
100 |
118 |
101 def __init__(self, parent, window, controler): |
119 def __init__(self, parent, tagname, window, controler): |
102 wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0) |
120 wx.stc.StyledTextCtrl.__init__(self, parent, ID_TEXTVIEWER, size=wx.Size(0, 0), style=0) |
103 |
121 |
104 self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
122 self.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
105 self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
123 self.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
106 |
124 |
144 self.Jumps = [] |
162 self.Jumps = [] |
145 self.TextChanged = False |
163 self.TextChanged = False |
146 self.DisableEvents = True |
164 self.DisableEvents = True |
147 self.TextSyntax = "ST" |
165 self.TextSyntax = "ST" |
148 self.CurrentAction = None |
166 self.CurrentAction = None |
|
167 self.TagName = tagname |
149 |
168 |
150 self.ParentWindow = window |
169 self.ParentWindow = window |
151 self.Controler = controler |
170 self.Controler = controler |
152 |
171 |
153 self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
172 self.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE) |
156 if controler: |
175 if controler: |
157 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
176 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
158 self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWER) |
177 self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWER) |
159 self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
178 self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
160 self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER) |
179 self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWER) |
|
180 |
|
181 def SetTagName(self, tagname): |
|
182 self.TagName = tagname |
|
183 |
|
184 def GetTagName(self): |
|
185 return self.TagName |
|
186 |
|
187 def IsViewing(self, tagname): |
|
188 return self.TagName == tagname |
|
189 |
|
190 def SetMode(self, mode): |
|
191 pass |
161 |
192 |
162 def OnModification(self, event): |
193 def OnModification(self, event): |
163 if not self.DisableEvents: |
194 if not self.DisableEvents: |
164 mod_type = event.GetModificationType() |
195 mod_type = event.GetModificationType() |
165 if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO): |
196 if not (mod_type&wx.stc.STC_PERFORMED_UNDO or mod_type&wx.stc.STC_PERFORMED_REDO): |
185 except: |
216 except: |
186 values = event.GetDragText() |
217 values = event.GetDragText() |
187 if isinstance(values, tuple): |
218 if isinstance(values, tuple): |
188 if values[1] in ["functionBlock", "program", "location"]: |
219 if values[1] in ["functionBlock", "program", "location"]: |
189 event.SetDragText("") |
220 event.SetDragText("") |
190 else: |
221 elif values[1] != "location": |
191 event.SetDragText(values[0]) |
222 if values[3] == self.TagName: |
|
223 event.SetDragText(values[0]) |
|
224 else: |
|
225 event.SetDragText("") |
|
226 message = wx.MessageDialog(self.ParentWindow, "Variable don't belong to this POU!", "Error", wx.OK|wx.ICON_ERROR) |
|
227 message.ShowModal() |
|
228 message.Destroy() |
192 event.Skip() |
229 event.Skip() |
193 |
230 |
194 def SetTextSyntax(self, syntax): |
231 def SetTextSyntax(self, syntax): |
195 self.TextSyntax = syntax |
232 self.TextSyntax = syntax |
196 |
233 |
197 def SetKeywords(self, keywords): |
234 def SetKeywords(self, keywords): |
198 self.Keywords = [keyword.upper() for keyword in keywords] |
235 self.Keywords = [keyword.upper() for keyword in keywords] |
199 self.Colourise(0, -1) |
|
200 |
|
201 def SetVariables(self, variables): |
|
202 self.Variables = [variable.upper() for variable in variables] |
|
203 self.Colourise(0, -1) |
|
204 |
|
205 def SetFunctions(self, blocktypes): |
|
206 self.Functions = [] |
|
207 for category in blocktypes: |
|
208 for blocktype in category["list"]: |
|
209 if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables: |
|
210 self.Functions.append(blocktype["name"].upper()) |
|
211 self.Colourise(0, -1) |
236 self.Colourise(0, -1) |
212 |
237 |
213 def RefreshJumpList(self): |
238 def RefreshJumpList(self): |
214 self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
239 self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
215 self.Colourise(0, -1) |
240 self.Colourise(0, -1) |
235 def RefreshView(self): |
260 def RefreshView(self): |
236 self.ResetBuffer() |
261 self.ResetBuffer() |
237 self.DisableEvents = True |
262 self.DisableEvents = True |
238 old_cursor_pos = self.GetCurrentPos() |
263 old_cursor_pos = self.GetCurrentPos() |
239 old_text = self.GetText() |
264 old_text = self.GetText() |
240 new_text = self.Controler.GetCurrentElementEditingText() |
265 new_text = self.Controler.GetEditedElementText(self.TagName) |
241 self.SetText(new_text) |
266 self.SetText(new_text) |
242 new_cursor_pos = GetCursorPos(old_text, new_text) |
267 new_cursor_pos = GetCursorPos(old_text, new_text) |
243 if new_cursor_pos != None: |
268 if new_cursor_pos != None: |
244 self.GotoPos(new_cursor_pos) |
269 self.GotoPos(new_cursor_pos) |
245 else: |
270 else: |
246 self.GotoPos(old_cursor_pos) |
271 self.GotoPos(old_cursor_pos) |
247 self.ScrollToColumn(0) |
272 self.ScrollToColumn(0) |
248 self.RefreshJumpList() |
273 self.RefreshJumpList() |
249 self.EmptyUndoBuffer() |
274 self.EmptyUndoBuffer() |
250 self.DisableEvents = False |
275 self.DisableEvents = False |
251 |
276 |
252 def VerifyVariableTypeCompatibility(self): |
277 words = self.TagName.split("::") |
253 pass |
278 self.Variables = [variable["Name"].upper() for variable in self.Controler.GetEditedElementInterfaceVars(self.TagName)] |
|
279 if self.Controler.GetEditedElementType(self.TagName)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
|
280 self.Variables.append(words[-1].upper()) |
|
281 |
|
282 self.Functions = [] |
|
283 for category in self.Controler.GetBlockTypes(self.TagName): |
|
284 for blocktype in category["list"]: |
|
285 if blocktype["type"] == "function" and blocktype["name"] not in self.Keywords and blocktype["name"] not in self.Variables: |
|
286 self.Functions.append(blocktype["name"].upper()) |
|
287 |
|
288 self.Colourise(0, -1) |
254 |
289 |
255 def OnStyleNeeded(self, event): |
290 def OnStyleNeeded(self, event): |
256 self.TextChanged = True |
291 self.TextChanged = True |
257 line = self.LineFromPosition(self.GetEndStyled()) |
292 line = self.LineFromPosition(self.GetEndStyled()) |
258 if line == 0: |
293 if line == 0: |
378 self.RefreshBuffer() |
413 self.RefreshBuffer() |
379 |
414 |
380 def RefreshModel(self): |
415 def RefreshModel(self): |
381 if self.TextChanged: |
416 if self.TextChanged: |
382 self.RefreshJumpList() |
417 self.RefreshJumpList() |
383 self.Controler.SetCurrentElementEditingText(self.GetText()) |
418 self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
384 |
419 |
385 def OnKeyDown(self, event): |
420 def OnKeyDown(self, event): |
386 if self.CallTipActive(): |
421 if self.CallTipActive(): |
387 self.CallTipCancel() |
422 self.CallTipCancel() |
388 key = event.KeyCode() |
423 key = event.GetKeyCode() |
389 |
424 |
390 # Code completion |
425 # Code completion |
391 if key == wx.WXK_SPACE and event.ControlDown(): |
426 if key == wx.WXK_SPACE and event.ControlDown(): |
392 |
427 |
393 line = self.GetCurrentLine() |
428 line = self.GetCurrentLine() |