author | Edouard Tisserant |
Tue, 02 Oct 2018 15:52:11 +0200 | |
changeset 2306 | 908471b344ba |
parent 2177 | 10aa87518401 |
child 2409 | 00d90ab8a462 |
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 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
25 |
|
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
26 |
from __future__ import absolute_import |
814 | 27 |
import re |
28 |
from types import * |
|
29 |
||
30 |
import wx |
|
31 |
import wx.stc |
|
32 |
||
33 |
from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD |
|
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
34 |
from plcopen.structures import ST_BLOCK_START_KEYWORDS, IEC_BLOCK_START_KEYWORDS, LOCATIONDATATYPES |
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
35 |
from editors.EditorPanel import EditorPanel |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
36 |
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos |
814 | 37 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
38 |
# ------------------------------------------------------------------------------- |
814 | 39 |
# Textual programs Viewer class |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
40 |
# ------------------------------------------------------------------------------- |
814 | 41 |
|
42 |
||
43 |
NEWLINE = "\n" |
|
44 |
NUMBERS = [str(i) for i in xrange(10)] |
|
45 |
LETTERS = ['_'] |
|
46 |
for i in xrange(26): |
|
47 |
LETTERS.append(chr(ord('a') + i)) |
|
48 |
LETTERS.append(chr(ord('A') + i)) |
|
49 |
||
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
50 |
[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
|
51 |
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
|
52 |
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
|
53 |
STC_PLC_EMPTY] = range(11) |
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
54 |
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
814 | 55 |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
56 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
57 |
ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
814 | 58 |
] = [wx.NewId() for _init_ctrls in range(2)] |
59 |
||
60 |
re_texts = {} |
|
61 |
re_texts["letter"] = "[A-Za-z]" |
|
62 |
re_texts["digit"] = "[0-9]" |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
63 |
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)" % re_texts |
814 | 64 |
IDENTIFIER_MODEL = re.compile(re_texts["identifier"]) |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
65 |
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]" % re_texts) |
814 | 66 |
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
67 |
||
68 |
HIGHLIGHT_TYPES = { |
|
69 |
ERROR_HIGHLIGHT: STC_PLC_ERROR, |
|
70 |
SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
|
71 |
} |
|
72 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
73 |
|
814 | 74 |
def LineStartswith(line, symbols): |
1833
2269739dd098
fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
75 |
return reduce(lambda x, y: x or y, map(line.startswith, symbols), False) |
814 | 76 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
77 |
|
814 | 78 |
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
|
79 |
|
814 | 80 |
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
|
81 |
|
814 | 82 |
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
|
83 |
self.Editor = CustomStyledTextCtrl(id=ID_TEXTVIEWERTEXTCTRL, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
84 |
parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
814 | 85 |
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
|
86 |
|
814 | 87 |
self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
88 |
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
|
89 |
|
814 | 90 |
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
|
91 |
|
814 | 92 |
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
|
93 |
|
814 | 94 |
# Global default styles for all languages |
95 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
|
96 |
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
|
97 |
|
814 | 98 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
99 |
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
|
100 |
|
814 | 101 |
# Highlighting styles |
102 |
self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
|
103 |
self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
|
104 |
self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
|
105 |
self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
|
106 |
self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
|
107 |
self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
|
108 |
self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
|
109 |
self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
|
110 |
self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
|
111 |
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
|
112 |
|
814 | 113 |
# Indicators styles |
114 |
self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
|
115 |
if self.ParentWindow is not None and self.Controler is not None: |
|
116 |
self.Editor.IndicatorSetForeground(0, wx.RED) |
|
117 |
else: |
|
118 |
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
|
119 |
|
814 | 120 |
# Line numbers in the margin |
121 |
self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
|
122 |
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
|
123 |
|
814 | 124 |
# Folding |
125 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") |
|
126 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") |
|
127 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") |
|
128 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") |
|
129 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
|
130 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
|
131 |
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
|
132 |
|
814 | 133 |
# Indentation size |
134 |
self.Editor.SetTabWidth(2) |
|
135 |
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
|
136 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
137 |
self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT | |
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
138 |
wx.stc.STC_MOD_BEFOREDELETE | |
814 | 139 |
wx.stc.STC_PERFORMED_USER) |
140 |
||
141 |
self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) |
|
142 |
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
|
143 |
self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI) |
814 | 144 |
self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
145 |
if self.Controler is not None: |
|
146 |
self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
|
147 |
self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) |
|
148 |
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
|
149 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
150 |
def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): |
814 | 151 |
if tagname != "" and controler is not None: |
152 |
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
|
153 |
|
814 | 154 |
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
|
155 |
|
814 | 156 |
self.Keywords = [] |
157 |
self.Variables = {} |
|
158 |
self.Functions = {} |
|
159 |
self.TypeNames = [] |
|
160 |
self.Jumps = [] |
|
161 |
self.EnumeratedValues = [] |
|
162 |
self.DisableEvents = True |
|
163 |
self.TextSyntax = None |
|
164 |
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
|
165 |
|
814 | 166 |
self.InstancePath = instancepath |
167 |
self.ContextStack = [] |
|
168 |
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
|
169 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
170 |
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
|
171 |
|
814 | 172 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
173 |
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
|
174 |
|
814 | 175 |
def __del__(self): |
176 |
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
|
177 |
|
814 | 178 |
def GetTitle(self): |
179 |
if self.Debug or self.TagName == "": |
|
180 |
if len(self.InstancePath) > 15: |
|
181 |
return "..." + self.InstancePath[-12:] |
|
182 |
return self.InstancePath |
|
183 |
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
|
184 |
|
814 | 185 |
def GetInstancePath(self): |
186 |
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
|
187 |
|
814 | 188 |
def IsViewing(self, tagname): |
189 |
if self.Debug or self.TagName == "": |
|
190 |
return self.InstancePath == tagname |
|
191 |
else: |
|
192 |
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
|
193 |
|
814 | 194 |
def GetText(self): |
195 |
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
|
196 |
|
814 | 197 |
def SetText(self, text): |
198 |
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
|
199 |
|
814 | 200 |
def SelectAll(self): |
201 |
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
|
202 |
|
814 | 203 |
def Colourise(self, start, end): |
204 |
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
|
205 |
|
814 | 206 |
def StartStyling(self, pos, mask): |
207 |
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
|
208 |
|
814 | 209 |
def SetStyling(self, length, style): |
210 |
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
|
211 |
|
814 | 212 |
def GetCurrentPos(self): |
213 |
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
|
214 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
215 |
def ResetSearchResults(self): |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
216 |
self.Highlights = [] |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
217 |
self.SearchParams = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
218 |
self.SearchResults = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
219 |
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
|
220 |
|
814 | 221 |
def OnModification(self, event): |
222 |
if not self.DisableEvents: |
|
223 |
mod_type = event.GetModificationType() |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
224 |
if mod_type & wx.stc.STC_MOD_BEFOREINSERT: |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
225 |
if self.CurrentAction is None: |
814 | 226 |
self.StartBuffering() |
227 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
228 |
self.Controler.EndBuffering() |
|
229 |
self.StartBuffering() |
|
230 |
self.CurrentAction = ("Add", event.GetPosition()) |
|
231 |
wx.CallAfter(self.RefreshModel) |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
232 |
elif mod_type & wx.stc.STC_MOD_BEFOREDELETE: |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
233 |
if self.CurrentAction is None: |
814 | 234 |
self.StartBuffering() |
235 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
236 |
self.Controler.EndBuffering() |
|
237 |
self.StartBuffering() |
|
238 |
self.CurrentAction = ("Delete", event.GetPosition()) |
|
239 |
wx.CallAfter(self.RefreshModel) |
|
240 |
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
|
241 |
|
814 | 242 |
def OnDoDrop(self, event): |
243 |
try: |
|
244 |
values = eval(event.GetDragText()) |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1775
diff
changeset
|
245 |
except Exception: |
814 | 246 |
values = event.GetDragText() |
247 |
if isinstance(values, tuple): |
|
248 |
message = None |
|
249 |
if values[1] in ["program", "debug"]: |
|
250 |
event.SetDragText("") |
|
251 |
elif values[1] in ["functionBlock", "function"]: |
|
252 |
blocktype = values[0] |
|
253 |
blockname = values[2] |
|
254 |
if len(values) > 3: |
|
255 |
blockinputs = values[3] |
|
256 |
else: |
|
257 |
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
|
258 |
if values[1] != "function": |
814 | 259 |
if blockname == "": |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
260 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Block name"), _("Please enter a block name"), "", wx.OK | wx.CANCEL | wx.CENTRE) |
814 | 261 |
if dialog.ShowModal() == wx.ID_OK: |
262 |
blockname = dialog.GetValue() |
|
263 |
else: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
diff
changeset
|
264 |
event.SetDragText("") |
814 | 265 |
return |
266 |
dialog.Destroy() |
|
267 |
if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
268 |
message = _("\"%s\" pou already exists!") % blockname |
814 | 269 |
elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
270 |
message = _("\"%s\" element for this pou already exists!") % blockname |
814 | 271 |
else: |
272 |
self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
273 |
self.RefreshVariablePanel() |
|
274 |
self.RefreshVariableTree() |
|
275 |
blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug) |
|
276 |
hint = ',\n '.join( |
|
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
277 |
[" " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
278 |
[" " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
814 | 279 |
if values[1] == "function": |
280 |
event.SetDragText(blocktype+"(\n "+hint+")") |
|
281 |
else: |
|
282 |
event.SetDragText(blockname+"(\n "+hint+")") |
|
283 |
elif values[1] == "location": |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
284 |
_pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
814 | 285 |
if len(values) > 2 and pou_type == "program": |
286 |
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
|
287 |
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
|
288 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
289 |
_("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
|
290 |
_('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
|
291 |
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
|
292 |
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
|
293 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
294 |
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
|
295 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
296 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
297 |
message = _("\"%s\" pou already exists!") % var_name |
814 | 298 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
299 |
message = _("\"%s\" element for this pou already exists!") % var_name |
814 | 300 |
else: |
301 |
location = values[0] |
|
302 |
if not location.startswith("%"): |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
303 |
dialog = wx.SingleChoiceDialog( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
304 |
self.ParentWindow, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
305 |
_("Select a variable class:"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
306 |
_("Variable class"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
307 |
[_("Input"), _("Output"), _("Memory")], |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
308 |
wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
814 | 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] |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
327 |
self.Controler.AddEditedElementPouVar( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
location=location, description=values[4]) |
814 | 331 |
self.RefreshVariablePanel() |
332 |
self.RefreshVariableTree() |
|
333 |
event.SetDragText(var_name) |
|
334 |
else: |
|
335 |
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
|
336 |
elif values[1] == "NamedConstant": |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
337 |
_pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, 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
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
343 |
_("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
|
344 |
_('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
|
345 |
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
|
346 |
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
|
347 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
348 |
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
|
349 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
350 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
351 |
message = _("\"%s\" pou already exists!") % var_name |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
352 |
else: |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
event.SetDragText(var_name) |
814 | 362 |
elif values[1] == "Global": |
363 |
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
|
364 |
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
|
365 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
366 |
_("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
|
367 |
_('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
|
368 |
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
|
369 |
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
|
370 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
371 |
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
|
372 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
373 |
elif var_name.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
374 |
message = _("\"%s\" pou already exists!") % var_name |
814 | 375 |
else: |
376 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
377 |
self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
|
378 |
self.RefreshVariablePanel() |
|
379 |
self.RefreshVariableTree() |
|
380 |
event.SetDragText(var_name) |
|
381 |
elif values[1] == "Constant": |
|
382 |
event.SetDragText(values[0]) |
|
383 |
elif values[3] == self.TagName: |
|
384 |
self.ResetBuffer() |
|
385 |
event.SetDragText(values[0]) |
|
386 |
wx.CallAfter(self.RefreshModel) |
|
387 |
else: |
|
388 |
message = _("Variable don't belong to this POU!") |
|
389 |
if message is not None: |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
390 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 391 |
dialog.ShowModal() |
392 |
dialog.Destroy() |
|
393 |
event.SetDragText("") |
|
394 |
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
|
395 |
|
814 | 396 |
def SetTextSyntax(self, syntax): |
397 |
self.TextSyntax = syntax |
|
398 |
if syntax in ["ST", "ALL"]: |
|
399 |
self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
|
400 |
self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
|
401 |
self.Editor.SetMarginSensitive(2, 1) |
|
402 |
self.Editor.SetMarginWidth(2, 12) |
|
403 |
if syntax == "ST": |
|
404 |
self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
|
405 |
self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
|
406 |
else: |
|
407 |
self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
|
408 |
self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
|
409 |
else: |
|
410 |
self.BlockStartKeywords = [] |
|
411 |
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
|
412 |
|
814 | 413 |
def SetKeywords(self, keywords): |
414 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
415 |
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
|
416 |
|
814 | 417 |
def RefreshJumpList(self): |
1637
6f4624687b89
fix IL jumps highlighting in Text Viewer
Surkov Sergey <surkovsv93@gmail.com>
parents:
1613
diff
changeset
|
418 |
if self.TextSyntax == "IL": |
814 | 419 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.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
|
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): |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
437 |
if self.CurrentAction is not None: |
814 | 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) |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
476 |
if new_cursor_pos is not None: |
1060
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(): |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
494 |
interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
814 | 495 |
for param in ["EN", "ENO"]: |
1775
b45f2768fab1
clean-up: fix PEP8 E713 test for membership should be 'not in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
496 |
if param not in interface: |
814 | 497 |
interface[param] = {} |
1763
bcc07ff2362c
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset
|
498 |
if blockname in self.Functions: |
814 | 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("::") |
|
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
509 |
self.Variables = self.GenerateVariableTree([ |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
510 |
(variable.Name, variable.Type, variable.Tree) |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
511 |
for variable in |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
512 |
self.Controler.GetEditedElementInterfaceVars( |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
513 |
self.TagName, True, self.Debug) |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
514 |
]) |
814 | 515 |
if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL": |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
516 |
return_type, (var_tree, _var_dimension) = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, True, self.Debug) |
814 | 517 |
if return_type is not None: |
518 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
519 |
else: |
|
520 |
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
|
521 |
|
814 | 522 |
def GenerateVariableTree(self, list): |
523 |
tree = {} |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
524 |
for var_name, _var_type, (var_tree, _var_dimension) in list: |
814 | 525 |
tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
526 |
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
|
527 |
|
814 | 528 |
def IsValidVariable(self, name, context): |
529 |
return context is not None and context.get(name, None) is not None |
|
530 |
||
531 |
def IsCallParameter(self, name, call): |
|
532 |
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
|
533 |
return (call["interface"].get(name.upper(), None) is not None or |
814 | 534 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
535 |
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
|
536 |
|
814 | 537 |
def RefreshLineFolding(self, line_number): |
538 |
if self.TextSyntax in ["ST", "ALL"]: |
|
539 |
level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
|
540 |
line = self.Editor.GetLine(line_number).strip() |
|
541 |
if line == "": |
|
542 |
if line_number > 0: |
|
543 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
544 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
545 |
else: |
|
546 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
547 |
if level != wx.stc.STC_FOLDLEVELBASE: |
|
1758
845ca626db09
clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
548 |
level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
814 | 549 |
elif LineStartswith(line, self.BlockStartKeywords): |
550 |
level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
|
551 |
elif LineStartswith(line, self.BlockEndKeywords): |
|
552 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
553 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
554 |
else: |
|
555 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
556 |
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
|
557 |
|
814 | 558 |
def OnStyleNeeded(self, event): |
559 |
self.TextChanged = True |
|
560 |
line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
|
561 |
if line_number == 0: |
|
562 |
start_pos = last_styled_pos = 0 |
|
563 |
else: |
|
564 |
start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
|
565 |
self.RefreshLineFolding(line_number) |
|
566 |
end_pos = event.GetPosition() |
|
567 |
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
|
568 |
|
814 | 569 |
current_context = self.Variables |
570 |
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
|
571 |
|
814 | 572 |
current_pos = last_styled_pos |
573 |
state = SPACE |
|
574 |
line = "" |
|
575 |
word = "" |
|
576 |
while current_pos < end_pos: |
|
577 |
char = chr(self.Editor.GetCharAt(current_pos)).upper() |
|
578 |
line += char |
|
579 |
if char == NEWLINE: |
|
580 |
self.ContextStack = [] |
|
581 |
current_context = self.Variables |
|
582 |
if state == COMMENT: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
583 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_COMMENT) |
814 | 584 |
elif state == NUMBER: |
585 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
586 |
elif state == WORD: |
|
587 |
if word in self.Keywords or word in self.TypeNames: |
|
588 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
589 |
elif self.IsValidVariable(word, current_context): |
|
590 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
591 |
elif self.IsCallParameter(word, current_call): |
|
592 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
593 |
elif word in self.Functions: |
|
594 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
595 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
596 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
597 |
elif word in self.EnumeratedValues: |
|
598 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
599 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
600 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 601 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
602 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
603 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
604 |
self.StartStyling(current_pos, 0xff) |
|
605 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
606 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 607 |
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
|
608 |
if (state != DPRAGMA) and (state != COMMENT): |
1108
1ec5b4d244f3
Fix bug with multiline Pragma syntax highlighting in TextViewer
Laurent Bessard
parents:
1091
diff
changeset
|
609 |
state = SPACE |
814 | 610 |
line = "" |
611 |
line_number += 1 |
|
612 |
self.RefreshLineFolding(line_number) |
|
613 |
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
|
614 |
self.SetStyling(current_pos - last_styled_pos - 1, STC_PLC_EMPTY) |
814 | 615 |
last_styled_pos = current_pos |
616 |
if state == WORD: |
|
617 |
current_context = self.Variables |
|
618 |
state = COMMENT |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
619 |
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
|
620 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 621 |
last_styled_pos = current_pos |
622 |
if state == WORD: |
|
623 |
current_context = self.Variables |
|
624 |
state = PRAGMA |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
625 |
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
|
626 |
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
|
627 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
628 |
state = DPRAGMA |
814 | 629 |
elif state == COMMENT: |
630 |
if line.endswith("*)"): |
|
631 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
632 |
last_styled_pos = current_pos + 1 |
|
633 |
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
|
634 |
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
|
635 |
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
|
636 |
else: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
diff
changeset
|
637 |
current_call = None |
814 | 638 |
elif state == PRAGMA: |
639 |
if line.endswith("}"): |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
640 |
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
|
641 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
642 |
state = SPACE |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
643 |
elif state == DPRAGMA: |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
644 |
if line.endswith("}}"): |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
645 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_EMPTY) |
814 | 646 |
last_styled_pos = current_pos + 1 |
647 |
state = SPACE |
|
648 |
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
|
649 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 650 |
last_styled_pos = current_pos |
651 |
if state == WORD: |
|
652 |
current_context = self.Variables |
|
653 |
if line.endswith("'"): |
|
654 |
state = STRING |
|
655 |
else: |
|
656 |
state = WSTRING |
|
657 |
elif state == STRING: |
|
658 |
if line.endswith("'") and not line.endswith("$'"): |
|
659 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
660 |
last_styled_pos = current_pos + 1 |
|
661 |
state = SPACE |
|
662 |
elif state == WSTRING: |
|
663 |
if line.endswith('"') and not line.endswith('$"'): |
|
664 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
665 |
last_styled_pos = current_pos + 1 |
|
666 |
state = SPACE |
|
667 |
elif char in LETTERS: |
|
668 |
if state == NUMBER: |
|
669 |
word = "#" |
|
670 |
state = WORD |
|
671 |
elif state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
672 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 673 |
word = char |
674 |
last_styled_pos = current_pos |
|
675 |
state = WORD |
|
676 |
else: |
|
677 |
word += char |
|
678 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
679 |
if state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
680 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 681 |
last_styled_pos = current_pos |
682 |
state = NUMBER |
|
683 |
elif state == WORD and char != '.': |
|
684 |
word += char |
|
685 |
elif char == '(' and state == SPACE: |
|
686 |
self.CallStack.append(current_call) |
|
687 |
current_call = None |
|
688 |
else: |
|
689 |
if state == WORD: |
|
690 |
if word in self.Keywords or word in self.TypeNames: |
|
691 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
692 |
elif self.IsValidVariable(word, current_context): |
|
693 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
694 |
elif self.IsCallParameter(word, current_call): |
|
695 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
696 |
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
|
697 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
814 | 698 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
699 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
700 |
elif word in self.EnumeratedValues: |
|
701 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
702 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
703 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 704 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
705 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
706 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
707 |
self.StartStyling(current_pos, 0xff) |
|
708 |
if char == '.': |
|
709 |
if word != "]": |
|
710 |
if current_context is not None: |
|
711 |
current_context = current_context.get(word, None) |
|
712 |
else: |
|
713 |
current_context = None |
|
714 |
elif char == '(': |
|
715 |
self.CallStack.append(current_call) |
|
716 |
current_call = self.Functions.get(word, None) |
|
717 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
718 |
current_call = {"interface": current_context.get(word, {}), |
|
719 |
"extensible": False} |
|
720 |
current_context = self.Variables |
|
721 |
else: |
|
894
a4919f228924
Fixed bug when indexing table in Pragma within ST/IL code
Laurent Bessard
parents:
871
diff
changeset
|
722 |
if char == '[' and current_context is not None: |
814 | 723 |
self.ContextStack.append(current_context.get(word, None)) |
724 |
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
|
725 |
|
814 | 726 |
word = "" |
727 |
last_styled_pos = current_pos |
|
728 |
state = SPACE |
|
729 |
elif state == NUMBER: |
|
730 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
731 |
last_styled_pos = current_pos |
|
732 |
state = SPACE |
|
733 |
if char == ']': |
|
734 |
if len(self.ContextStack) > 0: |
|
735 |
current_context = self.ContextStack.pop() |
|
736 |
else: |
|
737 |
current_context = self.Variables |
|
738 |
word = char |
|
739 |
state = WORD |
|
740 |
elif char == ')': |
|
741 |
current_context = self.Variables |
|
742 |
if len(self.CallStack) > 0: |
|
743 |
current_call = self.CallStack.pop() |
|
744 |
else: |
|
745 |
current_call = None |
|
746 |
word = char |
|
747 |
state = WORD |
|
748 |
current_pos += 1 |
|
749 |
if state == COMMENT: |
|
750 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
751 |
elif state == NUMBER: |
|
752 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
753 |
elif state == WORD: |
|
754 |
if word in self.Keywords or word in self.TypeNames: |
|
755 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
756 |
elif self.IsValidVariable(word, current_context): |
|
757 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
758 |
elif self.IsCallParameter(word, current_call): |
|
759 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
760 |
elif self.TextSyntax == "IL" and word in self.Functions: |
|
761 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
762 |
elif word in self.Jumps: |
|
763 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
764 |
elif word in self.EnumeratedValues: |
|
765 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
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 - last_styled_pos, STC_PLC_EMPTY) |
814 | 768 |
else: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
769 |
self.SetStyling(current_pos - start_pos, STC_PLC_EMPTY) |
814 | 770 |
self.ShowHighlights(start_pos, end_pos) |
771 |
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
|
772 |
|
814 | 773 |
def OnMarginClick(self, event): |
774 |
if event.GetMargin() == 2: |
|
775 |
line = self.Editor.LineFromPosition(event.GetPosition()) |
|
776 |
if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
|
777 |
self.Editor.ToggleFold(line) |
|
778 |
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
|
779 |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
780 |
def OnUpdateUI(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
781 |
selected = self.Editor.GetSelectedText() |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
782 |
if self.ParentWindow and selected != "": |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
783 |
self.ParentWindow.SetCopyBuffer(selected, True) |
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
784 |
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
|
785 |
|
814 | 786 |
def Cut(self): |
787 |
self.ResetBuffer() |
|
788 |
self.DisableEvents = True |
|
789 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
|
790 |
self.DisableEvents = False |
|
791 |
self.RefreshModel() |
|
792 |
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
|
793 |
|
814 | 794 |
def Copy(self): |
795 |
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
|
796 |
if self.ParentWindow: |
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
797 |
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
|
798 |
|
814 | 799 |
def Paste(self): |
800 |
self.ResetBuffer() |
|
801 |
self.DisableEvents = True |
|
802 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
|
803 |
self.DisableEvents = False |
|
804 |
self.RefreshModel() |
|
805 |
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
|
806 |
|
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
807 |
def Search(self, criteria): |
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
808 |
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
|
809 |
|
814 | 810 |
def Find(self, direction, search_params): |
811 |
if self.SearchParams != search_params: |
|
812 |
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
|
813 |
|
814 | 814 |
self.SearchParams = search_params |
815 |
self.SearchResults = [ |
|
816 |
(infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT) |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
817 |
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
|
818 |
self.Search(search_params)] |
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
819 |
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
|
820 |
|
814 | 821 |
if len(self.SearchResults) > 0: |
822 |
if self.CurrentFindHighlight is not None: |
|
823 |
old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
824 |
if self.SearchParams["wrap"]: |
|
825 |
idx = (old_idx + direction) % len(self.SearchResults) |
|
826 |
else: |
|
827 |
idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
828 |
if idx != old_idx: |
|
829 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
830 |
self.CurrentFindHighlight = self.SearchResults[idx] |
|
831 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
832 |
else: |
|
833 |
self.CurrentFindHighlight = self.SearchResults[0] |
|
834 |
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
|
835 |
|
814 | 836 |
else: |
837 |
if self.CurrentFindHighlight is not None: |
|
838 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
839 |
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
|
840 |
|
814 | 841 |
def RefreshModel(self): |
842 |
self.RefreshJumpList() |
|
1904
7dd49b65208b
Textviewer : moved call to Colourise in a better place, so that ST highlighting gets also updated when typing in some case, not only IL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
1878
diff
changeset
|
843 |
self.Colourise(0, -1) |
814 | 844 |
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
|
845 |
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
|
846 |
|
814 | 847 |
def OnKeyDown(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
848 |
key = event.GetKeyCode() |
814 | 849 |
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
|
850 |
|
814 | 851 |
if self.Editor.CallTipActive(): |
852 |
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
|
853 |
|
814 | 854 |
key_handled = False |
855 |
||
856 |
line = self.Editor.GetCurrentLine() |
|
857 |
if line == 0: |
|
858 |
start_pos = 0 |
|
859 |
else: |
|
860 |
start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
|
861 |
end_pos = self.GetCurrentPos() |
|
862 |
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
|
863 |
|
814 | 864 |
# Code completion |
865 |
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
|
866 |
|
814 | 867 |
words = lineText.split(" ") |
868 |
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
|
869 |
|
814 | 870 |
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
|
871 |
|
814 | 872 |
if self.TextSyntax == "IL": |
873 |
if len(words) == 1: |
|
874 |
kw = self.Keywords |
|
875 |
elif len(words) == 2: |
|
876 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
877 |
kw = self.Functions |
|
878 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
879 |
kw = self.Jumps |
|
880 |
else: |
|
881 |
kw = self.Variables.keys() |
|
882 |
else: |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
883 |
kw = self.Keywords + self.Variables.keys() + self.Functions.keys() |
814 | 884 |
if len(kw) > 0: |
885 |
if len(words[-1]) > 0: |
|
886 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
887 |
kw.sort() |
|
888 |
self.Editor.AutoCompSetIgnoreCase(True) |
|
889 |
self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
890 |
key_handled = True |
|
891 |
elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
|
892 |
if self.TextSyntax in ["ST", "ALL"]: |
|
893 |
indent = self.Editor.GetLineIndentation(line) |
|
894 |
if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
|
895 |
indent = (indent / 2 + 1) * 2 |
|
896 |
self.Editor.AddText("\n" + " " * indent) |
|
897 |
key_handled = True |
|
898 |
elif key == wx.WXK_BACK: |
|
899 |
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
|
900 |
if not self.Editor.GetSelectedText(): |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
901 |
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
|
902 |
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
|
903 |
self.Editor.DelLineLeft() |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
904 |
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
|
905 |
key_handled = True |
814 | 906 |
if not key_handled: |
907 |
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
|
908 |
else: |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
909 |
event.Skip() |
814 | 910 |
|
911 |
def OnKillFocus(self, event): |
|
912 |
self.Editor.AutoCompCancel() |
|
913 |
event.Skip() |
|
914 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
915 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
916 |
# Highlights showing functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
917 |
# ------------------------------------------------------------------------------- |
814 | 918 |
|
919 |
def OnRefreshHighlightsTimer(self, event): |
|
920 |
self.RefreshView() |
|
921 |
event.Skip() |
|
922 |
||
923 |
def ClearHighlights(self, highlight_type=None): |
|
924 |
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
|
925 |
|
814 | 926 |
if highlight_type is None: |
927 |
self.Highlights = [] |
|
928 |
else: |
|
929 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
930 |
if highlight_type is not None: |
|
931 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
932 |
self.RefreshView() |
|
933 |
||
934 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
935 |
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
|
936 |
|
814 | 937 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
938 |
if infos[0] == "body" and highlight_type is not None: |
|
939 |
self.Highlights.append((infos[1], start, end, highlight_type)) |
|
940 |
self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) |
|
941 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
942 |
||
943 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
944 |
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
|
945 |
|
814 | 946 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
947 |
if infos[0] == "body" and highlight_type is not None and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
948 |
(infos[1], start, end, highlight_type) in self.Highlights: |
814 | 949 |
self.Highlights.remove((infos[1], start, end, highlight_type)) |
950 |
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
|
951 |
|
814 | 952 |
def ShowHighlights(self, start_pos, end_pos): |
953 |
for indent, start, end, highlight_type in self.Highlights: |
|
954 |
if start[0] == 0: |
|
955 |
highlight_start_pos = start[1] - indent |
|
956 |
else: |
|
957 |
highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
|
958 |
if end[0] == 0: |
|
959 |
highlight_end_pos = end[1] - indent + 1 |
|
960 |
else: |
|
961 |
highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
|
962 |
if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
|
963 |
self.StartStyling(highlight_start_pos, 0xff) |
|
964 |
self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
|
965 |
self.StartStyling(highlight_start_pos, 0x00) |
|
966 |
self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) |