author | usveticic |
Wed, 16 Sep 2020 09:42:26 +0200 | |
branch | svghmi |
changeset 3057 | 696301e869d5 |
parent 2456 | 7373e3048167 |
child 2737 | 38afed869ff6 |
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 |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
27 |
from __future__ import division |
814 | 28 |
import re |
2456
7373e3048167
python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2450
diff
changeset
|
29 |
from functools import reduce |
814 | 30 |
|
31 |
import wx |
|
32 |
import wx.stc |
|
2432
dbc065a2f7a5
python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2409
diff
changeset
|
33 |
from six.moves import xrange |
814 | 34 |
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos |
814 | 39 |
|
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 |
# 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
|
42 |
# ------------------------------------------------------------------------------- |
814 | 43 |
|
44 |
||
45 |
NEWLINE = "\n" |
|
46 |
NUMBERS = [str(i) for i in xrange(10)] |
|
47 |
LETTERS = ['_'] |
|
48 |
for i in xrange(26): |
|
49 |
LETTERS.append(chr(ord('a') + i)) |
|
50 |
LETTERS.append(chr(ord('A') + i)) |
|
51 |
||
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
52 |
[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
|
53 |
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
|
54 |
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
|
55 |
STC_PLC_EMPTY] = range(11) |
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
56 |
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = range(8) |
814 | 57 |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
58 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
59 |
ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL, |
814 | 60 |
] = [wx.NewId() for _init_ctrls in range(2)] |
61 |
||
62 |
re_texts = {} |
|
63 |
re_texts["letter"] = "[A-Za-z]" |
|
64 |
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
|
65 |
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)" % re_texts |
814 | 66 |
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
|
67 |
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]" % re_texts) |
814 | 68 |
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$") |
69 |
||
70 |
HIGHLIGHT_TYPES = { |
|
71 |
ERROR_HIGHLIGHT: STC_PLC_ERROR, |
|
72 |
SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT, |
|
73 |
} |
|
74 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
75 |
|
814 | 76 |
def LineStartswith(line, symbols): |
1833
2269739dd098
fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
77 |
return reduce(lambda x, y: x or y, map(line.startswith, symbols), False) |
814 | 78 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
79 |
|
814 | 80 |
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
|
81 |
|
814 | 82 |
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
|
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, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
86 |
parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
814 | 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 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
139 |
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
|
140 |
wx.stc.STC_MOD_BEFOREDELETE | |
814 | 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 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
152 |
def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): |
814 | 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() |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
226 |
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
|
227 |
if self.CurrentAction is None: |
814 | 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) |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
234 |
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
|
235 |
if self.CurrentAction is None: |
814 | 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()) |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1775
diff
changeset
|
247 |
except Exception: |
814 | 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 == "": |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
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: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
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)]: |
|
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\" pou already exists!") % blockname |
814 | 271 |
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
|
272 |
message = _("\"%s\" element for this pou already exists!") % blockname |
814 | 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( |
|
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
279 |
[" " + 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
|
280 |
[" " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
814 | 281 |
if values[1] == "function": |
282 |
event.SetDragText(blocktype+"(\n "+hint+")") |
|
283 |
else: |
|
284 |
event.SetDragText(blockname+"(\n "+hint+")") |
|
285 |
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
|
286 |
_pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
814 | 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)]: |
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\" pou already exists!") % var_name |
814 | 300 |
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
|
301 |
message = _("\"%s\" element for this pou already exists!") % var_name |
814 | 302 |
else: |
303 |
location = values[0] |
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
_("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
|
308 |
_("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
|
309 |
[_("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
|
310 |
wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
814 | 311 |
if dialog.ShowModal() == wx.ID_OK: |
312 |
selected = dialog.GetSelection() |
|
313 |
else: |
|
314 |
selected = None |
|
315 |
dialog.Destroy() |
|
316 |
if selected is None: |
|
317 |
event.SetDragText("") |
|
318 |
return |
|
319 |
if selected == 0: |
|
320 |
location = "%I" + location |
|
321 |
elif selected == 1: |
|
322 |
location = "%Q" + location |
|
323 |
else: |
|
324 |
location = "%M" + location |
|
325 |
if values[2] is not None: |
|
326 |
var_type = values[2] |
|
327 |
else: |
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
location=location, description=values[4]) |
814 | 333 |
self.RefreshVariablePanel() |
334 |
self.RefreshVariableTree() |
|
335 |
event.SetDragText(var_name) |
|
336 |
else: |
|
337 |
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
|
338 |
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
|
339 |
_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
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
345 |
_("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
|
346 |
_('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
|
347 |
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
|
348 |
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
|
349 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
350 |
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
|
351 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
352 |
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
|
353 |
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
|
354 |
else: |
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 = 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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
event.SetDragText(var_name) |
814 | 364 |
elif values[1] == "Global": |
365 |
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
|
366 |
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
|
367 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
368 |
_("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
|
369 |
_('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
|
370 |
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
|
371 |
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
|
372 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
373 |
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
|
374 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
375 |
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
|
376 |
message = _("\"%s\" pou already exists!") % var_name |
814 | 377 |
else: |
378 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
379 |
self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
|
380 |
self.RefreshVariablePanel() |
|
381 |
self.RefreshVariableTree() |
|
382 |
event.SetDragText(var_name) |
|
383 |
elif values[1] == "Constant": |
|
384 |
event.SetDragText(values[0]) |
|
385 |
elif values[3] == self.TagName: |
|
386 |
self.ResetBuffer() |
|
387 |
event.SetDragText(values[0]) |
|
388 |
wx.CallAfter(self.RefreshModel) |
|
389 |
else: |
|
390 |
message = _("Variable don't belong to this POU!") |
|
391 |
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
|
392 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 393 |
dialog.ShowModal() |
394 |
dialog.Destroy() |
|
395 |
event.SetDragText("") |
|
396 |
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
|
397 |
|
814 | 398 |
def SetTextSyntax(self, syntax): |
399 |
self.TextSyntax = syntax |
|
400 |
if syntax in ["ST", "ALL"]: |
|
401 |
self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
|
402 |
self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
|
403 |
self.Editor.SetMarginSensitive(2, 1) |
|
404 |
self.Editor.SetMarginWidth(2, 12) |
|
405 |
if syntax == "ST": |
|
406 |
self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
|
407 |
self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
|
408 |
else: |
|
409 |
self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
|
410 |
self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
|
411 |
else: |
|
412 |
self.BlockStartKeywords = [] |
|
413 |
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
|
414 |
|
814 | 415 |
def SetKeywords(self, keywords): |
416 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
417 |
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
|
418 |
|
814 | 419 |
def RefreshJumpList(self): |
1637
6f4624687b89
fix IL jumps highlighting in Text Viewer
Surkov Sergey <surkovsv93@gmail.com>
parents:
1613
diff
changeset
|
420 |
if self.TextSyntax == "IL": |
814 | 421 |
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
|
422 |
|
814 | 423 |
# Buffer the last model state |
424 |
def RefreshBuffer(self): |
|
425 |
self.Controler.BufferProject() |
|
426 |
if self.ParentWindow: |
|
427 |
self.ParentWindow.RefreshTitle() |
|
428 |
self.ParentWindow.RefreshFileMenu() |
|
429 |
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
|
430 |
|
814 | 431 |
def StartBuffering(self): |
432 |
self.Controler.StartBuffering() |
|
433 |
if self.ParentWindow: |
|
434 |
self.ParentWindow.RefreshTitle() |
|
435 |
self.ParentWindow.RefreshFileMenu() |
|
436 |
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
|
437 |
|
814 | 438 |
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
|
439 |
if self.CurrentAction is not None: |
814 | 440 |
self.Controler.EndBuffering() |
441 |
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
|
442 |
|
814 | 443 |
def GetBufferState(self): |
444 |
if not self.Debug and self.TextSyntax != "ALL": |
|
445 |
return self.Controler.GetBufferState() |
|
446 |
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
|
447 |
|
814 | 448 |
def Undo(self): |
449 |
if not self.Debug and self.TextSyntax != "ALL": |
|
450 |
self.Controler.LoadPrevious() |
|
451 |
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
|
452 |
|
814 | 453 |
def Redo(self): |
454 |
if not self.Debug and self.TextSyntax != "ALL": |
|
455 |
self.Controler.LoadNext() |
|
456 |
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
|
457 |
|
814 | 458 |
def HasNoModel(self): |
459 |
if not self.Debug and self.TextSyntax != "ALL": |
|
460 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
461 |
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
|
462 |
|
814 | 463 |
def RefreshView(self, variablepanel=True): |
464 |
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
|
465 |
|
814 | 466 |
if self.Controler is not None: |
467 |
self.ResetBuffer() |
|
468 |
self.DisableEvents = True |
|
469 |
old_cursor_pos = self.GetCurrentPos() |
|
1060
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
470 |
line = self.Editor.GetFirstVisibleLine() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
471 |
column = self.Editor.GetXOffset() |
814 | 472 |
old_text = self.GetText() |
473 |
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
|
474 |
if old_text != new_text: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
475 |
self.SetText(new_text) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
476 |
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
|
477 |
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
|
478 |
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
|
479 |
self.Editor.GotoPos(new_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
480 |
else: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
481 |
self.Editor.GotoPos(old_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
482 |
self.RefreshJumpList() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
483 |
self.Editor.EmptyUndoBuffer() |
814 | 484 |
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
|
485 |
|
814 | 486 |
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
|
487 |
|
814 | 488 |
self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
489 |
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
|
490 |
|
814 | 491 |
self.Functions = {} |
492 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
|
493 |
for blocktype in category["list"]: |
|
494 |
blockname = blocktype["name"].upper() |
|
495 |
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
|
496 |
interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
814 | 497 |
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
|
498 |
if param not in interface: |
814 | 499 |
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
|
500 |
if blockname in self.Functions: |
814 | 501 |
self.Functions[blockname]["interface"].update(interface) |
502 |
self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
|
503 |
else: |
|
504 |
self.Functions[blockname] = {"interface": interface, |
|
505 |
"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
|
506 |
|
814 | 507 |
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
|
508 |
|
814 | 509 |
def RefreshVariableTree(self): |
510 |
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
|
511 |
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
|
512 |
(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
|
513 |
for variable in |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
514 |
self.Controler.GetEditedElementInterfaceVars( |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1853
diff
changeset
|
515 |
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
|
516 |
]) |
814 | 517 |
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
|
518 |
return_type, (var_tree, _var_dimension) = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, True, self.Debug) |
814 | 519 |
if return_type is not None: |
520 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
521 |
else: |
|
522 |
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
|
523 |
|
814 | 524 |
def GenerateVariableTree(self, list): |
525 |
tree = {} |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
526 |
for var_name, _var_type, (var_tree, _var_dimension) in list: |
814 | 527 |
tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
528 |
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
|
529 |
|
814 | 530 |
def IsValidVariable(self, name, context): |
531 |
return context is not None and context.get(name, None) is not None |
|
532 |
||
533 |
def IsCallParameter(self, name, call): |
|
534 |
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
|
535 |
return (call["interface"].get(name.upper(), None) is not None or |
814 | 536 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
537 |
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
|
538 |
|
814 | 539 |
def RefreshLineFolding(self, line_number): |
540 |
if self.TextSyntax in ["ST", "ALL"]: |
|
541 |
level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
|
542 |
line = self.Editor.GetLine(line_number).strip() |
|
543 |
if line == "": |
|
544 |
if line_number > 0: |
|
545 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
546 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
547 |
else: |
|
548 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
549 |
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
|
550 |
level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
814 | 551 |
elif LineStartswith(line, self.BlockStartKeywords): |
552 |
level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
|
553 |
elif LineStartswith(line, self.BlockEndKeywords): |
|
554 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
555 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
556 |
else: |
|
557 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
558 |
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
|
559 |
|
814 | 560 |
def OnStyleNeeded(self, event): |
561 |
self.TextChanged = True |
|
562 |
line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
|
563 |
if line_number == 0: |
|
564 |
start_pos = last_styled_pos = 0 |
|
565 |
else: |
|
566 |
start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
|
567 |
self.RefreshLineFolding(line_number) |
|
568 |
end_pos = event.GetPosition() |
|
569 |
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
|
570 |
|
814 | 571 |
current_context = self.Variables |
572 |
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
|
573 |
|
814 | 574 |
current_pos = last_styled_pos |
575 |
state = SPACE |
|
576 |
line = "" |
|
577 |
word = "" |
|
578 |
while current_pos < end_pos: |
|
579 |
char = chr(self.Editor.GetCharAt(current_pos)).upper() |
|
580 |
line += char |
|
581 |
if char == NEWLINE: |
|
582 |
self.ContextStack = [] |
|
583 |
current_context = self.Variables |
|
584 |
if state == COMMENT: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
585 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_COMMENT) |
814 | 586 |
elif state == NUMBER: |
587 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
588 |
elif state == WORD: |
|
589 |
if word in self.Keywords or word in self.TypeNames: |
|
590 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
591 |
elif self.IsValidVariable(word, current_context): |
|
592 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
593 |
elif self.IsCallParameter(word, current_call): |
|
594 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
595 |
elif word in self.Functions: |
|
596 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
597 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
598 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
599 |
elif word in self.EnumeratedValues: |
|
600 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
601 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
602 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 603 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
604 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
605 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
606 |
self.StartStyling(current_pos, 0xff) |
|
607 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
608 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 609 |
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
|
610 |
if (state != DPRAGMA) and (state != COMMENT): |
1108
1ec5b4d244f3
Fix bug with multiline Pragma syntax highlighting in TextViewer
Laurent Bessard
parents:
1091
diff
changeset
|
611 |
state = SPACE |
814 | 612 |
line = "" |
613 |
line_number += 1 |
|
614 |
self.RefreshLineFolding(line_number) |
|
615 |
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
|
616 |
self.SetStyling(current_pos - last_styled_pos - 1, STC_PLC_EMPTY) |
814 | 617 |
last_styled_pos = current_pos |
618 |
if state == WORD: |
|
619 |
current_context = self.Variables |
|
620 |
state = COMMENT |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
621 |
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
|
622 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 623 |
last_styled_pos = current_pos |
624 |
if state == WORD: |
|
625 |
current_context = self.Variables |
|
626 |
state = PRAGMA |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
627 |
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
|
628 |
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
|
629 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
630 |
state = DPRAGMA |
814 | 631 |
elif state == COMMENT: |
632 |
if line.endswith("*)"): |
|
633 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
634 |
last_styled_pos = current_pos + 1 |
|
635 |
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
|
636 |
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
|
637 |
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
|
638 |
else: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
diff
changeset
|
639 |
current_call = None |
814 | 640 |
elif state == PRAGMA: |
641 |
if line.endswith("}"): |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
642 |
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
|
643 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
644 |
state = SPACE |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
645 |
elif state == DPRAGMA: |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
646 |
if line.endswith("}}"): |
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 + 1, STC_PLC_EMPTY) |
814 | 648 |
last_styled_pos = current_pos + 1 |
649 |
state = SPACE |
|
650 |
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
|
651 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 652 |
last_styled_pos = current_pos |
653 |
if state == WORD: |
|
654 |
current_context = self.Variables |
|
655 |
if line.endswith("'"): |
|
656 |
state = STRING |
|
657 |
else: |
|
658 |
state = WSTRING |
|
659 |
elif state == STRING: |
|
660 |
if line.endswith("'") and not line.endswith("$'"): |
|
661 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
662 |
last_styled_pos = current_pos + 1 |
|
663 |
state = SPACE |
|
664 |
elif state == WSTRING: |
|
665 |
if line.endswith('"') and not line.endswith('$"'): |
|
666 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
667 |
last_styled_pos = current_pos + 1 |
|
668 |
state = SPACE |
|
669 |
elif char in LETTERS: |
|
670 |
if state == NUMBER: |
|
671 |
word = "#" |
|
672 |
state = WORD |
|
673 |
elif state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
674 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 675 |
word = char |
676 |
last_styled_pos = current_pos |
|
677 |
state = WORD |
|
678 |
else: |
|
679 |
word += char |
|
680 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
681 |
if state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
682 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 683 |
last_styled_pos = current_pos |
684 |
state = NUMBER |
|
685 |
elif state == WORD and char != '.': |
|
686 |
word += char |
|
687 |
elif char == '(' and state == SPACE: |
|
688 |
self.CallStack.append(current_call) |
|
689 |
current_call = None |
|
690 |
else: |
|
691 |
if state == WORD: |
|
692 |
if word in self.Keywords or word in self.TypeNames: |
|
693 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
694 |
elif self.IsValidVariable(word, current_context): |
|
695 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
696 |
elif self.IsCallParameter(word, current_call): |
|
697 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
698 |
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
|
699 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
814 | 700 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
701 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
702 |
elif word in self.EnumeratedValues: |
|
703 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
704 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
705 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 706 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
707 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
708 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
709 |
self.StartStyling(current_pos, 0xff) |
|
710 |
if char == '.': |
|
711 |
if word != "]": |
|
712 |
if current_context is not None: |
|
713 |
current_context = current_context.get(word, None) |
|
714 |
else: |
|
715 |
current_context = None |
|
716 |
elif char == '(': |
|
717 |
self.CallStack.append(current_call) |
|
718 |
current_call = self.Functions.get(word, None) |
|
719 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
720 |
current_call = {"interface": current_context.get(word, {}), |
|
721 |
"extensible": False} |
|
722 |
current_context = self.Variables |
|
723 |
else: |
|
894
a4919f228924
Fixed bug when indexing table in Pragma within ST/IL code
Laurent Bessard
parents:
871
diff
changeset
|
724 |
if char == '[' and current_context is not None: |
814 | 725 |
self.ContextStack.append(current_context.get(word, None)) |
726 |
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
|
727 |
|
814 | 728 |
word = "" |
729 |
last_styled_pos = current_pos |
|
730 |
state = SPACE |
|
731 |
elif state == NUMBER: |
|
732 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
733 |
last_styled_pos = current_pos |
|
734 |
state = SPACE |
|
735 |
if char == ']': |
|
736 |
if len(self.ContextStack) > 0: |
|
737 |
current_context = self.ContextStack.pop() |
|
738 |
else: |
|
739 |
current_context = self.Variables |
|
740 |
word = char |
|
741 |
state = WORD |
|
742 |
elif char == ')': |
|
743 |
current_context = self.Variables |
|
744 |
if len(self.CallStack) > 0: |
|
745 |
current_call = self.CallStack.pop() |
|
746 |
else: |
|
747 |
current_call = None |
|
748 |
word = char |
|
749 |
state = WORD |
|
750 |
current_pos += 1 |
|
751 |
if state == COMMENT: |
|
752 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
753 |
elif state == NUMBER: |
|
754 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
755 |
elif state == WORD: |
|
756 |
if word in self.Keywords or word in self.TypeNames: |
|
757 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
758 |
elif self.IsValidVariable(word, current_context): |
|
759 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
760 |
elif self.IsCallParameter(word, current_call): |
|
761 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
762 |
elif self.TextSyntax == "IL" and word in self.Functions: |
|
763 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
764 |
elif word in self.Jumps: |
|
765 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
766 |
elif word in self.EnumeratedValues: |
|
767 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
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 - last_styled_pos, STC_PLC_EMPTY) |
814 | 770 |
else: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
771 |
self.SetStyling(current_pos - start_pos, STC_PLC_EMPTY) |
814 | 772 |
self.ShowHighlights(start_pos, end_pos) |
773 |
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
|
774 |
|
814 | 775 |
def OnMarginClick(self, event): |
776 |
if event.GetMargin() == 2: |
|
777 |
line = self.Editor.LineFromPosition(event.GetPosition()) |
|
778 |
if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
|
779 |
self.Editor.ToggleFold(line) |
|
780 |
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
|
781 |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
782 |
def OnUpdateUI(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
783 |
selected = self.Editor.GetSelectedText() |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
784 |
if self.ParentWindow and selected != "": |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
785 |
self.ParentWindow.SetCopyBuffer(selected, True) |
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
786 |
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
|
787 |
|
814 | 788 |
def Cut(self): |
789 |
self.ResetBuffer() |
|
790 |
self.DisableEvents = True |
|
791 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
|
792 |
self.DisableEvents = False |
|
793 |
self.RefreshModel() |
|
794 |
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
|
795 |
|
814 | 796 |
def Copy(self): |
797 |
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
|
798 |
if self.ParentWindow: |
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
799 |
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
|
800 |
|
814 | 801 |
def Paste(self): |
802 |
self.ResetBuffer() |
|
803 |
self.DisableEvents = True |
|
804 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
|
805 |
self.DisableEvents = False |
|
806 |
self.RefreshModel() |
|
807 |
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
|
808 |
|
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
809 |
def Search(self, criteria): |
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
810 |
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
|
811 |
|
814 | 812 |
def Find(self, direction, search_params): |
813 |
if self.SearchParams != search_params: |
|
814 |
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
|
815 |
|
814 | 816 |
self.SearchParams = search_params |
817 |
self.SearchResults = [ |
|
818 |
(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
|
819 |
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
|
820 |
self.Search(search_params)] |
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
821 |
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
|
822 |
|
814 | 823 |
if len(self.SearchResults) > 0: |
824 |
if self.CurrentFindHighlight is not None: |
|
825 |
old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
826 |
if self.SearchParams["wrap"]: |
|
827 |
idx = (old_idx + direction) % len(self.SearchResults) |
|
828 |
else: |
|
829 |
idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
830 |
if idx != old_idx: |
|
831 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
832 |
self.CurrentFindHighlight = self.SearchResults[idx] |
|
833 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
834 |
else: |
|
835 |
self.CurrentFindHighlight = self.SearchResults[0] |
|
836 |
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
|
837 |
|
814 | 838 |
else: |
839 |
if self.CurrentFindHighlight is not None: |
|
840 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
841 |
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
|
842 |
|
814 | 843 |
def RefreshModel(self): |
844 |
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
|
845 |
self.Colourise(0, -1) |
814 | 846 |
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
|
847 |
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
|
848 |
|
814 | 849 |
def OnKeyDown(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
850 |
key = event.GetKeyCode() |
814 | 851 |
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
|
852 |
|
814 | 853 |
if self.Editor.CallTipActive(): |
854 |
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
|
855 |
|
814 | 856 |
key_handled = False |
857 |
||
858 |
line = self.Editor.GetCurrentLine() |
|
859 |
if line == 0: |
|
860 |
start_pos = 0 |
|
861 |
else: |
|
862 |
start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
|
863 |
end_pos = self.GetCurrentPos() |
|
864 |
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
|
865 |
|
814 | 866 |
# Code completion |
867 |
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
|
868 |
|
814 | 869 |
words = lineText.split(" ") |
870 |
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
|
871 |
|
814 | 872 |
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
|
873 |
|
814 | 874 |
if self.TextSyntax == "IL": |
875 |
if len(words) == 1: |
|
876 |
kw = self.Keywords |
|
877 |
elif len(words) == 2: |
|
878 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
879 |
kw = self.Functions |
|
880 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
881 |
kw = self.Jumps |
|
882 |
else: |
|
883 |
kw = self.Variables.keys() |
|
884 |
else: |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
885 |
kw = self.Keywords + self.Variables.keys() + self.Functions.keys() |
814 | 886 |
if len(kw) > 0: |
887 |
if len(words[-1]) > 0: |
|
888 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
889 |
kw.sort() |
|
890 |
self.Editor.AutoCompSetIgnoreCase(True) |
|
891 |
self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
892 |
key_handled = True |
|
893 |
elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
|
894 |
if self.TextSyntax in ["ST", "ALL"]: |
|
895 |
indent = self.Editor.GetLineIndentation(line) |
|
896 |
if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
897 |
indent = (indent // 2 + 1) * 2 |
814 | 898 |
self.Editor.AddText("\n" + " " * indent) |
899 |
key_handled = True |
|
900 |
elif key == wx.WXK_BACK: |
|
901 |
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
|
902 |
if not self.Editor.GetSelectedText(): |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
903 |
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
|
904 |
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
|
905 |
self.Editor.DelLineLeft() |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
906 |
self.Editor.AddText(" " * ((max(0, indent - 1) // 2) * 2)) |
1613
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
907 |
key_handled = True |
814 | 908 |
if not key_handled: |
909 |
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
|
910 |
else: |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
911 |
event.Skip() |
814 | 912 |
|
913 |
def OnKillFocus(self, event): |
|
914 |
self.Editor.AutoCompCancel() |
|
915 |
event.Skip() |
|
916 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
917 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
918 |
# Highlights showing functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
919 |
# ------------------------------------------------------------------------------- |
814 | 920 |
|
921 |
def OnRefreshHighlightsTimer(self, event): |
|
922 |
self.RefreshView() |
|
923 |
event.Skip() |
|
924 |
||
925 |
def ClearHighlights(self, highlight_type=None): |
|
926 |
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
|
927 |
|
814 | 928 |
if highlight_type is None: |
929 |
self.Highlights = [] |
|
930 |
else: |
|
931 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
932 |
if highlight_type is not None: |
|
933 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
934 |
self.RefreshView() |
|
935 |
||
936 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
937 |
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
|
938 |
|
814 | 939 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
940 |
if infos[0] == "body" and highlight_type is not None: |
|
941 |
self.Highlights.append((infos[1], start, end, highlight_type)) |
|
942 |
self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) |
|
943 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
944 |
||
945 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
946 |
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
|
947 |
|
814 | 948 |
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
|
949 |
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
|
950 |
(infos[1], start, end, highlight_type) in self.Highlights: |
814 | 951 |
self.Highlights.remove((infos[1], start, end, highlight_type)) |
952 |
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
|
953 |
|
814 | 954 |
def ShowHighlights(self, start_pos, end_pos): |
955 |
for indent, start, end, highlight_type in self.Highlights: |
|
956 |
if start[0] == 0: |
|
957 |
highlight_start_pos = start[1] - indent |
|
958 |
else: |
|
959 |
highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
|
960 |
if end[0] == 0: |
|
961 |
highlight_end_pos = end[1] - indent + 1 |
|
962 |
else: |
|
963 |
highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
|
964 |
if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
|
965 |
self.StartStyling(highlight_start_pos, 0xff) |
|
966 |
self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
|
967 |
self.StartStyling(highlight_start_pos, 0x00) |
|
2409
00d90ab8a462
Fix segmentation fault when last lines in text POUs should be highlighted
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2177
diff
changeset
|
968 |
until_end = max(0, len(self.Editor.GetText()) - highlight_end_pos) |
00d90ab8a462
Fix segmentation fault when last lines in text POUs should be highlighted
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2177
diff
changeset
|
969 |
self.SetStyling(until_end, wx.stc.STC_STYLE_DEFAULT) |