author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 01 Jun 2017 14:37:14 +0300 | |
changeset 1686 | 85fdcc04da25 |
parent 1637 | 6f4624687b89 |
child 1730 | 64d8f52bc8c8 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1556
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import re |
|
26 |
from types import * |
|
27 |
||
28 |
import wx |
|
29 |
import wx.stc |
|
30 |
||
31 |
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
|
32 |
from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES |
|
33 |
from EditorPanel import EditorPanel |
|
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
34 |
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos, NAVIGATION_KEYS |
814 | 35 |
|
36 |
#------------------------------------------------------------------------------- |
|
37 |
# Textual programs Viewer class |
|
38 |
#------------------------------------------------------------------------------- |
|
39 |
||
40 |
||
41 |
NEWLINE = "\n" |
|
42 |
NUMBERS = [str(i) for i in xrange(10)] |
|
43 |
LETTERS = ['_'] |
|
44 |
for i in xrange(26): |
|
45 |
LETTERS.append(chr(ord('a') + i)) |
|
46 |
LETTERS.append(chr(ord('A') + i)) |
|
47 |
||
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
48 |
[STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
49 |
STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
50 |
STC_PLC_ERROR, STC_PLC_SEARCH_RESULT, |
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
51 |
STC_PLC_EMPTY] = range(11) |
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
52 |
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
814 | 53 |
|
54 |
[ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
|
55 |
] = [wx.NewId() for _init_ctrls in range(2)] |
|
56 |
||
57 |
re_texts = {} |
|
58 |
re_texts["letter"] = "[A-Za-z]" |
|
59 |
re_texts["digit"] = "[0-9]" |
|
60 |
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)"%re_texts |
|
61 |
IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
|
62 |
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]"%re_texts) |
|
63 |
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
|
64 |
||
65 |
HIGHLIGHT_TYPES = { |
|
66 |
ERROR_HIGHLIGHT: STC_PLC_ERROR, |
|
67 |
SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
|
68 |
} |
|
69 |
||
70 |
def LineStartswith(line, symbols): |
|
71 |
return reduce(lambda x, y: x or y, map(lambda x: line.startswith(x), symbols), False) |
|
72 |
||
73 |
class TextViewer(EditorPanel): |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
74 |
|
814 | 75 |
ID = ID_TEXTVIEWER |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
76 |
|
814 | 77 |
if wx.VERSION < (2, 6, 0): |
78 |
def Bind(self, event, function, id = None): |
|
79 |
if id is not None: |
|
80 |
event(self, id, function) |
|
81 |
else: |
|
82 |
event(self, function) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
83 |
|
814 | 84 |
def _init_Editor(self, prnt): |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
85 |
self.Editor = CustomStyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
814 | 86 |
parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
87 |
self.Editor.ParentWindow = self |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
88 |
|
814 | 89 |
self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
90 |
self.Editor.CmdKeyAssign(ord('-'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMOUT) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
91 |
|
814 | 92 |
self.Editor.SetViewWhiteSpace(False) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
93 |
|
814 | 94 |
self.Editor.SetLexer(wx.stc.STC_LEX_CONTAINER) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
95 |
|
814 | 96 |
# Global default styles for all languages |
97 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
|
98 |
self.Editor.StyleClearAll() # Reset all to be like the default |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
99 |
|
814 | 100 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
101 |
self.Editor.SetSelBackground(1, "#E0E0E0") |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
102 |
|
814 | 103 |
# Highlighting styles |
104 |
self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
|
105 |
self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
|
106 |
self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
|
107 |
self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
|
108 |
self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
|
109 |
self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
|
110 |
self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
|
111 |
self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
|
112 |
self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
|
113 |
self.Editor.StyleSetSpec(STC_PLC_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500,size:%(size)d" % faces) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
114 |
|
814 | 115 |
# Indicators styles |
116 |
self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
|
117 |
if self.ParentWindow is not None and self.Controler is not None: |
|
118 |
self.Editor.IndicatorSetForeground(0, wx.RED) |
|
119 |
else: |
|
120 |
self.Editor.IndicatorSetForeground(0, wx.WHITE) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
121 |
|
814 | 122 |
# Line numbers in the margin |
123 |
self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
|
124 |
self.Editor.SetMarginWidth(1, 50) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
125 |
|
814 | 126 |
# Folding |
127 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") |
|
128 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") |
|
129 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") |
|
130 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") |
|
131 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
|
132 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
|
133 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL, wx.stc.STC_MARK_TCORNER, "white", "#808080") |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
134 |
|
814 | 135 |
# Indentation size |
136 |
self.Editor.SetTabWidth(2) |
|
137 |
self.Editor.SetUseTabs(0) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
138 |
|
814 | 139 |
self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT| |
140 |
wx.stc.STC_MOD_BEFOREDELETE| |
|
141 |
wx.stc.STC_PERFORMED_USER) |
|
142 |
||
143 |
self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) |
|
144 |
self.Editor.Bind(wx.stc.EVT_STC_MARGINCLICK, self.OnMarginClick) |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
145 |
self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI) |
814 | 146 |
self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
147 |
if self.Controler is not None: |
|
148 |
self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
|
149 |
self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) |
|
150 |
self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModification, id=ID_TEXTVIEWERTEXTCTRL) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
151 |
|
814 | 152 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
153 |
if tagname != "" and controler is not None: |
|
154 |
self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
155 |
|
814 | 156 |
EditorPanel.__init__(self, parent, tagname, window, controler, debug) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
157 |
|
814 | 158 |
self.Keywords = [] |
159 |
self.Variables = {} |
|
160 |
self.Functions = {} |
|
161 |
self.TypeNames = [] |
|
162 |
self.Jumps = [] |
|
163 |
self.EnumeratedValues = [] |
|
164 |
self.DisableEvents = True |
|
165 |
self.TextSyntax = None |
|
166 |
self.CurrentAction = None |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
167 |
|
814 | 168 |
self.InstancePath = instancepath |
169 |
self.ContextStack = [] |
|
170 |
self.CallStack = [] |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
171 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
172 |
self.ResetSearchResults() |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
173 |
|
814 | 174 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
175 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
176 |
|
814 | 177 |
def __del__(self): |
178 |
self.RefreshHighlightsTimer.Stop() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
179 |
|
814 | 180 |
def GetTitle(self): |
181 |
if self.Debug or self.TagName == "": |
|
182 |
if len(self.InstancePath) > 15: |
|
183 |
return "..." + self.InstancePath[-12:] |
|
184 |
return self.InstancePath |
|
185 |
return EditorPanel.GetTitle(self) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
186 |
|
814 | 187 |
def GetInstancePath(self): |
188 |
return self.InstancePath |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
189 |
|
814 | 190 |
def IsViewing(self, tagname): |
191 |
if self.Debug or self.TagName == "": |
|
192 |
return self.InstancePath == tagname |
|
193 |
else: |
|
194 |
return self.TagName == tagname |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
195 |
|
814 | 196 |
def GetText(self): |
197 |
return self.Editor.GetText() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
198 |
|
814 | 199 |
def SetText(self, text): |
200 |
self.Editor.SetText(text) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
201 |
|
814 | 202 |
def SelectAll(self): |
203 |
self.Editor.SelectAll() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
204 |
|
814 | 205 |
def Colourise(self, start, end): |
206 |
self.Editor.Colourise(start, end) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
207 |
|
814 | 208 |
def StartStyling(self, pos, mask): |
209 |
self.Editor.StartStyling(pos, mask) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
210 |
|
814 | 211 |
def SetStyling(self, length, style): |
212 |
self.Editor.SetStyling(length, style) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
213 |
|
814 | 214 |
def GetCurrentPos(self): |
215 |
return self.Editor.GetCurrentPos() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
216 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
217 |
def ResetSearchResults(self): |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
218 |
self.Highlights = [] |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
219 |
self.SearchParams = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
220 |
self.SearchResults = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
221 |
self.CurrentFindHighlight = None |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
222 |
|
814 | 223 |
def OnModification(self, event): |
224 |
if not self.DisableEvents: |
|
225 |
mod_type = event.GetModificationType() |
|
226 |
if mod_type&wx.stc.STC_MOD_BEFOREINSERT: |
|
227 |
if self.CurrentAction == None: |
|
228 |
self.StartBuffering() |
|
229 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
230 |
self.Controler.EndBuffering() |
|
231 |
self.StartBuffering() |
|
232 |
self.CurrentAction = ("Add", event.GetPosition()) |
|
233 |
wx.CallAfter(self.RefreshModel) |
|
234 |
elif mod_type&wx.stc.STC_MOD_BEFOREDELETE: |
|
235 |
if self.CurrentAction == None: |
|
236 |
self.StartBuffering() |
|
237 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
238 |
self.Controler.EndBuffering() |
|
239 |
self.StartBuffering() |
|
240 |
self.CurrentAction = ("Delete", event.GetPosition()) |
|
241 |
wx.CallAfter(self.RefreshModel) |
|
242 |
event.Skip() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
243 |
|
814 | 244 |
def OnDoDrop(self, event): |
245 |
try: |
|
246 |
values = eval(event.GetDragText()) |
|
247 |
except: |
|
248 |
values = event.GetDragText() |
|
249 |
if isinstance(values, tuple): |
|
250 |
message = None |
|
251 |
if values[1] in ["program", "debug"]: |
|
252 |
event.SetDragText("") |
|
253 |
elif values[1] in ["functionBlock", "function"]: |
|
254 |
blocktype = values[0] |
|
255 |
blockname = values[2] |
|
256 |
if len(values) > 3: |
|
257 |
blockinputs = values[3] |
|
258 |
else: |
|
259 |
blockinputs = None |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
260 |
if values[1] != "function": |
814 | 261 |
if blockname == "": |
1488
00fb79aba7ac
add i18n for couple of strings in TextViewer.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1417
diff
changeset
|
262 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Block name"), _("Please enter a block name"), "", wx.OK|wx.CANCEL|wx.CENTRE) |
814 | 263 |
if dialog.ShowModal() == wx.ID_OK: |
264 |
blockname = dialog.GetValue() |
|
265 |
else: |
|
1504
d3f97b72c02a
fix issue that if functional block is dragged from project panel into
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1488
diff
changeset
|
266 |
event.SetDragText("") |
814 | 267 |
return |
268 |
dialog.Destroy() |
|
269 |
if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
270 |
message = _("\"%s\" pou already exists!")%blockname |
|
271 |
elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
272 |
message = _("\"%s\" element for this pou already exists!")%blockname |
|
273 |
else: |
|
274 |
self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
275 |
self.RefreshVariablePanel() |
|
276 |
self.RefreshVariableTree() |
|
277 |
blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug) |
|
278 |
hint = ',\n '.join( |
|
279 |
[ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
|
280 |
[ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
|
281 |
if values[1] == "function": |
|
282 |
event.SetDragText(blocktype+"(\n "+hint+")") |
|
283 |
else: |
|
284 |
event.SetDragText(blockname+"(\n "+hint+")") |
|
285 |
elif values[1] == "location": |
|
286 |
pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
|
287 |
if len(values) > 2 and pou_type == "program": |
|
288 |
var_name = values[3] |
|
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
289 |
dlg = wx.TextEntryDialog( |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
290 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
291 |
_("Confirm or change variable name"), |
1578
f8e2a04c4445
add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
292 |
_('Variable Drop'), var_name) |
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
293 |
dlg.SetValue(var_name) |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
294 |
var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
295 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
296 |
if var_name is None: |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
297 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
298 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
814 | 299 |
message = _("\"%s\" pou already exists!")%var_name |
300 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
301 |
message = _("\"%s\" element for this pou already exists!")%var_name |
|
302 |
else: |
|
303 |
location = values[0] |
|
304 |
if not location.startswith("%"): |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
305 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
306 |
_("Select a variable class:"), _("Variable class"), |
1578
f8e2a04c4445
add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
307 |
[_("Input"), _("Output"), _("Memory")], |
814 | 308 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
309 |
if dialog.ShowModal() == wx.ID_OK: |
|
310 |
selected = dialog.GetSelection() |
|
311 |
else: |
|
312 |
selected = None |
|
313 |
dialog.Destroy() |
|
314 |
if selected is None: |
|
315 |
event.SetDragText("") |
|
316 |
return |
|
317 |
if selected == 0: |
|
318 |
location = "%I" + location |
|
319 |
elif selected == 1: |
|
320 |
location = "%Q" + location |
|
321 |
else: |
|
322 |
location = "%M" + location |
|
323 |
if values[2] is not None: |
|
324 |
var_type = values[2] |
|
325 |
else: |
|
326 |
var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0] |
|
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1347
diff
changeset
|
327 |
self.Controler.AddEditedElementPouVar(self.TagName, |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
328 |
var_type, var_name, |
1406
82db84fe88ea
Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents:
1347
diff
changeset
|
329 |
location=location, description=values[4]) |
814 | 330 |
self.RefreshVariablePanel() |
331 |
self.RefreshVariableTree() |
|
332 |
event.SetDragText(var_name) |
|
333 |
else: |
|
334 |
event.SetDragText("") |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
335 |
elif values[1] == "NamedConstant": |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
336 |
pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
337 |
if pou_type == "program": |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
338 |
initval = values[0] |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
339 |
var_name = values[3] |
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
340 |
dlg = wx.TextEntryDialog( |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
341 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
342 |
_("Confirm or change variable name"), |
1578
f8e2a04c4445
add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
343 |
_('Variable Drop'), var_name) |
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
344 |
dlg.SetValue(var_name) |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
345 |
var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
346 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
347 |
if var_name is None: |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
348 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
349 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
350 |
message = _("\"%s\" pou already exists!")%var_name |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
351 |
else: |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
352 |
var_type = values[2] |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
353 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
354 |
self.Controler.AddEditedElementPouVar(self.TagName, |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
355 |
var_type, |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
356 |
var_name, |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
357 |
description=values[4], initval=initval) |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
358 |
self.RefreshVariablePanel() |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
359 |
self.RefreshVariableTree() |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
360 |
event.SetDragText(var_name) |
814 | 361 |
elif values[1] == "Global": |
362 |
var_name = values[0] |
|
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
363 |
dlg = wx.TextEntryDialog( |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
364 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
365 |
_("Confirm or change variable name"), |
1578
f8e2a04c4445
add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
366 |
_('Variable Drop'), var_name) |
1417
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
367 |
dlg.SetValue(var_name) |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
368 |
var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
369 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
370 |
if var_name is None: |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
371 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
372 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
814 | 373 |
message = _("\"%s\" pou already exists!")%var_name |
374 |
else: |
|
375 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
376 |
self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
|
377 |
self.RefreshVariablePanel() |
|
378 |
self.RefreshVariableTree() |
|
379 |
event.SetDragText(var_name) |
|
380 |
elif values[1] == "Constant": |
|
381 |
event.SetDragText(values[0]) |
|
382 |
elif values[3] == self.TagName: |
|
383 |
self.ResetBuffer() |
|
384 |
event.SetDragText(values[0]) |
|
385 |
wx.CallAfter(self.RefreshModel) |
|
386 |
else: |
|
387 |
message = _("Variable don't belong to this POU!") |
|
388 |
if message is not None: |
|
389 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
390 |
dialog.ShowModal() |
|
391 |
dialog.Destroy() |
|
392 |
event.SetDragText("") |
|
393 |
event.Skip() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
394 |
|
814 | 395 |
def SetTextSyntax(self, syntax): |
396 |
self.TextSyntax = syntax |
|
397 |
if syntax in ["ST", "ALL"]: |
|
398 |
self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
|
399 |
self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
|
400 |
self.Editor.SetMarginSensitive(2, 1) |
|
401 |
self.Editor.SetMarginWidth(2, 12) |
|
402 |
if syntax == "ST": |
|
403 |
self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
|
404 |
self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
|
405 |
else: |
|
406 |
self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
|
407 |
self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
|
408 |
else: |
|
409 |
self.BlockStartKeywords = [] |
|
410 |
self.BlockEndKeywords = [] |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
411 |
|
814 | 412 |
def SetKeywords(self, keywords): |
413 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
414 |
self.Colourise(0, -1) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
415 |
|
814 | 416 |
def RefreshJumpList(self): |
1637
6f4624687b89
fix IL jumps highlighting in Text Viewer
Surkov Sergey <surkovsv93@gmail.com>
parents:
1613
diff
changeset
|
417 |
if self.TextSyntax == "IL": |
814 | 418 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
419 |
self.Colourise(0, -1) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
420 |
|
814 | 421 |
# Buffer the last model state |
422 |
def RefreshBuffer(self): |
|
423 |
self.Controler.BufferProject() |
|
424 |
if self.ParentWindow: |
|
425 |
self.ParentWindow.RefreshTitle() |
|
426 |
self.ParentWindow.RefreshFileMenu() |
|
427 |
self.ParentWindow.RefreshEditMenu() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
428 |
|
814 | 429 |
def StartBuffering(self): |
430 |
self.Controler.StartBuffering() |
|
431 |
if self.ParentWindow: |
|
432 |
self.ParentWindow.RefreshTitle() |
|
433 |
self.ParentWindow.RefreshFileMenu() |
|
434 |
self.ParentWindow.RefreshEditMenu() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
435 |
|
814 | 436 |
def ResetBuffer(self): |
437 |
if self.CurrentAction != None: |
|
438 |
self.Controler.EndBuffering() |
|
439 |
self.CurrentAction = None |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
440 |
|
814 | 441 |
def GetBufferState(self): |
442 |
if not self.Debug and self.TextSyntax != "ALL": |
|
443 |
return self.Controler.GetBufferState() |
|
444 |
return False, False |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
445 |
|
814 | 446 |
def Undo(self): |
447 |
if not self.Debug and self.TextSyntax != "ALL": |
|
448 |
self.Controler.LoadPrevious() |
|
449 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
450 |
|
814 | 451 |
def Redo(self): |
452 |
if not self.Debug and self.TextSyntax != "ALL": |
|
453 |
self.Controler.LoadNext() |
|
454 |
self.ParentWindow.CloseTabsWithoutModel() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
455 |
|
814 | 456 |
def HasNoModel(self): |
457 |
if not self.Debug and self.TextSyntax != "ALL": |
|
458 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
459 |
return False |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
460 |
|
814 | 461 |
def RefreshView(self, variablepanel=True): |
462 |
EditorPanel.RefreshView(self, variablepanel) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
463 |
|
814 | 464 |
if self.Controler is not None: |
465 |
self.ResetBuffer() |
|
466 |
self.DisableEvents = True |
|
467 |
old_cursor_pos = self.GetCurrentPos() |
|
1060
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
468 |
line = self.Editor.GetFirstVisibleLine() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
469 |
column = self.Editor.GetXOffset() |
814 | 470 |
old_text = self.GetText() |
471 |
new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug) |
|
1060
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
472 |
if old_text != new_text: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
473 |
self.SetText(new_text) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
474 |
new_cursor_pos = GetCursorPos(old_text, new_text) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
475 |
self.Editor.LineScroll(column, line) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
476 |
if new_cursor_pos != None: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
477 |
self.Editor.GotoPos(new_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
478 |
else: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
479 |
self.Editor.GotoPos(old_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
480 |
self.RefreshJumpList() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
481 |
self.Editor.EmptyUndoBuffer() |
814 | 482 |
self.DisableEvents = False |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
483 |
|
814 | 484 |
self.RefreshVariableTree() |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
485 |
|
814 | 486 |
self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
487 |
self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()] |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
488 |
|
814 | 489 |
self.Functions = {} |
490 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
|
491 |
for blocktype in category["list"]: |
|
492 |
blockname = blocktype["name"].upper() |
|
493 |
if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in self.Variables.keys(): |
|
494 |
interface = dict([(name, {}) for name, type, modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
|
495 |
for param in ["EN", "ENO"]: |
|
496 |
if not interface.has_key(param): |
|
497 |
interface[param] = {} |
|
498 |
if self.Functions.has_key(blockname): |
|
499 |
self.Functions[blockname]["interface"].update(interface) |
|
500 |
self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
|
501 |
else: |
|
502 |
self.Functions[blockname] = {"interface": interface, |
|
503 |
"extensible": blocktype["extensible"]} |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
504 |
|
814 | 505 |
self.Colourise(0, -1) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
506 |
|
814 | 507 |
def RefreshVariableTree(self): |
508 |
words = self.TagName.split("::") |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
509 |
self.Variables = self.GenerateVariableTree( |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
510 |
[(variable.Name, variable.Type, variable.Tree) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
511 |
for variable in self.Controler.GetEditedElementInterfaceVars( |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
512 |
self.TagName, True, self.Debug)]) |
814 | 513 |
if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
514 |
return_type, (var_tree, var_dimension) = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, True, self.Debug) |
814 | 515 |
if return_type is not None: |
516 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
517 |
else: |
|
518 |
self.Variables[words[-1].upper()] = {} |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
519 |
|
814 | 520 |
def GenerateVariableTree(self, list): |
521 |
tree = {} |
|
522 |
for var_name, var_type, (var_tree, var_dimension) in list: |
|
523 |
tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
|
524 |
return tree |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
525 |
|
814 | 526 |
def IsValidVariable(self, name, context): |
527 |
return context is not None and context.get(name, None) is not None |
|
528 |
||
529 |
def IsCallParameter(self, name, call): |
|
530 |
if call is not None: |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
531 |
return (call["interface"].get(name.upper(), None) is not None or |
814 | 532 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
533 |
return False |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
534 |
|
814 | 535 |
def RefreshLineFolding(self, line_number): |
536 |
if self.TextSyntax in ["ST", "ALL"]: |
|
537 |
level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
|
538 |
line = self.Editor.GetLine(line_number).strip() |
|
539 |
if line == "": |
|
540 |
if line_number > 0: |
|
541 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
542 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
543 |
else: |
|
544 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
545 |
if level != wx.stc.STC_FOLDLEVELBASE: |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
546 |
level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
814 | 547 |
elif LineStartswith(line, self.BlockStartKeywords): |
548 |
level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
|
549 |
elif LineStartswith(line, self.BlockEndKeywords): |
|
550 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
551 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
552 |
else: |
|
553 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
554 |
self.Editor.SetFoldLevel(line_number, level) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
555 |
|
814 | 556 |
def OnStyleNeeded(self, event): |
557 |
self.TextChanged = True |
|
558 |
line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
|
559 |
if line_number == 0: |
|
560 |
start_pos = last_styled_pos = 0 |
|
561 |
else: |
|
562 |
start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
|
563 |
self.RefreshLineFolding(line_number) |
|
564 |
end_pos = event.GetPosition() |
|
565 |
self.StartStyling(start_pos, 0xff) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
566 |
|
814 | 567 |
current_context = self.Variables |
568 |
current_call = None |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
569 |
|
814 | 570 |
current_pos = last_styled_pos |
571 |
state = SPACE |
|
572 |
line = "" |
|
573 |
word = "" |
|
574 |
while current_pos < end_pos: |
|
575 |
char = chr(self.Editor.GetCharAt(current_pos)).upper() |
|
576 |
line += char |
|
577 |
if char == NEWLINE: |
|
578 |
self.ContextStack = [] |
|
579 |
current_context = self.Variables |
|
580 |
if state == COMMENT: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
581 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_COMMENT) |
814 | 582 |
elif state == NUMBER: |
583 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
584 |
elif state == WORD: |
|
585 |
if word in self.Keywords or word in self.TypeNames: |
|
586 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
587 |
elif self.IsValidVariable(word, current_context): |
|
588 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
589 |
elif self.IsCallParameter(word, current_call): |
|
590 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
591 |
elif word in self.Functions: |
|
592 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
593 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
594 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
595 |
elif word in self.EnumeratedValues: |
|
596 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
597 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
598 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 599 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
600 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
601 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
602 |
self.StartStyling(current_pos, 0xff) |
|
603 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
604 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 605 |
last_styled_pos = current_pos |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
606 |
if (state != DPRAGMA) and (state != COMMENT): |
1108
1ec5b4d244f3
Fix bug with multiline Pragma syntax highlighting in TextViewer
Laurent Bessard
parents:
1091
diff
changeset
|
607 |
state = SPACE |
814 | 608 |
line = "" |
609 |
line_number += 1 |
|
610 |
self.RefreshLineFolding(line_number) |
|
611 |
elif line.endswith("(*") and state != COMMENT: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
612 |
self.SetStyling(current_pos - last_styled_pos - 1, STC_PLC_EMPTY) |
814 | 613 |
last_styled_pos = current_pos |
614 |
if state == WORD: |
|
615 |
current_context = self.Variables |
|
616 |
state = COMMENT |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
617 |
elif line.endswith("{") and state not in [PRAGMA, DPRAGMA]: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
618 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 619 |
last_styled_pos = current_pos |
620 |
if state == WORD: |
|
621 |
current_context = self.Variables |
|
622 |
state = PRAGMA |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
623 |
elif line.endswith("{{") and state == PRAGMA: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
624 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
625 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
626 |
state = DPRAGMA |
814 | 627 |
elif state == COMMENT: |
628 |
if line.endswith("*)"): |
|
629 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
630 |
last_styled_pos = current_pos + 1 |
|
631 |
state = SPACE |
|
1521
e44950d4c218
fix highlighting input/outputs in function call in ST, if comment section is placed
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1509
diff
changeset
|
632 |
if len(self.CallStack) > 0: |
e44950d4c218
fix highlighting input/outputs in function call in ST, if comment section is placed
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1509
diff
changeset
|
633 |
current_call = self.CallStack.pop() |
e44950d4c218
fix highlighting input/outputs in function call in ST, if comment section is placed
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1509
diff
changeset
|
634 |
else: |
e44950d4c218
fix highlighting input/outputs in function call in ST, if comment section is placed
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1509
diff
changeset
|
635 |
current_call = None |
814 | 636 |
elif state == PRAGMA: |
637 |
if line.endswith("}"): |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
638 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
639 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
640 |
state = SPACE |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
641 |
elif state == DPRAGMA: |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
642 |
if line.endswith("}}"): |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
643 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_EMPTY) |
814 | 644 |
last_styled_pos = current_pos + 1 |
645 |
state = SPACE |
|
646 |
elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
647 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 648 |
last_styled_pos = current_pos |
649 |
if state == WORD: |
|
650 |
current_context = self.Variables |
|
651 |
if line.endswith("'"): |
|
652 |
state = STRING |
|
653 |
else: |
|
654 |
state = WSTRING |
|
655 |
elif state == STRING: |
|
656 |
if line.endswith("'") and not line.endswith("$'"): |
|
657 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
658 |
last_styled_pos = current_pos + 1 |
|
659 |
state = SPACE |
|
660 |
elif state == WSTRING: |
|
661 |
if line.endswith('"') and not line.endswith('$"'): |
|
662 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
663 |
last_styled_pos = current_pos + 1 |
|
664 |
state = SPACE |
|
665 |
elif char in LETTERS: |
|
666 |
if state == NUMBER: |
|
667 |
word = "#" |
|
668 |
state = WORD |
|
669 |
elif state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
670 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 671 |
word = char |
672 |
last_styled_pos = current_pos |
|
673 |
state = WORD |
|
674 |
else: |
|
675 |
word += char |
|
676 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
677 |
if state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
678 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 679 |
last_styled_pos = current_pos |
680 |
state = NUMBER |
|
681 |
elif state == WORD and char != '.': |
|
682 |
word += char |
|
683 |
elif char == '(' and state == SPACE: |
|
684 |
self.CallStack.append(current_call) |
|
685 |
current_call = None |
|
686 |
else: |
|
687 |
if state == WORD: |
|
688 |
if word in self.Keywords or word in self.TypeNames: |
|
689 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
690 |
elif self.IsValidVariable(word, current_context): |
|
691 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
692 |
elif self.IsCallParameter(word, current_call): |
|
693 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
694 |
elif word in self.Functions: |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
695 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
814 | 696 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
697 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
698 |
elif word in self.EnumeratedValues: |
|
699 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
700 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
701 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 702 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
703 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
704 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
705 |
self.StartStyling(current_pos, 0xff) |
|
706 |
if char == '.': |
|
707 |
if word != "]": |
|
708 |
if current_context is not None: |
|
709 |
current_context = current_context.get(word, None) |
|
710 |
else: |
|
711 |
current_context = None |
|
712 |
elif char == '(': |
|
713 |
self.CallStack.append(current_call) |
|
714 |
current_call = self.Functions.get(word, None) |
|
715 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
716 |
current_call = {"interface": current_context.get(word, {}), |
|
717 |
"extensible": False} |
|
718 |
current_context = self.Variables |
|
719 |
else: |
|
894
a4919f228924
Fixed bug when indexing table in Pragma within ST/IL code
Laurent Bessard
parents:
871
diff
changeset
|
720 |
if char == '[' and current_context is not None: |
814 | 721 |
self.ContextStack.append(current_context.get(word, None)) |
722 |
current_context = self.Variables |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
723 |
|
814 | 724 |
word = "" |
725 |
last_styled_pos = current_pos |
|
726 |
state = SPACE |
|
727 |
elif state == NUMBER: |
|
728 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
729 |
last_styled_pos = current_pos |
|
730 |
state = SPACE |
|
731 |
if char == ']': |
|
732 |
if len(self.ContextStack) > 0: |
|
733 |
current_context = self.ContextStack.pop() |
|
734 |
else: |
|
735 |
current_context = self.Variables |
|
736 |
word = char |
|
737 |
state = WORD |
|
738 |
elif char == ')': |
|
739 |
current_context = self.Variables |
|
740 |
if len(self.CallStack) > 0: |
|
741 |
current_call = self.CallStack.pop() |
|
742 |
else: |
|
743 |
current_call = None |
|
744 |
word = char |
|
745 |
state = WORD |
|
746 |
current_pos += 1 |
|
747 |
if state == COMMENT: |
|
748 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
749 |
elif state == NUMBER: |
|
750 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
751 |
elif state == WORD: |
|
752 |
if word in self.Keywords or word in self.TypeNames: |
|
753 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
754 |
elif self.IsValidVariable(word, current_context): |
|
755 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
756 |
elif self.IsCallParameter(word, current_call): |
|
757 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
758 |
elif self.TextSyntax == "IL" and word in self.Functions: |
|
759 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
760 |
elif word in self.Jumps: |
|
761 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
762 |
elif word in self.EnumeratedValues: |
|
763 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
764 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
765 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 766 |
else: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
767 |
self.SetStyling(current_pos - start_pos, STC_PLC_EMPTY) |
814 | 768 |
self.ShowHighlights(start_pos, end_pos) |
769 |
event.Skip() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
770 |
|
814 | 771 |
def OnMarginClick(self, event): |
772 |
if event.GetMargin() == 2: |
|
773 |
line = self.Editor.LineFromPosition(event.GetPosition()) |
|
774 |
if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
|
775 |
self.Editor.ToggleFold(line) |
|
776 |
event.Skip() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
777 |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
778 |
def OnUpdateUI(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
779 |
selected = self.Editor.GetSelectedText() |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
780 |
if self.ParentWindow and selected != "": |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
781 |
self.ParentWindow.SetCopyBuffer(selected, True) |
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
782 |
event.Skip() |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
783 |
|
814 | 784 |
def Cut(self): |
785 |
self.ResetBuffer() |
|
786 |
self.DisableEvents = True |
|
787 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
|
788 |
self.DisableEvents = False |
|
789 |
self.RefreshModel() |
|
790 |
self.RefreshBuffer() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
791 |
|
814 | 792 |
def Copy(self): |
793 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY) |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
794 |
if self.ParentWindow: |
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
795 |
self.ParentWindow.RefreshEditMenu() |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
796 |
|
814 | 797 |
def Paste(self): |
798 |
self.ResetBuffer() |
|
799 |
self.DisableEvents = True |
|
800 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
|
801 |
self.DisableEvents = False |
|
802 |
self.RefreshModel() |
|
803 |
self.RefreshBuffer() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
804 |
|
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
805 |
def Search(self, criteria): |
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
806 |
return self.Controler.SearchInPou(self.TagName, criteria, self.Debug) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
807 |
|
814 | 808 |
def Find(self, direction, search_params): |
809 |
if self.SearchParams != search_params: |
|
810 |
self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
811 |
|
814 | 812 |
self.SearchParams = search_params |
813 |
self.SearchResults = [ |
|
814 |
(infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
815 |
for infos, start, end, text in |
1556
32e9d0ef30dc
fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents:
1548
diff
changeset
|
816 |
self.Search(search_params)] |
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
817 |
self.CurrentFindHighlight = None |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
818 |
|
814 | 819 |
if len(self.SearchResults) > 0: |
820 |
if self.CurrentFindHighlight is not None: |
|
821 |
old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
822 |
if self.SearchParams["wrap"]: |
|
823 |
idx = (old_idx + direction) % len(self.SearchResults) |
|
824 |
else: |
|
825 |
idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
826 |
if idx != old_idx: |
|
827 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
828 |
self.CurrentFindHighlight = self.SearchResults[idx] |
|
829 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
830 |
else: |
|
831 |
self.CurrentFindHighlight = self.SearchResults[0] |
|
832 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
833 |
|
814 | 834 |
else: |
835 |
if self.CurrentFindHighlight is not None: |
|
836 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
837 |
self.CurrentFindHighlight = None |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
838 |
|
814 | 839 |
def RefreshModel(self): |
840 |
self.RefreshJumpList() |
|
841 |
self.Controler.SetEditedElementText(self.TagName, self.GetText()) |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
842 |
self.ResetSearchResults() |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
843 |
|
814 | 844 |
def OnKeyDown(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
845 |
key = event.GetKeyCode() |
814 | 846 |
if self.Controler is not None: |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
847 |
|
814 | 848 |
if self.Editor.CallTipActive(): |
849 |
self.Editor.CallTipCancel() |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
850 |
|
814 | 851 |
key_handled = False |
852 |
||
853 |
line = self.Editor.GetCurrentLine() |
|
854 |
if line == 0: |
|
855 |
start_pos = 0 |
|
856 |
else: |
|
857 |
start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
|
858 |
end_pos = self.GetCurrentPos() |
|
859 |
lineText = self.Editor.GetTextRange(start_pos, end_pos).replace("\t", " ") |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
860 |
|
814 | 861 |
# Code completion |
862 |
if key == wx.WXK_SPACE and event.ControlDown(): |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
863 |
|
814 | 864 |
words = lineText.split(" ") |
865 |
words = [word for i, word in enumerate(words) if word != '' or i == len(words) - 1] |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
866 |
|
814 | 867 |
kw = [] |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
868 |
|
814 | 869 |
if self.TextSyntax == "IL": |
870 |
if len(words) == 1: |
|
871 |
kw = self.Keywords |
|
872 |
elif len(words) == 2: |
|
873 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
874 |
kw = self.Functions |
|
875 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
876 |
kw = self.Jumps |
|
877 |
else: |
|
878 |
kw = self.Variables.keys() |
|
879 |
else: |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
880 |
kw = self.Keywords + self.Variables.keys() + self.Functions.keys() |
814 | 881 |
if len(kw) > 0: |
882 |
if len(words[-1]) > 0: |
|
883 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
884 |
kw.sort() |
|
885 |
self.Editor.AutoCompSetIgnoreCase(True) |
|
886 |
self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
887 |
key_handled = True |
|
888 |
elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
|
889 |
if self.TextSyntax in ["ST", "ALL"]: |
|
890 |
indent = self.Editor.GetLineIndentation(line) |
|
891 |
if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
|
892 |
indent = (indent / 2 + 1) * 2 |
|
893 |
self.Editor.AddText("\n" + " " * indent) |
|
894 |
key_handled = True |
|
895 |
elif key == wx.WXK_BACK: |
|
896 |
if self.TextSyntax in ["ST", "ALL"]: |
|
1613
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
897 |
if not self.Editor.GetSelectedText(): |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
898 |
indent = self.Editor.GetColumn(self.Editor.GetCurrentPos()) |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
899 |
if lineText.strip() == "" and len(lineText) > 0 and indent > 0: |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
900 |
self.Editor.DelLineLeft() |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
901 |
self.Editor.AddText(" " * ((max(0, indent - 1) / 2) * 2)) |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
902 |
key_handled = True |
814 | 903 |
if not key_handled: |
904 |
event.Skip() |
|
1548
3ebc08f75fef
fix issue with non-working global hotkeys in IEC code panel
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1521
diff
changeset
|
905 |
else: |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
906 |
event.Skip() |
814 | 907 |
|
908 |
def OnKillFocus(self, event): |
|
909 |
self.Editor.AutoCompCancel() |
|
910 |
event.Skip() |
|
911 |
||
912 |
#------------------------------------------------------------------------------- |
|
913 |
# Highlights showing functions |
|
914 |
#------------------------------------------------------------------------------- |
|
915 |
||
916 |
def OnRefreshHighlightsTimer(self, event): |
|
917 |
self.RefreshView() |
|
918 |
event.Skip() |
|
919 |
||
920 |
def ClearHighlights(self, highlight_type=None): |
|
921 |
EditorPanel.ClearHighlights(self, highlight_type) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
922 |
|
814 | 923 |
if highlight_type is None: |
924 |
self.Highlights = [] |
|
925 |
else: |
|
926 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
927 |
if highlight_type is not None: |
|
928 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
929 |
self.RefreshView() |
|
930 |
||
931 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
932 |
EditorPanel.AddHighlight(self, infos, start, end, highlight_type) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
933 |
|
814 | 934 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
935 |
if infos[0] == "body" and highlight_type is not None: |
|
936 |
self.Highlights.append((infos[1], start, end, highlight_type)) |
|
937 |
self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) |
|
938 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
939 |
||
940 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
941 |
EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
942 |
|
814 | 943 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
944 |
if (infos[0] == "body" and highlight_type is not None and |
814 | 945 |
(infos[1], start, end, highlight_type) in self.Highlights): |
946 |
self.Highlights.remove((infos[1], start, end, highlight_type)) |
|
947 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
948 |
|
814 | 949 |
def ShowHighlights(self, start_pos, end_pos): |
950 |
for indent, start, end, highlight_type in self.Highlights: |
|
951 |
if start[0] == 0: |
|
952 |
highlight_start_pos = start[1] - indent |
|
953 |
else: |
|
954 |
highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
|
955 |
if end[0] == 0: |
|
956 |
highlight_end_pos = end[1] - indent + 1 |
|
957 |
else: |
|
958 |
highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
|
959 |
if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
|
960 |
self.StartStyling(highlight_start_pos, 0xff) |
|
961 |
self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
|
962 |
self.StartStyling(highlight_start_pos, 0x00) |
|
963 |
self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
964 |