editors/TextViewer.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 26 Apr 2024 09:24:26 +0200
changeset 3938 fc4af5685aa3
parent 3795 223a91584172
permissions -rw-r--r--
merge
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    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
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import re
2456
7373e3048167 python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2450
diff changeset
    27
from functools import reduce
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx.stc
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
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
    33
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
    34
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
    35
from controls.CustomStyledTextCtrl import CustomStyledTextCtrl, faces, GetCursorPos
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    37
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
#                         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
    39
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
NEWLINE = "\n"
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
    43
NUMBERS = [str(i) for i in range(10)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
LETTERS = ['_']
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
    45
for i in range(26):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
    LETTERS.append(chr(ord('a') + i))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
    LETTERS.append(chr(ord('A') + i))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
    49
[STC_PLC_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
    50
 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
    51
 STC_PLC_ERROR, STC_PLC_SEARCH_RESULT,
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
    52
 STC_PLC_EMPTY] = list(range(11))
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
    53
[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA, DPRAGMA] = list(range(8))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
re_texts = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
re_texts["letter"] = "[A-Za-z]"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
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
    58
re_texts["identifier"] = "((?:%(letter)s|(?:_(?:%(letter)s|%(digit)s)))(?:_?(?:%(letter)s|%(digit)s))*)" % re_texts
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
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
    60
LABEL_MODEL = re.compile("[ \t\n]%(identifier)s:[ \t\n]" % re_texts)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
EXTENSIBLE_PARAMETER = re.compile("IN[1-9][0-9]*$")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
HIGHLIGHT_TYPES = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
    ERROR_HIGHLIGHT: STC_PLC_ERROR,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    SEARCH_RESULT_HIGHLIGHT: STC_PLC_SEARCH_RESULT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    68
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
def LineStartswith(line, symbols):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
    70
    return reduce(lambda x, y: x or y, list(map(line.startswith, symbols)), False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    72
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
class TextViewer(EditorPanel):
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
    74
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    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
    76
        self.Editor = CustomStyledTextCtrl(parent=prnt, name="TextViewer", size=wx.Size(0, 0), style=0)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        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
    78
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        self.Editor.CmdKeyAssign(ord('+'), wx.stc.STC_SCMOD_CTRL, wx.stc.STC_CMD_ZOOMIN)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        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
    81
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        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
    83
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        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
    85
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        # Global default styles for all languages
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        self.Editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "face:%(mono)s,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        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
    89
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        self.Editor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        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
    92
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        # Highlighting styles
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.Editor.StyleSetSpec(STC_PLC_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        self.Editor.StyleSetSpec(STC_PLC_VARIABLE, "fore:#7F0000,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.Editor.StyleSetSpec(STC_PLC_PARAMETER, "fore:#7F007F,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        self.Editor.StyleSetSpec(STC_PLC_FUNCTION, "fore:#7F7F00,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        self.Editor.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        self.Editor.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        self.Editor.StyleSetSpec(STC_PLC_STRING, "fore:#007F00,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        self.Editor.StyleSetSpec(STC_PLC_JUMP, "fore:#FF7FFF,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        self.Editor.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        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
   104
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        # Indicators styles
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        self.Editor.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        if self.ParentWindow is not None and self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
            self.Editor.IndicatorSetForeground(0, wx.RED)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
            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
   111
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
        # Line numbers in the margin
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
        self.Editor.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        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
   115
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        # Folding
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN,    wx.stc.STC_MARK_BOXMINUS,          "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER,        wx.stc.STC_MARK_BOXPLUS,           "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB,     wx.stc.STC_MARK_VLINE,             "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL,    wx.stc.STC_MARK_LCORNER,           "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND,     wx.stc.STC_MARK_BOXPLUSCONNECTED,  "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
        self.Editor.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID, wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        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
   124
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
        # Indentation size
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        self.Editor.SetTabWidth(2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
        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
   128
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   129
        self.Editor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT |
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   130
                                    wx.stc.STC_MOD_BEFOREDELETE)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
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
   132
        self.Bind(wx.stc.EVT_STC_STYLENEEDED, self.OnStyleNeeded, self.Editor)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
        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
   134
        self.Editor.Bind(wx.stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
        self.Editor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
            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
   138
            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
   139
            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
   140
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   141
    def __init__(self, parent, tagname, window, controler, debug=False, instancepath=""):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        if tagname != "" and controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
            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
   144
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
        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
   146
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
        self.Keywords = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
        self.Variables = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
        self.Functions = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        self.TypeNames = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.Jumps = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        self.EnumeratedValues = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.DisableEvents = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
        self.TextSyntax = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        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
   156
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.InstancePath = instancepath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        self.ContextStack = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        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
   160
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   161
        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
   162
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
        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
   165
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
    def GetTitle(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        if self.Debug or self.TagName == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
            if len(self.InstancePath) > 15:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
                return "..." + self.InstancePath[-12:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            return self.InstancePath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        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
   172
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
    def GetInstancePath(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
        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
   175
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
    def IsViewing(self, tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
        if self.Debug or self.TagName == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
            return self.InstancePath == tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
            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
   181
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
    def GetText(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
        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
   184
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
    def SetText(self, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        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
   187
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
    def SelectAll(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
        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
   190
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
    def Colourise(self, start, end):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
        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
   193
3795
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3791
diff changeset
   194
    def StartStyling(self, *a, **k):
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3791
diff changeset
   195
        self.Editor.StartStyling(*a, **k)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   196
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   197
    INDIC0 = 0
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   198
    INDIC1 = 1
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   199
    INDIC2 = 2
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
    def SetStyling(self, length, style):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
        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
   203
3429
67a4d207bace IDE: Fix one more sequel of wxPython4 port : typo in editors/TextViewer.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3327
diff changeset
   204
    def SetIndicatorCurrentFillRange(self, start, length, indic):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   205
        self.Editor.SetIndicatorCurrent(indic)
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   206
        self.Editor.IndicatorFillRange(start, length)
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   207
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
    def GetCurrentPos(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
        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
   210
1178
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   211
    def ResetSearchResults(self):
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   212
        self.Highlights = []
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   213
        self.SearchParams = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   214
        self.SearchResults = None
3e2aebc9c7c0 Fixed search highlight bug in ST and Code text editors
Laurent Bessard
parents: 1126
diff changeset
   215
        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
   216
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   217
    Buffering = "Off"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
    def OnModification(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        if not self.DisableEvents:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
            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
   221
            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
   222
                if self.CurrentAction is None:
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   223
                    self.Buffering = "ShouldStart"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
                elif self.CurrentAction[0] != "Add" or self.CurrentAction[1] != event.GetPosition() - 1:
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   225
                    self.Buffering = "ShouldRestart"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
                self.CurrentAction = ("Add", event.GetPosition())
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   227
                self.RefreshModelAfter()
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   228
            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
   229
                if self.CurrentAction is None:
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   230
                    self.Buffering = "ShouldStart"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
                elif self.CurrentAction[0] != "Delete" or self.CurrentAction[1] != event.GetPosition() + 1:
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   232
                    self.Buffering = "ShouldRestart"
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
                self.CurrentAction = ("Delete", event.GetPosition())
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   234
                self.RefreshModelAfter()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
    def OnDoDrop(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            values = event.GetDragText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
        if isinstance(values, tuple):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
            if values[1] in ["program", "debug"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
                event.SetDragText("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            elif values[1] in ["functionBlock", "function"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
                blocktype = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
                blockname = values[2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
                if len(values) > 3:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                    blockinputs = values[3]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                            blockname = dialog.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                        self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                        self.RefreshVariablePanel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                        self.RefreshVariableTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
                blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
                if values[1] == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
                    event.SetDragText(blocktype+"(\n    "+hint+")")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
                    event.SetDragText(blockname+"(\n    "+hint+")")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
                if len(values) > 2 and pou_type == "program":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                        location = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                                selected = dialog.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                                selected = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                            if selected is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
                                event.SetDragText("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
                                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                            if selected == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                                location = "%I" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                            elif selected == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                                location = "%Q" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                                location = "%M" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                        if values[2] is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                            var_type = values[2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
                        self.RefreshVariablePanel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                        self.RefreshVariableTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                        event.SetDragText(var_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
            elif values[1] == "Global":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
                        self.RefreshVariablePanel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
                        self.RefreshVariableTree()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
                    event.SetDragText(var_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
            elif values[1] == "Constant":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
                event.SetDragText(values[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
            elif values[3] == self.TagName:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
                self.ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
                event.SetDragText(values[0])
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   382
                self.RefreshModelAfter()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
                message = _("Variable don't belong to this POU!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
                dialog.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
                dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
                event.SetDragText("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
    def SetTextSyntax(self, syntax):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
        self.TextSyntax = syntax
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        if syntax in ["ST", "ALL"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
            self.Editor.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
            self.Editor.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
            self.Editor.SetMarginSensitive(2, 1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
            self.Editor.SetMarginWidth(2, 12)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
            if syntax == "ST":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
                self.BlockStartKeywords = ST_BLOCK_START_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
                self.BlockEndKeywords = ST_BLOCK_START_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
                self.BlockStartKeywords = IEC_BLOCK_START_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
                self.BlockEndKeywords = IEC_BLOCK_START_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
            self.BlockStartKeywords = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
    def SetKeywords(self, keywords):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
        self.Keywords = [keyword.upper() for keyword in keywords]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
    # Buffer the last model state
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
    def RefreshBuffer(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
        self.Controler.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
        if self.ParentWindow:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
            self.ParentWindow.RefreshTitle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
            self.ParentWindow.RefreshFileMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
    def StartBuffering(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
        self.Controler.StartBuffering()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
        if self.ParentWindow:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
            self.ParentWindow.RefreshTitle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
            self.ParentWindow.RefreshFileMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   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
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   432
    def EndBuffering(self):
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   433
        self.Controler.EndBuffering()
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   434
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
    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
   436
        if self.CurrentAction is not None:
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   437
            self.EndBuffering()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
            self.CurrentAction = None
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   439
            self.Buffering == "Off"
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   440
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
    def GetBufferState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
        if not self.Debug and self.TextSyntax != "ALL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
            return self.Controler.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
        return False, False
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   445
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
    def Undo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
        if not self.Debug and self.TextSyntax != "ALL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
            self.Controler.LoadPrevious()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
            self.ParentWindow.CloseTabsWithoutModel()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   450
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
    def Redo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
        if not self.Debug and self.TextSyntax != "ALL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
            self.Controler.LoadNext()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
            self.ParentWindow.CloseTabsWithoutModel()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   455
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
    def HasNoModel(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
        if not self.Debug and self.TextSyntax != "ALL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
            return self.Controler.GetEditedElement(self.TagName) is None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
        return False
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   460
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
    def RefreshView(self, variablepanel=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
        EditorPanel.RefreshView(self, variablepanel)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   463
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
        if self.Controler is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
            self.ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
            self.DisableEvents = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
            old_cursor_pos = self.GetCurrentPos()
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   468
            line = self.Editor.GetFirstVisibleLine()
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   469
            column = self.Editor.GetXOffset()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
            old_text = self.GetText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
            new_text = self.Controler.GetEditedElementText(self.TagName, self.Debug)
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   472
            if old_text != new_text:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   473
                self.SetText(new_text)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   474
                new_cursor_pos = GetCursorPos(old_text, new_text)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   475
                self.Editor.LineScroll(column, line)
1743
c3c3d1318130 clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   476
                if new_cursor_pos is not None:
1060
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   477
                    self.Editor.GotoPos(new_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   478
                else:
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   479
                    self.Editor.GotoPos(old_cursor_pos)
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   480
                self.RefreshJumpList()
ac9896336b90 Fixed unexpected scrolling when PythonEditor, TextViewer and CFileEditor get focus
Laurent Bessard
parents: 1057
diff changeset
   481
                self.Editor.EmptyUndoBuffer()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
            self.DisableEvents = False
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   483
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
            self.RefreshVariableTree()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   485
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
            self.TypeNames = [typename.upper() for typename in self.Controler.GetDataTypes(self.TagName, True, self.Debug)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
            self.EnumeratedValues = [value.upper() for value in self.Controler.GetEnumeratedDataValues()]
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   488
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
            self.Functions = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
            for category in self.Controler.GetBlockTypes(self.TagName, self.Debug):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
                for blocktype in category["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
                    blockname = blocktype["name"].upper()
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
   493
                    if blocktype["type"] == "function" and blockname not in self.Keywords and blockname not in list(self.Variables.keys()):
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
   494
                        interface = dict([(name, {}) for name, _type, _modifier in blocktype["inputs"] + blocktype["outputs"] if name != ''])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
                        for param in ["EN", "ENO"]:
1775
b45f2768fab1 clean-up: fix PEP8 E713 test for membership should be 'not in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   496
                            if param not in interface:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
                                interface[param] = {}
1763
bcc07ff2362c clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   498
                        if blockname in self.Functions:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
                            self.Functions[blockname]["interface"].update(interface)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
                            self.Functions[blockname]["extensible"] |= blocktype["extensible"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
                            self.Functions[blockname] = {"interface": interface,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
                                                         "extensible": blocktype["extensible"]}
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   504
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
        self.Colourise(0, -1)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   506
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
    def RefreshVariableTree(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
        words = self.TagName.split("::")
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   509
        self.Variables = self.GenerateVariableTree([
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   510
            (variable.Name, variable.Type, variable.Tree)
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   511
            for variable in
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   512
            self.Controler.GetEditedElementInterfaceVars(
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   513
                self.TagName, True, self.Debug)
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   514
        ])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
        if self.Controler.GetEditedElementType(self.TagName, self.Debug)[1] == "function" or words[0] == "T" and self.TextSyntax == "IL":
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
   516
            return_type, (var_tree, _var_dimension) = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, True, self.Debug)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
            if return_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
                self.Variables[words[-1].upper()] = self.GenerateVariableTree(var_tree)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
                self.Variables[words[-1].upper()] = {}
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   521
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
    def GenerateVariableTree(self, list):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
        tree = {}
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
   524
        for var_name, _var_type, (var_tree, _var_dimension) in list:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
            tree[var_name.upper()] = self.GenerateVariableTree(var_tree)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
        return tree
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   527
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
    def IsValidVariable(self, name, context):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
        return context is not None and context.get(name, None) is not None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
    def IsCallParameter(self, name, call):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        if call is not None:
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   533
            return (call["interface"].get(name.upper(), None) is not None or
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
                    call["extensible"] and EXTENSIBLE_PARAMETER.match(name.upper()) is not None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
        return False
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   536
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
    def RefreshLineFolding(self, line_number):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
        if self.TextSyntax in ["ST", "ALL"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
            level = wx.stc.STC_FOLDLEVELBASE + self.Editor.GetLineIndentation(line_number)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
            line = self.Editor.GetLine(line_number).strip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
            if line == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
                if line_number > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
                    if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
                        level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
                        level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
                if level != wx.stc.STC_FOLDLEVELBASE:
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1747
diff changeset
   548
                    level |= wx.stc.STC_FOLDLEVELWHITEFLAG
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
            elif LineStartswith(line, self.BlockStartKeywords):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
                level |= wx.stc.STC_FOLDLEVELHEADERFLAG
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
            elif LineStartswith(line, self.BlockEndKeywords):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
                if LineStartswith(self.Editor.GetLine(line_number - 1).strip(), self.BlockEndKeywords):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
                    level = self.Editor.GetFoldLevel(self.Editor.GetFoldParent(line_number - 1)) & wx.stc.STC_FOLDLEVELNUMBERMASK
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
                    level = self.Editor.GetFoldLevel(line_number - 1) & wx.stc.STC_FOLDLEVELNUMBERMASK
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
            self.Editor.SetFoldLevel(line_number, level)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   557
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
    def OnStyleNeeded(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
        self.TextChanged = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
        line_number = self.Editor.LineFromPosition(self.Editor.GetEndStyled())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        if line_number == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
            start_pos = last_styled_pos = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
            start_pos = last_styled_pos = self.Editor.GetLineEndPosition(line_number - 1) + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
        self.RefreshLineFolding(line_number)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
        end_pos = event.GetPosition()
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   567
        self.StartStyling(start_pos)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   568
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
        current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
        current_call = None
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   571
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
        current_pos = last_styled_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
        state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
        line = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
        word = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
        while current_pos < end_pos:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
            char = chr(self.Editor.GetCharAt(current_pos)).upper()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
            line += char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
            if char == NEWLINE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
                self.ContextStack = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
                current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
                if state == COMMENT:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   583
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_COMMENT)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
                elif state == NUMBER:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
                elif state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
                    if word in self.Keywords or word in self.TypeNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
                    elif self.IsValidVariable(word, current_context):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
                    elif self.IsCallParameter(word, current_call):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
                    elif word in self.Functions:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
                    elif self.TextSyntax == "IL" and word in self.Jumps:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
                    elif word in self.EnumeratedValues:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
                    else:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   600
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
                        if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   602
                            self.SetIndicatorCurrentFillRange(last_styled_pos, current_pos - last_styled_pos, self.INDIC0)
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   603
                            self.StartStyling(current_pos)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
                else:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   605
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
                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
   607
                if (state != DPRAGMA) and (state != COMMENT):
1108
1ec5b4d244f3 Fix bug with multiline Pragma syntax highlighting in TextViewer
Laurent Bessard
parents: 1091
diff changeset
   608
                    state = SPACE
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
                line = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
                line_number += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
                self.RefreshLineFolding(line_number)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
            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
   613
                self.SetStyling(current_pos - last_styled_pos - 1, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
                last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
                if state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
                    current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
                state = COMMENT
871
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   618
            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
   619
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
                last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
                if state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
                    current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
                state = PRAGMA
871
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   624
            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
   625
                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
   626
                last_styled_pos = current_pos
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   627
                state = DPRAGMA
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
            elif state == COMMENT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
                if line.endswith("*)"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
                    self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
                    last_styled_pos = current_pos + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
                    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
   633
                    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
   634
                        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
   635
                    else:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1637
diff changeset
   636
                        current_call = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
            elif state == PRAGMA:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
                if line.endswith("}"):
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   639
                    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
   640
                    last_styled_pos = current_pos
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   641
                    state = SPACE
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   642
            elif state == DPRAGMA:
1af078aa0cf8 Add support for double bracket pragma in syntax highlighting of TextViewer
Laurent Bessard
parents: 858
diff changeset
   643
                if line.endswith("}}"):
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   644
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
                    last_styled_pos = current_pos + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
                    state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
            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
   648
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
                last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
                if state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
                    current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
                if line.endswith("'"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
                    state = STRING
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
                    state = WSTRING
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
            elif state == STRING:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
                if line.endswith("'") and not line.endswith("$'"):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
                    last_styled_pos = current_pos + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
                    state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
            elif state == WSTRING:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
                if line.endswith('"') and not line.endswith('$"'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
                    self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_STRING)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
                    last_styled_pos = current_pos + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
                    state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
            elif char in LETTERS:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
                if state == NUMBER:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
                    word = "#"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
                    state = WORD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
                elif state == SPACE:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   671
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
                    word = char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
                    last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
                    state = WORD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
                    word += char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
            elif char in NUMBERS or char == '.' and state != WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
                if state == SPACE:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   679
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
                    last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
                    state = NUMBER
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
                elif state == WORD and char != '.':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
                    word += char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
            elif char == '(' and state == SPACE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
                self.CallStack.append(current_call)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
                current_call = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
                if state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
                    if word in self.Keywords or word in self.TypeNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
                    elif self.IsValidVariable(word, current_context):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
                    elif self.IsCallParameter(word, current_call):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
                    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
   696
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
                    elif self.TextSyntax == "IL" and word in self.Jumps:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
                    elif word in self.EnumeratedValues:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
                    else:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   702
                        self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
                        if word not in ["]", ")"] and (self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos):
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   704
                            self.SetIndicatorCurrentFillRange(last_styled_pos, current_pos - last_styled_pos, self.INDIC0)
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   705
                            self.StartStyling(current_pos)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
                    if char == '.':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
                        if word != "]":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
                            if current_context is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
                                current_context = current_context.get(word, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
                                current_context = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
                    elif char == '(':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
                        self.CallStack.append(current_call)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
                        current_call = self.Functions.get(word, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
                        if current_call is None and self.IsValidVariable(word, current_context):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
                            current_call = {"interface": current_context.get(word, {}),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
                                            "extensible": False}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
                        current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
                    else:
894
a4919f228924 Fixed bug when indexing table in Pragma within ST/IL code
Laurent Bessard
parents: 871
diff changeset
   720
                        if char == '[' and current_context is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
                            self.ContextStack.append(current_context.get(word, None))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
                        current_context = self.Variables
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   723
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
                    word = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
                    last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
                    state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
                elif state == NUMBER:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
                    self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
                    last_styled_pos = current_pos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
                    state = SPACE
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
                if char == ']':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
                    if len(self.ContextStack) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
                        current_context = self.ContextStack.pop()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
                        current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
                    word = char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
                    state = WORD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
                elif char == ')':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
                    current_context = self.Variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
                    if len(self.CallStack) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
                        current_call = self.CallStack.pop()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
                        current_call = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
                    word = char
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
                    state = WORD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
            current_pos += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
        if state == COMMENT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
            self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
        elif state == NUMBER:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
            self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
        elif state == WORD:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
            if word in self.Keywords or word in self.TypeNames:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
            elif self.IsValidVariable(word, current_context):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
            elif self.IsCallParameter(word, current_call):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_PARAMETER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
            elif self.TextSyntax == "IL" and word in self.Functions:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
            elif word in self.Jumps:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
            elif word in self.EnumeratedValues:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
            else:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   765
                self.SetStyling(current_pos - last_styled_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
        else:
1509
7aaf850d8d1c fix highlighting of multiline comments in ST and IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1504
diff changeset
   767
            self.SetStyling(current_pos - start_pos, STC_PLC_EMPTY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
        self.ShowHighlights(start_pos, end_pos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
        event.Skip()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   770
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
    def OnMarginClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
        if event.GetMargin() == 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
            line = self.Editor.LineFromPosition(event.GetPosition())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
            if self.Editor.GetFoldLevel(line) & wx.stc.STC_FOLDLEVELHEADERFLAG:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
                self.Editor.ToggleFold(line)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
        event.Skip()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   777
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1108
diff changeset
   778
    def OnUpdateUI(self, event):
1262
7b9259945453 Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents: 1178
diff changeset
   779
        selected = self.Editor.GetSelectedText()
7b9259945453 Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents: 1178
diff changeset
   780
        if self.ParentWindow and selected != "":
7b9259945453 Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents: 1178
diff changeset
   781
            self.ParentWindow.SetCopyBuffer(selected, True)
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1108
diff changeset
   782
        event.Skip()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   783
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
    def Cut(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
        self.ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
        self.DisableEvents = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_CUT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
        self.DisableEvents = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
        self.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
        self.RefreshBuffer()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   791
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
    def Copy(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_COPY)
1126
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1108
diff changeset
   794
        if self.ParentWindow:
26baa0ae9fd7 Fixed bug with Copy/Paste in Primary Selection in Text Viewers
Laurent Bessard
parents: 1108
diff changeset
   795
            self.ParentWindow.RefreshEditMenu()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   796
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   797
    def Paste(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
        self.ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
        self.DisableEvents = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
        self.Editor.CmdKeyExecute(wx.stc.STC_CMD_PASTE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
        self.DisableEvents = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
        self.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
        self.RefreshBuffer()
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   804
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 980
diff changeset
   805
    def Search(self, criteria):
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 980
diff changeset
   806
        return self.Controler.SearchInPou(self.TagName, criteria, self.Debug)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   807
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   808
    def Find(self, direction, search_params):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
        if self.SearchParams != search_params:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
            self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   811
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
            self.SearchParams = search_params
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
            self.SearchResults = [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
                (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
   815
                for infos, start, end, _text in
1556
32e9d0ef30dc fix major bugs in Find and Search in Project functionality.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1548
diff changeset
   816
                self.Search(search_params)]
1057
3837e165b3f9 Added support for search in PythonEditor and IECCodeViewer
Laurent Bessard
parents: 980
diff changeset
   817
            self.CurrentFindHighlight = None
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   818
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
        if len(self.SearchResults) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
            if self.CurrentFindHighlight is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
                old_idx = self.SearchResults.index(self.CurrentFindHighlight)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
                if self.SearchParams["wrap"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
                    idx = (old_idx + direction) % len(self.SearchResults)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
                    idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
                if idx != old_idx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
                    self.RemoveHighlight(*self.CurrentFindHighlight)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
                    self.CurrentFindHighlight = self.SearchResults[idx]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
                    self.AddHighlight(*self.CurrentFindHighlight)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
                self.CurrentFindHighlight = self.SearchResults[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
                self.AddHighlight(*self.CurrentFindHighlight)
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   833
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
            if self.CurrentFindHighlight is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
                self.RemoveHighlight(*self.CurrentFindHighlight)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
            self.CurrentFindHighlight = None
1409
48f5f2a622c8 Added 'NamedConstant' drag'n'drop in text programs as well (was only accepted on graphical languages).
Edouard Tisserant
parents: 1406
diff changeset
   838
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   839
    pending_model_refresh=False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
    def RefreshModel(self):
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   841
        self.pending_model_refresh=False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
        self.RefreshJumpList()
1904
7dd49b65208b Textviewer : moved call to Colourise in a better place, so that ST highlighting gets also updated when typing in some case, not only IL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1878
diff changeset
   843
        self.Colourise(0, -1)
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   844
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   845
        if self.Buffering == "ShouldStart":
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   846
            self.StartBuffering()
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   847
            self.Buffering == "On"
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   848
        elif self.Buffering == "ShouldRestart":
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   849
            self.EndBuffering()
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   850
            self.StartBuffering()
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   851
            self.Buffering == "On"
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   852
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
        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
   854
        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
   855
3682
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   856
    def RefreshModelAfter(self):
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   857
        if self.pending_model_refresh:
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   858
            return
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   859
        self.pending_model_refresh=True
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   860
        wx.CallAfter(self.RefreshModel)
c613afdab571 IDE: Optimization of modification events processing in text editors.
Edouard Tisserant
parents: 3319
diff changeset
   861
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
    def OnKeyDown(self, event):
1262
7b9259945453 Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents: 1178
diff changeset
   863
        key = event.GetKeyCode()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
        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
   865
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
            if self.Editor.CallTipActive():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   867
                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
   868
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
            key_handled = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   870
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
            line = self.Editor.GetCurrentLine()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
            if line == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
                start_pos = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
                start_pos = self.Editor.GetLineEndPosition(line - 1) + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
            end_pos = self.GetCurrentPos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
            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
   878
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   879
            # Code completion
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
            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
   881
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
                words = lineText.split(" ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   883
                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
   884
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
                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
   886
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
                if self.TextSyntax == "IL":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   888
                    if len(words) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   889
                        kw = self.Keywords
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   890
                    elif len(words) == 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   891
                        if words[0].upper() in ["CAL", "CALC", "CALNC"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
                            kw = self.Functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   893
                        elif words[0].upper() in ["JMP", "JMPC", "JMPNC"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
                            kw = self.Jumps
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   895
                        else:
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
   896
                            kw = list(self.Variables.keys())
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
   897
                else:
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3688
diff changeset
   898
                    kw = self.Keywords + list(self.Variables.keys()) + list(self.Functions.keys())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
                if len(kw) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
                    if len(words[-1]) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
                        kw = [keyword for keyword in kw if keyword.startswith(words[-1])]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
                    kw.sort()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
                    self.Editor.AutoCompSetIgnoreCase(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
                    self.Editor.AutoCompShow(len(words[-1]), " ".join(kw))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
                key_handled = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
            elif key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
                if self.TextSyntax in ["ST", "ALL"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   908
                    indent = self.Editor.GetLineIndentation(line)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   909
                    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
   910
                        indent = (indent // 2 + 1) * 2
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
                    self.Editor.AddText("\n" + " " * indent)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
                    key_handled = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   913
            elif key == wx.WXK_BACK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   914
                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
   915
                    if not self.Editor.GetSelectedText():
41ca586da9dc fix strange behavior on Backspace press in ST
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1578
diff changeset
   916
                        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
   917
                        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
   918
                            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
   919
                            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
   920
                            key_handled = True
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
            if not key_handled:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
                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
   923
        else:
1262
7b9259945453 Fixed bug with Copy/Paste in generated ST code Viewer
Laurent Bessard
parents: 1178
diff changeset
   924
            event.Skip()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   925
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   926
    def OnKillFocus(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   927
        self.Editor.AutoCompCancel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   928
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   930
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   931
    #                        Highlights showing functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   932
    # -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
    def OnRefreshHighlightsTimer(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   936
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   938
    def ClearHighlights(self, highlight_type=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   939
        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
   940
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
        if highlight_type is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
            self.Highlights = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   943
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
            highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   945
            if highlight_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   946
                self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   947
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   948
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   949
    def AddHighlight(self, infos, start, end, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   950
        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
   951
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   952
        highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   953
        if infos[0] == "body" and highlight_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   954
            self.Highlights.append((infos[1], start, end, highlight_type))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   955
            self.Editor.GotoPos(self.Editor.PositionFromLine(start[0]) + start[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   956
            self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
    def RemoveHighlight(self, infos, start, end, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
        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
   960
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   961
        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
   962
        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
   963
           (infos[1], start, end, highlight_type) in self.Highlights:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
            self.Highlights.remove((infos[1], start, end, highlight_type))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
            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
   966
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
    def ShowHighlights(self, start_pos, end_pos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
        for indent, start, end, highlight_type in self.Highlights:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   969
            if start[0] == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
                highlight_start_pos = start[1] - indent
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
                highlight_start_pos = self.Editor.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
            if end[0] == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
                highlight_end_pos = end[1] - indent + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
                highlight_end_pos = self.Editor.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
            if highlight_start_pos < end_pos and highlight_end_pos > start_pos:
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2737
diff changeset
   978
                self.StartStyling(highlight_start_pos)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
                self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
3795
223a91584172 IDE: more fixes for wxPython 4.0.7 and pyhon 3.10
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3791
diff changeset
   980
                self.StartStyling(highlight_end_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
   981
                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
   982
                self.SetStyling(until_end, wx.stc.STC_STYLE_DEFAULT)