author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 11 Oct 2017 13:15:21 +0300 | |
changeset 1868 | 616c3f4bcbcb |
parent 1853 | 47a3f39bead0 |
child 1878 | fb73a6b6622d |
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 |
if wx.VERSION < (2, 6, 0): |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
83 |
def Bind(self, event, function, id=None): |
814 | 84 |
if id is not None: |
85 |
event(self, id, function) |
|
86 |
else: |
|
87 |
event(self, function) |
|
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
88 |
|
814 | 89 |
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
|
90 |
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
|
91 |
parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0) |
814 | 92 |
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
|
93 |
|
814 | 94 |
self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN) |
95 |
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
|
96 |
|
814 | 97 |
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
|
98 |
|
814 | 99 |
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
|
100 |
|
814 | 101 |
# Global default styles for all languages |
102 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces) |
|
103 |
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
|
104 |
|
814 | 105 |
self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,size:%(size)d" % faces) |
106 |
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
|
107 |
|
814 | 108 |
# Highlighting styles |
109 |
self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces) |
|
110 |
self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces) |
|
111 |
self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces) |
|
112 |
self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces) |
|
113 |
self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) |
|
114 |
self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) |
|
115 |
self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces) |
|
116 |
self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces) |
|
117 |
self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) |
|
118 |
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
|
119 |
|
814 | 120 |
# Indicators styles |
121 |
self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) |
|
122 |
if self.ParentWindow is not None and self.Controler is not None: |
|
123 |
self.Editor.IndicatorSetForeground(0, wx.RED) |
|
124 |
else: |
|
125 |
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
|
126 |
|
814 | 127 |
# Line numbers in the margin |
128 |
self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER) |
|
129 |
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
|
130 |
|
814 | 131 |
# Folding |
132 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN, wx.stc.STC_MARK_BOXMINUS, "white", "#808080") |
|
133 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS, "white", "#808080") |
|
134 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE, "white", "#808080") |
|
135 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL, wx.stc.STC_MARK_LCORNER, "white", "#808080") |
|
136 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND, wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") |
|
137 |
self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") |
|
138 |
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
|
139 |
|
814 | 140 |
# Indentation size |
141 |
self.Editor.SetTabWidth(2) |
|
142 |
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
|
143 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
144 |
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
|
145 |
wx.stc.STC_MOD_BEFOREDELETE | |
814 | 146 |
wx.stc.STC_PERFORMED_USER) |
147 |
||
148 |
self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, id=ID_TEXTVIEWERTEXTCTRL) |
|
149 |
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
|
150 |
self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI) |
814 | 151 |
self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
152 |
if self.Controler is not None: |
|
153 |
self.Editor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
|
154 |
self.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_TEXTVIEWERTEXTCTRL) |
|
155 |
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
|
156 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
157 |
def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""): |
814 | 158 |
if tagname != "" and controler is not None: |
159 |
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
|
160 |
|
814 | 161 |
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
|
162 |
|
814 | 163 |
self.Keywords = [] |
164 |
self.Variables = {} |
|
165 |
self.Functions = {} |
|
166 |
self.TypeNames = [] |
|
167 |
self.Jumps = [] |
|
168 |
self.EnumeratedValues = [] |
|
169 |
self.DisableEvents = True |
|
170 |
self.TextSyntax = None |
|
171 |
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
|
172 |
|
814 | 173 |
self.InstancePath = instancepath |
174 |
self.ContextStack = [] |
|
175 |
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
|
176 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
177 |
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
|
178 |
|
814 | 179 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
180 |
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
|
181 |
|
814 | 182 |
def __del__(self): |
183 |
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
|
184 |
|
814 | 185 |
def GetTitle(self): |
186 |
if self.Debug or self.TagName == "": |
|
187 |
if len(self.InstancePath) > 15: |
|
188 |
return "..." + self.InstancePath[-12:] |
|
189 |
return self.InstancePath |
|
190 |
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
|
191 |
|
814 | 192 |
def GetInstancePath(self): |
193 |
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
|
194 |
|
814 | 195 |
def IsViewing(self, tagname): |
196 |
if self.Debug or self.TagName == "": |
|
197 |
return self.InstancePath == tagname |
|
198 |
else: |
|
199 |
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
|
200 |
|
814 | 201 |
def GetText(self): |
202 |
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
|
203 |
|
814 | 204 |
def SetText(self, text): |
205 |
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
|
206 |
|
814 | 207 |
def SelectAll(self): |
208 |
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
|
209 |
|
814 | 210 |
def Colourise(self, start, end): |
211 |
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
|
212 |
|
814 | 213 |
def StartStyling(self, pos, mask): |
214 |
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
|
215 |
|
814 | 216 |
def SetStyling(self, length, style): |
217 |
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
|
218 |
|
814 | 219 |
def GetCurrentPos(self): |
220 |
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
|
221 |
|
1178
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
222 |
def ResetSearchResults(self): |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
223 |
self.Highlights = [] |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
224 |
self.SearchParams = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
225 |
self.SearchResults = None |
3e2aebc9c7c0
Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents:
1126
diff
changeset
|
226 |
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
|
227 |
|
814 | 228 |
def OnModification(self, event): |
229 |
if not self.DisableEvents: |
|
230 |
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
|
231 |
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
|
232 |
if self.CurrentAction is None: |
814 | 233 |
self.StartBuffering() |
234 |
elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1: |
|
235 |
self.Controler.EndBuffering() |
|
236 |
self.StartBuffering() |
|
237 |
self.CurrentAction = ("Add", event.GetPosition()) |
|
238 |
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
|
239 |
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
|
240 |
if self.CurrentAction is None: |
814 | 241 |
self.StartBuffering() |
242 |
elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1: |
|
243 |
self.Controler.EndBuffering() |
|
244 |
self.StartBuffering() |
|
245 |
self.CurrentAction = ("Delete", event.GetPosition()) |
|
246 |
wx.CallAfter(self.RefreshModel) |
|
247 |
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
|
248 |
|
814 | 249 |
def OnDoDrop(self, event): |
250 |
try: |
|
251 |
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
|
252 |
except Exception: |
814 | 253 |
values = event.GetDragText() |
254 |
if isinstance(values, tuple): |
|
255 |
message = None |
|
256 |
if values[1] in ["program", "debug"]: |
|
257 |
event.SetDragText("") |
|
258 |
elif values[1] in ["functionBlock", "function"]: |
|
259 |
blocktype = values[0] |
|
260 |
blockname = values[2] |
|
261 |
if len(values) > 3: |
|
262 |
blockinputs = values[3] |
|
263 |
else: |
|
264 |
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
|
265 |
if values[1] != "function": |
814 | 266 |
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
|
267 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Block name"), _("Please enter a block name"), "", wx.OK | wx.CANCEL | wx.CENTRE) |
814 | 268 |
if dialog.ShowModal() == wx.ID_OK: |
269 |
blockname = dialog.GetValue() |
|
270 |
else: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
diff
changeset
|
271 |
event.SetDragText("") |
814 | 272 |
return |
273 |
dialog.Destroy() |
|
274 |
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
|
275 |
message = _("\"%s\" pou already exists!") % blockname |
814 | 276 |
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
|
277 |
message = _("\"%s\" element for this pou already exists!") % blockname |
814 | 278 |
else: |
279 |
self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname) |
|
280 |
self.RefreshVariablePanel() |
|
281 |
self.RefreshVariableTree() |
|
282 |
blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug) |
|
283 |
hint = ',\n '.join( |
|
1747
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
284 |
[" " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] + |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
285 |
[" " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]]) |
814 | 286 |
if values[1] == "function": |
287 |
event.SetDragText(blocktype+"(\n "+hint+")") |
|
288 |
else: |
|
289 |
event.SetDragText(blockname+"(\n "+hint+")") |
|
290 |
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
|
291 |
_pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
814 | 292 |
if len(values) > 2 and pou_type == "program": |
293 |
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
|
294 |
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
|
295 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
296 |
_("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
|
297 |
_('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
|
298 |
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
|
299 |
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
|
300 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
301 |
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
|
302 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
303 |
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
|
304 |
message = _("\"%s\" pou already exists!") % var_name |
814 | 305 |
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
|
306 |
message = _("\"%s\" element for this pou already exists!") % var_name |
814 | 307 |
else: |
308 |
location = values[0] |
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
_("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
|
313 |
_("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
|
314 |
[_("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
|
315 |
wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
814 | 316 |
if dialog.ShowModal() == wx.ID_OK: |
317 |
selected = dialog.GetSelection() |
|
318 |
else: |
|
319 |
selected = None |
|
320 |
dialog.Destroy() |
|
321 |
if selected is None: |
|
322 |
event.SetDragText("") |
|
323 |
return |
|
324 |
if selected == 0: |
|
325 |
location = "%I" + location |
|
326 |
elif selected == 1: |
|
327 |
location = "%Q" + location |
|
328 |
else: |
|
329 |
location = "%M" + location |
|
330 |
if values[2] is not None: |
|
331 |
var_type = values[2] |
|
332 |
else: |
|
333 |
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
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
location=location, description=values[4]) |
814 | 338 |
self.RefreshVariablePanel() |
339 |
self.RefreshVariableTree() |
|
340 |
event.SetDragText(var_name) |
|
341 |
else: |
|
342 |
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
|
343 |
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
|
344 |
_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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
350 |
_("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
|
351 |
_('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
|
352 |
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
|
353 |
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
|
354 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
355 |
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
|
356 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
357 |
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
|
358 |
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
|
359 |
else: |
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
event.SetDragText(var_name) |
814 | 369 |
elif values[1] == "Global": |
370 |
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
|
371 |
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
|
372 |
self.ParentWindow, |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
373 |
_("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
|
374 |
_('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
|
375 |
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
|
376 |
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
|
377 |
dlg.Destroy() |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
378 |
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
|
379 |
return |
374238039643
Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents:
1409
diff
changeset
|
380 |
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
|
381 |
message = _("\"%s\" pou already exists!") % var_name |
814 | 382 |
else: |
383 |
if not var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]: |
|
384 |
self.Controler.AddEditedElementPouExternalVar(self.TagName, values[2], var_name) |
|
385 |
self.RefreshVariablePanel() |
|
386 |
self.RefreshVariableTree() |
|
387 |
event.SetDragText(var_name) |
|
388 |
elif values[1] == "Constant": |
|
389 |
event.SetDragText(values[0]) |
|
390 |
elif values[3] == self.TagName: |
|
391 |
self.ResetBuffer() |
|
392 |
event.SetDragText(values[0]) |
|
393 |
wx.CallAfter(self.RefreshModel) |
|
394 |
else: |
|
395 |
message = _("Variable don't belong to this POU!") |
|
396 |
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
|
397 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 398 |
dialog.ShowModal() |
399 |
dialog.Destroy() |
|
400 |
event.SetDragText("") |
|
401 |
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
|
402 |
|
814 | 403 |
def SetTextSyntax(self, syntax): |
404 |
self.TextSyntax = syntax |
|
405 |
if syntax in ["ST", "ALL"]: |
|
406 |
self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL) |
|
407 |
self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS) |
|
408 |
self.Editor.SetMarginSensitive(2, 1) |
|
409 |
self.Editor.SetMarginWidth(2, 12) |
|
410 |
if syntax == "ST": |
|
411 |
self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS |
|
412 |
self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS |
|
413 |
else: |
|
414 |
self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS |
|
415 |
self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS |
|
416 |
else: |
|
417 |
self.BlockStartKeywords = [] |
|
418 |
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
|
419 |
|
814 | 420 |
def SetKeywords(self, keywords): |
421 |
self.Keywords = [keyword.upper() for keyword in keywords] |
|
422 |
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
|
423 |
|
814 | 424 |
def RefreshJumpList(self): |
1637
6f4624687b89
fix IL jumps highlighting in Text Viewer
Surkov Sergey <surkovsv93@gmail.com>
parents:
1613
diff
changeset
|
425 |
if self.TextSyntax == "IL": |
814 | 426 |
self.Jumps = [jump.upper() for jump in LABEL_MODEL.findall(self.GetText())] |
427 |
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
|
428 |
|
814 | 429 |
# Buffer the last model state |
430 |
def RefreshBuffer(self): |
|
431 |
self.Controler.BufferProject() |
|
432 |
if self.ParentWindow: |
|
433 |
self.ParentWindow.RefreshTitle() |
|
434 |
self.ParentWindow.RefreshFileMenu() |
|
435 |
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
|
436 |
|
814 | 437 |
def StartBuffering(self): |
438 |
self.Controler.StartBuffering() |
|
439 |
if self.ParentWindow: |
|
440 |
self.ParentWindow.RefreshTitle() |
|
441 |
self.ParentWindow.RefreshFileMenu() |
|
442 |
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
|
443 |
|
814 | 444 |
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
|
445 |
if self.CurrentAction is not None: |
814 | 446 |
self.Controler.EndBuffering() |
447 |
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
|
448 |
|
814 | 449 |
def GetBufferState(self): |
450 |
if not self.Debug and self.TextSyntax != "ALL": |
|
451 |
return self.Controler.GetBufferState() |
|
452 |
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
|
453 |
|
814 | 454 |
def Undo(self): |
455 |
if not self.Debug and self.TextSyntax != "ALL": |
|
456 |
self.Controler.LoadPrevious() |
|
457 |
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
|
458 |
|
814 | 459 |
def Redo(self): |
460 |
if not self.Debug and self.TextSyntax != "ALL": |
|
461 |
self.Controler.LoadNext() |
|
462 |
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
|
463 |
|
814 | 464 |
def HasNoModel(self): |
465 |
if not self.Debug and self.TextSyntax != "ALL": |
|
466 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
467 |
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
|
468 |
|
814 | 469 |
def RefreshView(self, variablepanel=True): |
470 |
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
|
471 |
|
814 | 472 |
if self.Controler is not None: |
473 |
self.ResetBuffer() |
|
474 |
self.DisableEvents = True |
|
475 |
old_cursor_pos = self.GetCurrentPos() |
|
1060
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
476 |
line = self.Editor.GetFirstVisibleLine() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
477 |
column = self.Editor.GetXOffset() |
814 | 478 |
old_text = self.GetText() |
479 |
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
|
480 |
if old_text != new_text: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
481 |
self.SetText(new_text) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
self.Editor.GotoPos(new_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
486 |
else: |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
487 |
self.Editor.GotoPos(old_cursor_pos) |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
488 |
self.RefreshJumpList() |
ac9896336b90
Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents:
1057
diff
changeset
|
489 |
self.Editor.EmptyUndoBuffer() |
814 | 490 |
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
|
491 |
|
814 | 492 |
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
|
493 |
|
814 | 494 |
self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)] |
495 |
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
|
496 |
|
814 | 497 |
self.Functions = {} |
498 |
for category in self.Controler.GetBlockTypes(self.TagName, self.Debug): |
|
499 |
for blocktype in category["list"]: |
|
500 |
blockname = blocktype["name"].upper() |
|
501 |
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
|
502 |
interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != '']) |
814 | 503 |
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
|
504 |
if param not in interface: |
814 | 505 |
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
|
506 |
if blockname in self.Functions: |
814 | 507 |
self.Functions[blockname]["interface"].update(interface) |
508 |
self.Functions[blockname]["extensible"] |= blocktype["extensible"] |
|
509 |
else: |
|
510 |
self.Functions[blockname] = {"interface": interface, |
|
511 |
"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
|
512 |
|
814 | 513 |
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
|
514 |
|
814 | 515 |
def RefreshVariableTree(self): |
516 |
words = self.TagName.split("::") |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
517 |
self.Variables = self.GenerateVariableTree( |
1409
48f5f2a622c8
Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents:
1406
diff
changeset
|
518 |
[(variable.Name, variable.Type, variable.Tree) |
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
519 |
for variable in self.Controler.GetEditedElementInterfaceVars( |
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
1308
diff
changeset
|
520 |
self.TagName, True, self.Debug)]) |
814 | 521 |
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
|
522 |
return_type, (var_tree, _var_dimension) = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, True, self.Debug) |
814 | 523 |
if return_type is not None: |
524 |
self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree) |
|
525 |
else: |
|
526 |
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
|
527 |
|
814 | 528 |
def GenerateVariableTree(self, list): |
529 |
tree = {} |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1833
diff
changeset
|
530 |
for var_name, _var_type, (var_tree, _var_dimension) in list: |
814 | 531 |
tree[var_name.upper()] = self.GenerateVariableTree(var_tree) |
532 |
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
|
533 |
|
814 | 534 |
def IsValidVariable(self, name, context): |
535 |
return context is not None and context.get(name, None) is not None |
|
536 |
||
537 |
def IsCallParameter(self, name, call): |
|
538 |
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
|
539 |
return (call["interface"].get(name.upper(), None) is not None or |
814 | 540 |
call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None) |
541 |
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
|
542 |
|
814 | 543 |
def RefreshLineFolding(self, line_number): |
544 |
if self.TextSyntax in ["ST", "ALL"]: |
|
545 |
level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number) |
|
546 |
line = self.Editor.GetLine(line_number).strip() |
|
547 |
if line == "": |
|
548 |
if line_number > 0: |
|
549 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
550 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
551 |
else: |
|
552 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
553 |
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
|
554 |
level |= wx.stc.STC_FOLDLEVELWHITEFLAG |
814 | 555 |
elif LineStartswith(line, self.BlockStartKeywords): |
556 |
level |= wx.stc.STC_FOLDLEVELHEADERFLAG |
|
557 |
elif LineStartswith(line, self.BlockEndKeywords): |
|
558 |
if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords): |
|
559 |
level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
560 |
else: |
|
561 |
level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK |
|
562 |
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
|
563 |
|
814 | 564 |
def OnStyleNeeded(self, event): |
565 |
self.TextChanged = True |
|
566 |
line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled()) |
|
567 |
if line_number == 0: |
|
568 |
start_pos = last_styled_pos = 0 |
|
569 |
else: |
|
570 |
start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1 |
|
571 |
self.RefreshLineFolding(line_number) |
|
572 |
end_pos = event.GetPosition() |
|
573 |
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
|
574 |
|
814 | 575 |
current_context = self.Variables |
576 |
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
|
577 |
|
814 | 578 |
current_pos = last_styled_pos |
579 |
state = SPACE |
|
580 |
line = "" |
|
581 |
word = "" |
|
582 |
while current_pos < end_pos: |
|
583 |
char = chr(self.Editor.GetCharAt(current_pos)).upper() |
|
584 |
line += char |
|
585 |
if char == NEWLINE: |
|
586 |
self.ContextStack = [] |
|
587 |
current_context = self.Variables |
|
588 |
if state == COMMENT: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
589 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_COMMENT) |
814 | 590 |
elif state == NUMBER: |
591 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
592 |
elif state == WORD: |
|
593 |
if word in self.Keywords or word in self.TypeNames: |
|
594 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
595 |
elif self.IsValidVariable(word, current_context): |
|
596 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
597 |
elif self.IsCallParameter(word, current_call): |
|
598 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
599 |
elif word in self.Functions: |
|
600 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
601 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
|
602 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
603 |
elif word in self.EnumeratedValues: |
|
604 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
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 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
608 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
609 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
610 |
self.StartStyling(current_pos, 0xff) |
|
611 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
612 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 613 |
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
|
614 |
if (state != DPRAGMA) and (state != COMMENT): |
1108
1ec5b4d244f3
Fix bug with multiline Pragma syntax highlighting in TextViewer
Laurent Bessard
parents:
1091
diff
changeset
|
615 |
state = SPACE |
814 | 616 |
line = "" |
617 |
line_number += 1 |
|
618 |
self.RefreshLineFolding(line_number) |
|
619 |
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
|
620 |
self.SetStyling(current_pos - last_styled_pos - 1, STC_PLC_EMPTY) |
814 | 621 |
last_styled_pos = current_pos |
622 |
if state == WORD: |
|
623 |
current_context = self.Variables |
|
624 |
state = COMMENT |
|
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 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
|
626 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 627 |
last_styled_pos = current_pos |
628 |
if state == WORD: |
|
629 |
current_context = self.Variables |
|
630 |
state = PRAGMA |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
631 |
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
|
632 |
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
|
633 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
634 |
state = DPRAGMA |
814 | 635 |
elif state == COMMENT: |
636 |
if line.endswith("*)"): |
|
637 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
638 |
last_styled_pos = current_pos + 1 |
|
639 |
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
|
640 |
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
|
641 |
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
|
642 |
else: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1637
diff
changeset
|
643 |
current_call = None |
814 | 644 |
elif state == PRAGMA: |
645 |
if line.endswith("}"): |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
646 |
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
|
647 |
last_styled_pos = current_pos |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
648 |
state = SPACE |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
649 |
elif state == DPRAGMA: |
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
650 |
if line.endswith("}}"): |
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 + 1, STC_PLC_EMPTY) |
814 | 652 |
last_styled_pos = current_pos + 1 |
653 |
state = SPACE |
|
654 |
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
|
655 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 656 |
last_styled_pos = current_pos |
657 |
if state == WORD: |
|
658 |
current_context = self.Variables |
|
659 |
if line.endswith("'"): |
|
660 |
state = STRING |
|
661 |
else: |
|
662 |
state = WSTRING |
|
663 |
elif state == STRING: |
|
664 |
if line.endswith("'") and not line.endswith("$'"): |
|
665 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
666 |
last_styled_pos = current_pos + 1 |
|
667 |
state = SPACE |
|
668 |
elif state == WSTRING: |
|
669 |
if line.endswith('"') and not line.endswith('$"'): |
|
670 |
self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING) |
|
671 |
last_styled_pos = current_pos + 1 |
|
672 |
state = SPACE |
|
673 |
elif char in LETTERS: |
|
674 |
if state == NUMBER: |
|
675 |
word = "#" |
|
676 |
state = WORD |
|
677 |
elif state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
678 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 679 |
word = char |
680 |
last_styled_pos = current_pos |
|
681 |
state = WORD |
|
682 |
else: |
|
683 |
word += char |
|
684 |
elif char in NUMBERS or char == '.' and state != WORD: |
|
685 |
if state == SPACE: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
686 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 687 |
last_styled_pos = current_pos |
688 |
state = NUMBER |
|
689 |
elif state == WORD and char != '.': |
|
690 |
word += char |
|
691 |
elif char == '(' and state == SPACE: |
|
692 |
self.CallStack.append(current_call) |
|
693 |
current_call = None |
|
694 |
else: |
|
695 |
if state == WORD: |
|
696 |
if word in self.Keywords or word in self.TypeNames: |
|
697 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
698 |
elif self.IsValidVariable(word, current_context): |
|
699 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
700 |
elif self.IsCallParameter(word, current_call): |
|
701 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
702 |
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
|
703 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
814 | 704 |
elif self.TextSyntax == "IL" and word in self.Jumps: |
705 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
706 |
elif word in self.EnumeratedValues: |
|
707 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
708 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
709 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 710 |
if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos): |
711 |
self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
|
712 |
self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
|
713 |
self.StartStyling(current_pos, 0xff) |
|
714 |
if char == '.': |
|
715 |
if word != "]": |
|
716 |
if current_context is not None: |
|
717 |
current_context = current_context.get(word, None) |
|
718 |
else: |
|
719 |
current_context = None |
|
720 |
elif char == '(': |
|
721 |
self.CallStack.append(current_call) |
|
722 |
current_call = self.Functions.get(word, None) |
|
723 |
if current_call is None and self.IsValidVariable(word, current_context): |
|
724 |
current_call = {"interface": current_context.get(word, {}), |
|
725 |
"extensible": False} |
|
726 |
current_context = self.Variables |
|
727 |
else: |
|
894
a4919f228924
Fixed bug when indexing table in Pragma within ST/IL code
Laurent Bessard
parents:
871
diff
changeset
|
728 |
if char == '[' and current_context is not None: |
814 | 729 |
self.ContextStack.append(current_context.get(word, None)) |
730 |
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
|
731 |
|
814 | 732 |
word = "" |
733 |
last_styled_pos = current_pos |
|
734 |
state = SPACE |
|
735 |
elif state == NUMBER: |
|
736 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
737 |
last_styled_pos = current_pos |
|
738 |
state = SPACE |
|
739 |
if char == ']': |
|
740 |
if len(self.ContextStack) > 0: |
|
741 |
current_context = self.ContextStack.pop() |
|
742 |
else: |
|
743 |
current_context = self.Variables |
|
744 |
word = char |
|
745 |
state = WORD |
|
746 |
elif char == ')': |
|
747 |
current_context = self.Variables |
|
748 |
if len(self.CallStack) > 0: |
|
749 |
current_call = self.CallStack.pop() |
|
750 |
else: |
|
751 |
current_call = None |
|
752 |
word = char |
|
753 |
state = WORD |
|
754 |
current_pos += 1 |
|
755 |
if state == COMMENT: |
|
756 |
self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
|
757 |
elif state == NUMBER: |
|
758 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
759 |
elif state == WORD: |
|
760 |
if word in self.Keywords or word in self.TypeNames: |
|
761 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
|
762 |
elif self.IsValidVariable(word, current_context): |
|
763 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
|
764 |
elif self.IsCallParameter(word, current_call): |
|
765 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER) |
|
766 |
elif self.TextSyntax == "IL" and word in self.Functions: |
|
767 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
|
768 |
elif word in self.Jumps: |
|
769 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
|
770 |
elif word in self.EnumeratedValues: |
|
771 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
|
772 |
else: |
|
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
773 |
self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY) |
814 | 774 |
else: |
1509
7aaf850d8d1c
fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1504
diff
changeset
|
775 |
self.SetStyling(current_pos - start_pos, STC_PLC_EMPTY) |
814 | 776 |
self.ShowHighlights(start_pos, end_pos) |
777 |
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
|
778 |
|
814 | 779 |
def OnMarginClick(self, event): |
780 |
if event.GetMargin() == 2: |
|
781 |
line = self.Editor.LineFromPosition(event.GetPosition()) |
|
782 |
if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG: |
|
783 |
self.Editor.ToggleFold(line) |
|
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 |
|
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
786 |
def OnUpdateUI(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
787 |
selected = self.Editor.GetSelectedText() |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
788 |
if self.ParentWindow and selected != "": |
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
789 |
self.ParentWindow.SetCopyBuffer(selected, True) |
1126
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
790 |
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
|
791 |
|
814 | 792 |
def Cut(self): |
793 |
self.ResetBuffer() |
|
794 |
self.DisableEvents = True |
|
795 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
|
796 |
self.DisableEvents = False |
|
797 |
self.RefreshModel() |
|
798 |
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
|
799 |
|
814 | 800 |
def Copy(self): |
801 |
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
|
802 |
if self.ParentWindow: |
26baa0ae9fd7
Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents:
1108
diff
changeset
|
803 |
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
|
804 |
|
814 | 805 |
def Paste(self): |
806 |
self.ResetBuffer() |
|
807 |
self.DisableEvents = True |
|
808 |
self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE) |
|
809 |
self.DisableEvents = False |
|
810 |
self.RefreshModel() |
|
811 |
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
|
812 |
|
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
813 |
def Search(self, criteria): |
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
814 |
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
|
815 |
|
814 | 816 |
def Find(self, direction, search_params): |
817 |
if self.SearchParams != search_params: |
|
818 |
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
|
819 |
|
814 | 820 |
self.SearchParams = search_params |
821 |
self.SearchResults = [ |
|
822 |
(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
|
823 |
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
|
824 |
self.Search(search_params)] |
1057
3837e165b3f9
Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents:
980
diff
changeset
|
825 |
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
|
826 |
|
814 | 827 |
if len(self.SearchResults) > 0: |
828 |
if self.CurrentFindHighlight is not None: |
|
829 |
old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
830 |
if self.SearchParams["wrap"]: |
|
831 |
idx = (old_idx + direction) % len(self.SearchResults) |
|
832 |
else: |
|
833 |
idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
834 |
if idx != old_idx: |
|
835 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
836 |
self.CurrentFindHighlight = self.SearchResults[idx] |
|
837 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
838 |
else: |
|
839 |
self.CurrentFindHighlight = self.SearchResults[0] |
|
840 |
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
|
841 |
|
814 | 842 |
else: |
843 |
if self.CurrentFindHighlight is not None: |
|
844 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
845 |
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
|
846 |
|
814 | 847 |
def RefreshModel(self): |
848 |
self.RefreshJumpList() |
|
849 |
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
|
850 |
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
|
851 |
|
814 | 852 |
def OnKeyDown(self, event): |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
853 |
key = event.GetKeyCode() |
814 | 854 |
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
|
855 |
|
814 | 856 |
if self.Editor.CallTipActive(): |
857 |
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
|
858 |
|
814 | 859 |
key_handled = False |
860 |
||
861 |
line = self.Editor.GetCurrentLine() |
|
862 |
if line == 0: |
|
863 |
start_pos = 0 |
|
864 |
else: |
|
865 |
start_pos = self.Editor.GetLineEndPosition(line - 1) + 1 |
|
866 |
end_pos = self.GetCurrentPos() |
|
867 |
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
|
868 |
|
814 | 869 |
# Code completion |
870 |
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
|
871 |
|
814 | 872 |
words = lineText.split(" ") |
873 |
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
|
874 |
|
814 | 875 |
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
|
876 |
|
814 | 877 |
if self.TextSyntax == "IL": |
878 |
if len(words) == 1: |
|
879 |
kw = self.Keywords |
|
880 |
elif len(words) == 2: |
|
881 |
if words[0].upper() in ["CAL", "CALC", "CALNC"]: |
|
882 |
kw = self.Functions |
|
883 |
elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]: |
|
884 |
kw = self.Jumps |
|
885 |
else: |
|
886 |
kw = self.Variables.keys() |
|
887 |
else: |
|
871
1af078aa0cf8
Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents:
858
diff
changeset
|
888 |
kw = self.Keywords + self.Variables.keys() + self.Functions.keys() |
814 | 889 |
if len(kw) > 0: |
890 |
if len(words[-1]) > 0: |
|
891 |
kw = [keyword for keyword in kw if keyword.startswith(words[-1])] |
|
892 |
kw.sort() |
|
893 |
self.Editor.AutoCompSetIgnoreCase(True) |
|
894 |
self.Editor.AutoCompShow(len(words[-1]), " ".join(kw)) |
|
895 |
key_handled = True |
|
896 |
elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: |
|
897 |
if self.TextSyntax in ["ST", "ALL"]: |
|
898 |
indent = self.Editor.GetLineIndentation(line) |
|
899 |
if LineStartswith(lineText.strip(), self.BlockStartKeywords): |
|
900 |
indent = (indent / 2 + 1) * 2 |
|
901 |
self.Editor.AddText("\n" + " " * indent) |
|
902 |
key_handled = True |
|
903 |
elif key == wx.WXK_BACK: |
|
904 |
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
|
905 |
if not self.Editor.GetSelectedText(): |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
906 |
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
|
907 |
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
|
908 |
self.Editor.DelLineLeft() |
41ca586da9dc
fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
909 |
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
|
910 |
key_handled = True |
814 | 911 |
if not key_handled: |
912 |
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
|
913 |
else: |
1262
7b9259945453
Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents:
1178
diff
changeset
|
914 |
event.Skip() |
814 | 915 |
|
916 |
def OnKillFocus(self, event): |
|
917 |
self.Editor.AutoCompCancel() |
|
918 |
event.Skip() |
|
919 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
920 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
921 |
# Highlights showing functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
922 |
# ------------------------------------------------------------------------------- |
814 | 923 |
|
924 |
def OnRefreshHighlightsTimer(self, event): |
|
925 |
self.RefreshView() |
|
926 |
event.Skip() |
|
927 |
||
928 |
def ClearHighlights(self, highlight_type=None): |
|
929 |
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
|
930 |
|
814 | 931 |
if highlight_type is None: |
932 |
self.Highlights = [] |
|
933 |
else: |
|
934 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
|
935 |
if highlight_type is not None: |
|
936 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
937 |
self.RefreshView() |
|
938 |
||
939 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
940 |
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
|
941 |
|
814 | 942 |
highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) |
943 |
if infos[0] == "body" and highlight_type is not None: |
|
944 |
self.Highlights.append((infos[1], start, end, highlight_type)) |
|
945 |
self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1]) |
|
946 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
947 |
||
948 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
949 |
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
|
950 |
|
814 | 951 |
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
|
952 |
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
|
953 |
(infos[1], start, end, highlight_type) in self.Highlights: |
814 | 954 |
self.Highlights.remove((infos[1], start, end, highlight_type)) |
955 |
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
|
956 |
|
814 | 957 |
def ShowHighlights(self, start_pos, end_pos): |
958 |
for indent, start, end, highlight_type in self.Highlights: |
|
959 |
if start[0] == 0: |
|
960 |
highlight_start_pos = start[1] - indent |
|
961 |
else: |
|
962 |
highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 |
|
963 |
if end[0] == 0: |
|
964 |
highlight_end_pos = end[1] - indent + 1 |
|
965 |
else: |
|
966 |
highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 |
|
967 |
if highlight_start_pos < end_pos and highlight_end_pos > start_pos: |
|
968 |
self.StartStyling(highlight_start_pos, 0xff) |
|
969 |
self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) |
|
970 |
self.StartStyling(highlight_start_pos, 0x00) |
|
971 |
self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT) |