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