controls/VariablePanel.py
author Edouard Tisserant
Fri, 28 Feb 2020 16:09:21 +0100
branchsvghmi
changeset 2844 eee5dcd9fc92
parent 2579 8fb5c6eddc72
child 3300 95fe62bfe920
permissions -rw-r--r--
SVGHMI: detachable and discardable elements sets, Reworked geometric intersection, toward more accurate page content detection.

Moved page's widget/element dependency crawling functions so that it is possible to compute a global detachable and discardable elements sets.
Reworked geometric intersection detection logic to distinguish ovelapping and inclusion.
Goal is to include englobing and overlapping graphical elements, but not groups (would then include everything around...). Intermediate commit, to be continued.
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     1
#!/usr/bin/env python
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     2
# -*- coding: utf-8 -*-
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     3
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     6
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     8
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     9
# See COPYING file for copyrights details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    10
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    11
# This program is free software; you can redistribute it and/or
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    12
# modify it under the terms of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    13
# as published by the Free Software Foundation; either version 2
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    14
# of the License, or (at your option) any later version.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    15
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    16
# This program is distributed in the hope that it will be useful,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    19
# GNU General Public License for more details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    20
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    21
# You should have received a copy of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    22
# along with this program; if not, write to the Free Software
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
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
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    26
from __future__ import absolute_import
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
    27
from __future__ import division
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    28
import re
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2432
diff changeset
    29
from builtins import str as text
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    30
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    31
import wx
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    32
import wx.grid
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    33
import wx.lib.buttons
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
    34
from six import string_types
2432
dbc065a2f7a5 python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2301
diff changeset
    35
from six.moves import xrange
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
2574
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
    37
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1951
diff changeset
    39
from plcopen.VariableInfoCollector import _VariableInfos
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    40
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    41
from dialogs.ArrayTypeDialog import ArrayTypeDialog
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    42
from controls.CustomGrid import CustomGrid
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    43
from controls.CustomTable import CustomTable
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    44
from controls.LocationCellEditor import LocationCellEditor
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
from util.BitmapLibrary import GetBitmap
1834
cd42b426028b fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
    46
from util.TranslationCatalogs import NoTranslate
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    47
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    48
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    49
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    50
#                                 Helpers
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    51
# -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
    52
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    53
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
    54
[
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
    55
    TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
    56
    POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    57
] = range(10)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    58
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    59
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    60
def GetVariableTableColnames(location):
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
    61
    _ = NoTranslate
1772
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    62
    cols = ["#",
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    63
            _("Name"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    64
            _("Class"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    65
            _("Type"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    66
            _("Location"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    67
            _("Initial Value"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    68
            _("Option"),
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    69
            _("Documentation")]
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    70
    if not location:
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    71
        del cols[4]  # remove 'Location' column
c3679f96020b clean-up: fix PEP8 W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    72
    return cols
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    73
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    74
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    75
def GetOptions(constant=True, retain=True, non_retain=True):
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
    76
    _ = NoTranslate
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    77
    options = [""]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    78
    if constant:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    79
        options.append(_("Constant"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    80
    if retain:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    81
        options.append(_("Retain"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    82
    if non_retain:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    83
        options.append(_("Non-Retain"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    84
    return options
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    85
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    86
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    87
def GetFilterChoiceTransfer():
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1760
diff changeset
    88
    _ = NoTranslate
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    89
    return {_("All"): _("All"), _("Interface"): _("Interface"),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    90
            _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    91
            _("   External"): _("External"), _("Variables"): _("Variables"), _("   Local"): _("Local"),
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
    92
            _("   Temp"): _("Temp"), _("Global"): _("Global")}  # , _("Access") : _("Access")}
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    93
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    94
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
    95
CheckOptionForClass = {
1774
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
    96
    "Local": lambda x: x,
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
    97
    "Temp": lambda x: "",
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
    98
    "Input": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
    99
    "InOut": lambda x: "",
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   100
    "Output": lambda x: {"Retain": "Retain", "Non-Retain": "Non-Retain"}.get(x, ""),
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   101
    "Global": lambda x: {"Constant": "Constant", "Retain": "Retain"}.get(x, ""),
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
   102
    "External": lambda x: {"Constant": "Constant"}.get(x, "")
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1772
diff changeset
   103
}
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   104
2439
f0a040f1de1b Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2437
diff changeset
   105
LOCATION_MODEL = re.compile(r"((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$")
f0a040f1de1b Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2437
diff changeset
   106
LOCATION_MODEL_SET = re.compile(r"((?:%[IQM](?:[XBWLD]?[0-9]+(?:\.[0-9]+)*))?)$")
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   107
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   108
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   109
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   110
#                            Variables Panel Table
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   111
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   112
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   113
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   114
class VariableTable(CustomTable):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   115
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   116
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   117
    A custom wx.grid.Grid Table using user supplied data
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   118
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   119
    def __init__(self, parent, data, colnames):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   120
        # The base class must be initialized *first*
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   121
        CustomTable.__init__(self, parent, data, colnames)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   122
        self.old_value = None
2301
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   123
        self.OPTIONS_DICT = dict([(_(option), option)
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   124
                                  for option in GetOptions()])
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   125
        self.VARIABLE_CLASSES_DICT = dict([(_(_class), _class)
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   126
                                           for _class in GetFilterChoiceTransfer().itervalues()])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   127
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   128
    def GetValueByName(self, row, colname):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   129
        if row < self.GetNumberRows():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   130
            return getattr(self.data[row], colname)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   131
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   132
    def SetValueByName(self, row, colname, value):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   133
        if row < self.GetNumberRows():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   134
            setattr(self.data[row], colname, value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   135
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   136
    def GetValue(self, row, col):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   137
        if row < self.GetNumberRows():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   138
            if col == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   139
                return self.data[row].Number
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   140
            colname = self.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   141
            if colname == "Initial Value":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   142
                colname = "InitialValue"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   143
            value = getattr(self.data[row], colname, "")
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
   144
            if colname == "Type" and isinstance(value, tuple):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   145
                if value[0] == "array":
1833
2269739dd098 fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   146
                    return "ARRAY [%s] OF %s" % (",".join(map("..".join, value[2])), value[1])
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
   147
            if not isinstance(value, string_types):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   148
                value = str(value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   149
            if colname in ["Class", "Option"]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   150
                return _(value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   151
            return value
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   152
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   153
    def SetValue(self, row, col, value):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   154
        if col < len(self.colnames):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   155
            colname = self.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   156
            if colname == "Name":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   157
                self.old_value = getattr(self.data[row], colname)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   158
            elif colname == "Class":
2301
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   159
                value = self.VARIABLE_CLASSES_DICT[value]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   160
                self.SetValueByName(row, "Option", CheckOptionForClass[value](self.GetValueByName(row, "Option")))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   161
                if value == "External":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   162
                    self.SetValueByName(row, "InitialValue", "")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   163
            elif colname == "Option":
2301
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   164
                value = self.OPTIONS_DICT[value]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   165
            elif colname == "Initial Value":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   166
                colname = "InitialValue"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   167
            setattr(self.data[row], colname, value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   168
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   169
    def GetOldValue(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   170
        return self.old_value
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   171
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   172
    def _GetRowEdit(self, row):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   173
        row_edit = self.GetValueByName(row, "Edit")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   174
        var_type = self.Parent.GetTagName()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   175
        bodytype = self.Parent.Controler.GetEditedElementBodyType(var_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   176
        if bodytype in ["ST", "IL"]:
1752
d14ff9d7eb76 clean-up: fix PEP8 E703 statement ends with a semicolon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   177
            row_edit = True
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   178
        return row_edit
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   179
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   180
    def _updateColAttrs(self, grid):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   181
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   182
        wx.grid.Grid -> update the column attributes to add the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   183
        appropriate renderer given the column name.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   184
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   185
        Otherwise default to the default renderer.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   186
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   187
        for row in range(self.GetNumberRows()):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   188
            var_class = self.GetValueByName(row, "Class")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   189
            var_type = self.GetValueByName(row, "Type")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   190
            row_highlights = self.Highlights.get(row, {})
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   191
            for col in range(self.GetNumberCols()):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   192
                editor = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   193
                renderer = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   194
                colname = self.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   195
                if self.Parent.Debug:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   196
                    grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   197
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   198
                    if colname == "Option":
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   199
                        options = GetOptions(constant=var_class in ["Local", "External", "Global"],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   200
                                             retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   201
                                             non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   202
                        if len(options) > 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   203
                            editor = wx.grid.GridCellChoiceEditor()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   204
                            editor.SetParameters(",".join(map(_, options)))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   205
                        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   206
                            grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   207
                    elif col != 0 and self._GetRowEdit(row):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   208
                        grid.SetReadOnly(row, col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   209
                        if colname == "Name":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   210
                            editor = wx.grid.GridCellTextEditor()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   211
                            renderer = wx.grid.GridCellStringRenderer()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   212
                        elif colname == "Initial Value":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   213
                            if var_class not in ["External", "InOut"]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   214
                                if self.Parent.Controler.IsEnumeratedType(var_type):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   215
                                    editor = wx.grid.GridCellChoiceEditor()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   216
                                    editor.SetParameters(",".join([""] + self.Parent.Controler.GetEnumeratedDataValues(var_type)))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   217
                                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   218
                                    editor = wx.grid.GridCellTextEditor()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   219
                                renderer = wx.grid.GridCellStringRenderer()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   220
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   221
                                grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   222
                        elif colname == "Location":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   223
                            if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   224
                                editor = LocationCellEditor(self, self.Parent.Controler)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   225
                                renderer = wx.grid.GridCellStringRenderer()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   226
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   227
                                grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   228
                        elif colname == "Class":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   229
                            if len(self.Parent.ClassList) == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   230
                                grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   231
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   232
                                editor = wx.grid.GridCellChoiceEditor()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   233
                                excluded = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   234
                                if self.Parent.IsFunctionBlockType(var_type):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   235
                                    excluded.extend(["Local", "Temp"])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   236
                                editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   237
                    elif colname != "Documentation":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   238
                        grid.SetReadOnly(row, col, True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   239
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   240
                grid.SetCellEditor(row, col, editor)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   241
                grid.SetCellRenderer(row, col, renderer)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   242
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   243
                if colname == "Location" and LOCATION_MODEL.match(self.GetValueByName(row, colname)) is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   244
                    highlight_colours = ERROR_HIGHLIGHT
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   245
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   246
                    highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   247
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   248
                grid.SetCellTextColour(row, col, highlight_colours[1])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   249
            self.ResizeRow(grid, row)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   250
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   251
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   252
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   253
#                         Variable Panel Drop Target
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   254
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   255
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   256
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   257
class VariableDropTarget(wx.TextDropTarget):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   258
    '''
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   259
    This allows dragging a variable location from somewhere to the Location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   260
    column of a variable row.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   261
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   262
    The drag source should be a TextDataObject containing a Python tuple like:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   263
        ('%ID0.0.0', 'location', 'REAL')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   264
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   265
    c_ext/CFileEditor.py has an example of this (you can drag a C extension
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   266
    variable to the Location column of the variable panel).
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   267
    '''
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   268
    def __init__(self, parent):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   269
        wx.TextDropTarget.__init__(self)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   270
        self.ParentWindow = parent
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   271
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   272
    def OnDropText(self, x, y, data):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   273
        self.ParentWindow.ParentWindow.Select()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   274
        x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   275
        col = self.ParentWindow.VariablesGrid.XToCol(x)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   276
        row = self.ParentWindow.VariablesGrid.YToRow(y)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   277
        message = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   278
        element_type = self.ParentWindow.ElementType
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   279
        try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   280
            values = eval(data)
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1776
diff changeset
   281
        except Exception:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   282
            message = _("Invalid value \"%s\" for variable grid element") % data
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   283
            values = None
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
   284
        if not isinstance(values, tuple):
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   285
            message = _("Invalid value \"%s\" for variable grid element") % data
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   286
            values = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   287
        if values is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   288
            if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   289
                colname = self.ParentWindow.Table.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   290
                if colname == "Location" and values[1] == "location":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   291
                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   292
                        message = _("Can't give a location to a function block instance")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   293
                    elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   294
                        message = _("Can only give a location to local or global variables")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   295
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   296
                        location = values[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   297
                        variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   298
                        base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   299
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   300
                        if values[2] is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   301
                            base_location_type = self.ParentWindow.Controler.GetBaseType(values[2])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   302
                            if values[2] != variable_type and base_type != base_location_type:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   303
                                message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   304
                                          format(a1=values[2], a2=variable_type)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   305
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   306
                        if message is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   307
                            if not location.startswith("%"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   308
                                if location[0].isdigit() and base_type != "BOOL":
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   309
                                    message = _("Incompatible size of data between \"%s\" and \"BOOL\"") % location
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   310
                                elif location[0] not in LOCATIONDATATYPES:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   311
                                    message = _("Unrecognized data size \"%s\"") % location[0]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   312
                                elif base_type not in LOCATIONDATATYPES[location[0]]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   313
                                    message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   314
                                              format(a1=location, a2=variable_type)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   315
                                else:
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   316
                                    dialog = wx.SingleChoiceDialog(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   317
                                        self.ParentWindow.ParentWindow.ParentWindow,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   318
                                        _("Select a variable class:"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   319
                                        _("Variable class"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   320
                                        [_("Input"), _("Output"), _("Memory")],
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   321
                                        wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   322
                                    if dialog.ShowModal() == wx.ID_OK:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   323
                                        selected = dialog.GetSelection()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   324
                                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   325
                                        selected = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   326
                                    dialog.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   327
                                    if selected is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   328
                                        return
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   329
                                    if selected == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   330
                                        location = "%I" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   331
                                    elif selected == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   332
                                        location = "%Q" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   333
                                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   334
                                        location = "%M" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   335
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   336
                            if message is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   337
                                self.ParentWindow.Table.SetValue(row, col, location)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   338
                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   339
                                self.ParentWindow.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   340
                elif colname == "Initial Value" and values[1] == "Constant":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   341
                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   342
                        message = _("Can't set an initial value to a function block instance")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   343
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   344
                        self.ParentWindow.Table.SetValue(row, col, values[0])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   345
                        self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   346
                        self.ParentWindow.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   347
            elif (element_type not in ["config", "resource", "function"] and values[1] == "Global" and
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   348
                  self.ParentWindow.Filter in ["All", "Interface", "External"] or
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   349
                  element_type != "function" and values[1] in ["location", "NamedConstant"]):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   350
                if values[1] in ["location", "NamedConstant"]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   351
                    var_name = values[3]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   352
                else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   353
                    var_name = values[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   354
                tagname = self.ParentWindow.GetTagName()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   355
                dlg = wx.TextEntryDialog(
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   356
                    self.ParentWindow.ParentWindow.ParentWindow,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   357
                    _("Confirm or change variable name"),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   358
                    _('Variable Drop'), var_name)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   359
                dlg.SetValue(var_name)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   360
                var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   361
                dlg.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   362
                if var_name is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   363
                    return
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   364
                elif var_name.upper() in [
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   365
                        name.upper() for name in
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   366
                        self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   367
                    message = _("\"%s\" pou already exists!") % var_name
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   368
                elif not var_name.upper() in [
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   369
                        name.upper()
1764
d5df428640ff clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   370
                        for name in self.ParentWindow.Controler.
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   371
                        GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   372
                    var_infos = self.ParentWindow.DefaultValue.copy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   373
                    var_infos.Name = var_name
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   374
                    var_infos.Type = values[2]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   375
                    var_infos.Documentation = values[4]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   376
                    if values[1] == "location":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   377
                        location = values[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   378
                        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: 1767
diff changeset
   379
                            dialog = wx.SingleChoiceDialog(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   380
                                self.ParentWindow.ParentWindow.ParentWindow,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   381
                                _("Select a variable class:"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   382
                                _("Variable class"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   383
                                [_("Input"), _("Output"), _("Memory")],
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   384
                                wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   385
                            if dialog.ShowModal() == wx.ID_OK:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   386
                                selected = dialog.GetSelection()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   387
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   388
                                selected = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   389
                            dialog.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   390
                            if selected is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   391
                                return
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   392
                            if selected == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   393
                                location = "%I" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   394
                            elif selected == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   395
                                location = "%Q" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   396
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   397
                                location = "%M" + location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   398
                        if element_type == "functionBlock":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   399
                            configs = self.ParentWindow.Controler.GetProjectConfigNames(
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   400
                                self.ParentWindow.Debug)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   401
                            if len(configs) == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   402
                                return
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   403
                            if not var_name.upper() in [
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   404
                                    name.upper() for name in
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   405
                                    self.ParentWindow.Controler.GetConfigurationVariableNames(configs[0])]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   406
                                self.ParentWindow.Controler.AddConfigurationGlobalVar(
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   407
                                    configs[0], values[2], var_name, location, "")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   408
                            var_infos.Class = "External"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   409
                        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   410
                            if element_type == "program":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   411
                                var_infos.Class = "Local"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   412
                            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   413
                                var_infos.Class = "Global"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   414
                            var_infos.Location = location
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   415
                    elif values[1] == "NamedConstant":
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   416
                        if element_type in ["functionBlock", "program"]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   417
                            var_infos.Class = "Local"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   418
                            var_infos.InitialValue = values[0]
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   419
                        else:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   420
                            return
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   421
                    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   422
                        var_infos.Class = "External"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   423
                    var_infos.Number = len(self.ParentWindow.Values)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   424
                    self.ParentWindow.Values.append(var_infos)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   425
                    self.ParentWindow.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   426
                    self.ParentWindow.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   427
                else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   428
                    message = _("\"%s\" element for this pou already exists!") % var_name
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   429
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   430
        if message is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   431
            wx.CallAfter(self.ShowMessage, message)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   432
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   433
    def ShowMessage(self, message):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   434
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK | wx.ICON_ERROR)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   435
        message.ShowModal()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   436
        message.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   437
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   438
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   439
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   440
#                               Variable Panel
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   441
# -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   442
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   443
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   444
class VariablePanel(wx.Panel):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   445
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   446
    def __init__(self, parent, window, controler, element_type, debug=False):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   447
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   448
2301
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   449
        self.VARIABLE_CHOICES_DICT = dict([(_(_class), _class) for
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   450
                                           _class in GetFilterChoiceTransfer().iterkeys()])
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   451
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   452
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   453
        self.MainSizer.AddGrowableCol(0)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   454
        self.MainSizer.AddGrowableRow(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   455
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   456
        controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   457
        controls_sizer.AddGrowableCol(5)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   458
        controls_sizer.AddGrowableRow(0)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   459
        self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW | wx.ALL)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   460
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   461
        self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   462
        controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   463
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   464
        self.ReturnType = wx.ComboBox(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   465
                                      size=wx.Size(145, -1), style=wx.CB_READONLY)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   466
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   467
        controls_sizer.AddWindow(self.ReturnType)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   468
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   469
        self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   470
        controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   471
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   472
        self.Description = wx.TextCtrl(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   473
                                       size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   474
        self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   475
        self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   476
        controls_sizer.AddWindow(self.Description)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   477
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   478
        class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   479
        controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   480
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   481
        self.ClassFilter = wx.ComboBox(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   482
                                       size=wx.Size(145, -1), style=wx.CB_READONLY)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   483
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   484
        controls_sizer.AddWindow(self.ClassFilter)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   485
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   486
        for name, bitmap, help in [
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   487
                ("AddButton", "add_element", _("Add variable")),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   488
                ("DeleteButton", "remove_element", _("Remove variable")),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   489
                ("UpButton", "up", _("Move variable up")),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   490
                ("DownButton", "down", _("Move variable down"))]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   491
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap),
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   492
                                                    size=wx.Size(28, 28), style=wx.NO_BORDER)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   493
            button.SetToolTipString(help)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   494
            setattr(self, name, button)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   495
            controls_sizer.AddWindow(button)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   496
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   497
        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   498
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   499
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   500
                                self.OnVariablesGridCellChange)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   501
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   502
                                self.OnVariablesGridCellLeftClick)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   503
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   504
                                self.OnVariablesGridEditorShown)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   505
        self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   506
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   507
        self.SetSizer(self.MainSizer)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   508
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   509
        self.ParentWindow = window
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   510
        self.Controler = controler
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   511
        self.ElementType = element_type
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   512
        self.Debug = debug
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   513
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   514
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   515
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   516
                  self.RefreshHighlightsTimer)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   517
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   518
        self.Filter = "All"
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   519
        self.FilterChoices = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   520
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   521
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   522
        self.DefaultValue = _VariableInfos("LocalVar0", "", "", "", "", True, "", DefaultType, ([], []), 0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   523
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   524
        if element_type in ["config", "resource"]:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   525
            self.DefaultTypes = {"All": "Global"}
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   526
        else:
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   527
            self.DefaultTypes = {"All": "Local", "Interface": "Input", "Variables": "Local"}
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   528
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   529
        if element_type in ["config", "resource"] \
1776
81aa8aaccdd4 clean-up: fix PEP8 E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
   530
           or element_type in ["program", "transition", "action"]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   531
            # this is an element that can have located variables
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   532
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   533
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   534
            if element_type in ["config", "resource"]:
1760
ed2e2afb9573 clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   535
                self.FilterChoices = ["All", "Global"]  # ,"Access"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   536
            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   537
                self.FilterChoices = ["All",
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   538
                                      "Interface", "   Input", "   Output", "   InOut", "   External",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   539
                                      "Variables", "   Local", "   Temp"]  # ,"Access"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   540
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   541
            # these condense the ColAlignements list
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   542
            left = wx.ALIGN_LEFT
1755
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   543
            center = wx.ALIGN_CENTER
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   544
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   545
            #                        Num     Name    Class   Type    Loc     Init    Option   Doc
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   546
            self.ColSettings = {
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   547
                "size":             [40,     80,     100,    80,     110,    120,    100,     160],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   548
                "alignement":       [center, left,   left,   left,   left,   left,   left,    left],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   549
                "fixed_size":       [True,   False,  True,   False,  True,   True,   True,    False],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   550
            }
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   551
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   552
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   553
            # this is an element that cannot have located variables
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   554
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   555
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   556
            if element_type == "function":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   557
                self.FilterChoices = ["All",
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   558
                                      "Interface", "   Input", "   Output", "   InOut",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   559
                                      "Variables", "   Local"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   560
            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   561
                self.FilterChoices = ["All",
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   562
                                      "Interface", "   Input", "   Output", "   InOut", "   External",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   563
                                      "Variables", "   Local", "   Temp"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   564
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   565
            # these condense the alignements list
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   566
            left = wx.ALIGN_LEFT
1755
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   567
            center = wx.ALIGN_CENTER
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   568
624b9694cb0d clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   569
            #                        Num     Name    Class   Type    Init    Option   Doc
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   570
            self.ColSettings = {
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   571
                "size":             [40,     80,     100,    80,     120,    100,     160],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   572
                "alignement":       [center, left,   left,   left,   left,   left,    left],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   573
                "fixed_size":       [True,   False,  True,   False,  True,   True,    False],
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   574
            }
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   575
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   576
        self.PanelWidthMin = sum(self.ColSettings["size"])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   577
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   578
        self.ElementType = element_type
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   579
        self.BodyType = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   580
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   581
        for choice in self.FilterChoices:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   582
            self.ClassFilter.Append(_(choice))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   583
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   584
        reverse_transfer = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   585
        for filter, choice in self.FilterChoiceTransfer.items():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   586
            reverse_transfer[choice] = filter
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   587
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   588
        self.RefreshTypeList()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   589
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   590
        self.VariablesGrid.SetTable(self.Table)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   591
        self.VariablesGrid.SetButtons({"Add": self.AddButton,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   592
                                       "Delete": self.DeleteButton,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   593
                                       "Up": self.UpButton,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   594
                                       "Down": self.DownButton})
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   595
        self.VariablesGrid.SetEditable(not self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   596
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   597
        def _AddVariable(new_row):
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   598
            row_content = self.DefaultValue.copy()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   599
            if new_row > 0:
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   600
                # doesn't copy values of previous var if it's non-editable (like a FB)
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   601
                if self.Values[new_row-1].Edit:
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   602
                    row_content = self.Values[new_row-1].copy()
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   603
                old_name = self.Values[new_row-1].Name
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   604
                row_content.Name = self.Controler.GenerateNewName(
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   605
                    self.TagName, old_name, old_name+'%d')
2240
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   606
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   607
                # increment location address
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   608
                if row_content.Location != "" and LOCATION_MODEL_SET.match(row_content.Location):
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   609
                    old_location = row_content.Location
2439
f0a040f1de1b Fix pep8 warning: W605 invalid escape sequence ?x?
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2437
diff changeset
   610
                    model = re.compile(r"%[IQM][XBWLD]?(.*\.|)")
2240
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   611
                    prefix = model.match(old_location).group(0)
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   612
                    addr = int(re.split(model, old_location)[-1]) + 1
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2432
diff changeset
   613
                    row_content.Location = prefix + text(addr)
2240
e684aed23407 Automatically increment IEC-location address if copy of the variable is created
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1973
diff changeset
   614
1969
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   615
            if not row_content.Class:
0607c382d73f remove duplicating code for variables name generate
Surkov Sergey <surkovsv93@gmail.com>
parents: 1878
diff changeset
   616
                row_content.Class = self.DefaultTypes.get(self.Filter, self.Filter)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   617
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   618
            if self.Filter == "All" and len(self.Values) > 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   619
                self.Values.insert(new_row, row_content)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   620
            else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   621
                self.Values.append(row_content)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   622
                new_row = self.Table.GetNumberRows()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   623
            self.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   624
            if self.ElementType == "resource":
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   625
                self.ParentWindow.RefreshView(variablepanel=False)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   626
            self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   627
            return new_row
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   628
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   629
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   630
        def _DeleteVariable(row):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   631
            if _GetRowEdit(row):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   632
                self.Values.remove(self.Table.GetRow(row))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   633
                self.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   634
                if self.ElementType == "resource":
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   635
                    self.ParentWindow.RefreshView(variablepanel=False)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   636
                self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   637
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   638
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   639
        def _MoveVariable(row, move):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   640
            if self.Filter == "All":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   641
                new_row = max(0, min(row + move, len(self.Values) - 1))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   642
                if new_row != row:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   643
                    self.Values.insert(new_row, self.Values.pop(row))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   644
                    self.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   645
                    self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   646
                return new_row
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   647
            return row
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   648
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   649
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   650
        def _GetRowEdit(row):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   651
            row_edit = False
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   652
            if self:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   653
                row_edit = self.Table.GetValueByName(row, "Edit")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   654
                bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   655
                row_edit = row_edit or (bodytype in ["ST", "IL"])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   656
            return row_edit
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   657
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   658
        def _RefreshButtons():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   659
            if self:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   660
                table_length = len(self.Table.data)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   661
                row_edit = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   662
                row = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   663
                if table_length > 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   664
                    row = self.VariablesGrid.GetGridCursorRow()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   665
                    row_edit = _GetRowEdit(row)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   666
                self.AddButton.Enable(not self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   667
                self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   668
                self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   669
                self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   670
        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   671
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   672
        panel_width = window.Parent.ScreenRect.Width - 35
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   673
        if panel_width > self.PanelWidthMin:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   674
            stretch_cols_width = panel_width
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   675
            stretch_cols_sum = 0
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   676
            for col in range(len(self.ColSettings["fixed_size"])):
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   677
                if self.ColSettings["fixed_size"][col]:
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   678
                    stretch_cols_width -= self.ColSettings["size"][col]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   679
                else:
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   680
                    stretch_cols_sum += self.ColSettings["size"][col]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   681
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   682
        self.VariablesGrid.SetRowLabelSize(0)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   683
        for col in range(self.Table.GetNumberCols()):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   684
            attr = wx.grid.GridCellAttr()
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   685
            attr.SetAlignment(self.ColSettings["alignement"][col], wx.ALIGN_CENTRE)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   686
            self.VariablesGrid.SetColAttr(col, attr)
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   687
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSettings["size"][col])
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   688
            if (panel_width > self.PanelWidthMin) and not self.ColSettings["fixed_size"][col]:
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   689
                self.VariablesGrid.SetColSize(col, int((self.ColSettings["size"][col]/stretch_cols_sum)*stretch_cols_width))
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   690
            else:
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   691
                self.VariablesGrid.SetColSize(col, self.ColSettings["size"][col])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   692
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   693
    def __del__(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   694
        self.RefreshHighlightsTimer.Stop()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   695
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   696
    def SetTagName(self, tagname):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   697
        self.TagName = tagname
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   698
        self.BodyType = self.Controler.GetEditedElementBodyType(self.TagName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   699
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   700
    def GetTagName(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   701
        return self.TagName
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   702
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   703
    def IsFunctionBlockType(self, name):
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
   704
        if isinstance(name, tuple) or \
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1764
diff changeset
   705
           self.ElementType != "function" and self.BodyType in ["ST", "IL"]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   706
            return False
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   707
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   708
            return self.Controler.GetBlockType(name, debug=self.Debug) is not None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   709
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   710
    def RefreshView(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   711
        self.PouNames = self.Controler.GetProjectPouNames(self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   712
        returnType = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   713
        description = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   714
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   715
        words = self.TagName.split("::")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   716
        if self.ElementType == "config":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   717
            self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   718
        elif self.ElementType == "resource":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   719
            self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   720
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   721
            if self.ElementType == "function":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   722
                self.ReturnType.Clear()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   723
                for data_type in self.Controler.GetDataTypes(self.TagName, debug=self.Debug):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   724
                    self.ReturnType.Append(data_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   725
                returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, debug=self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   726
            description = self.Controler.GetPouDescription(words[1])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   727
            self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   728
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   729
        if returnType is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   730
            self.ReturnType.SetStringSelection(returnType)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   731
            self.ReturnType.Enable(not self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   732
            self.ReturnTypeLabel.Show()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   733
            self.ReturnType.Show()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   734
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   735
            self.ReturnType.Enable(False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   736
            self.ReturnTypeLabel.Hide()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   737
            self.ReturnType.Hide()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   738
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   739
        if description is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   740
            self.Description.SetValue(description)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   741
            self.Description.Enable(not self.Debug)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   742
            self.DescriptionLabel.Show()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   743
            self.Description.Show()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   744
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   745
            self.Description.Enable(False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   746
            self.DescriptionLabel.Hide()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   747
            self.Description.Hide()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   748
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   749
        self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   750
        self.VariablesGrid.RefreshButtons()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   751
        self.MainSizer.Layout()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   752
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   753
    def OnReturnTypeChanged(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   754
        words = self.TagName.split("::")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   755
        self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   756
        self.Controler.BufferProject()
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   757
        self.ParentWindow.RefreshView(variablepanel=False)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   758
        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   759
        event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   760
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   761
    def OnDescriptionChanged(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   762
        words = self.TagName.split("::")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   763
        old_description = self.Controler.GetPouDescription(words[1])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   764
        new_description = self.Description.GetValue()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   765
        if new_description != old_description:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   766
            self.Controler.SetPouDescription(words[1], new_description)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   767
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   768
        event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   769
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   770
    def OnClassFilter(self, event):
2301
5b8a7dd43f9f Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2240
diff changeset
   771
        self.Filter = self.FilterChoiceTransfer[self.VARIABLE_CHOICES_DICT[self.ClassFilter.GetStringSelection()]]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   772
        self.RefreshTypeList()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   773
        self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   774
        self.VariablesGrid.RefreshButtons()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   775
        event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   776
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   777
    def RefreshTypeList(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   778
        if self.Filter == "All":
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   779
            self.ClassList = [self.FilterChoiceTransfer[choice] for choice in self.FilterChoices if self.FilterChoiceTransfer[choice] not in ["All", "Interface", "Variables"]]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   780
        elif self.Filter == "Interface":
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   781
            self.ClassList = ["Input", "Output", "InOut", "External"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   782
        elif self.Filter == "Variables":
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   783
            self.ClassList = ["Local", "Temp"]
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   784
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   785
            self.ClassList = [self.Filter]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   786
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   787
    def ShowErrorMessage(self, message):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   788
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   789
        dialog.ShowModal()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   790
        dialog.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   791
2573
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   792
    def OnVariableNameChange(self, old_name, new_name):
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   793
        """ propagate renaming of variable to the rest of the project """
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   794
        if old_name != "":
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   795
            self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_name, new_name)
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   796
        self.Controler.BufferProject()
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   797
        wx.CallAfter(self.ParentWindow.RefreshView, False)
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   798
        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   799
2574
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   800
    def CheckVariableName(self, value, row):
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   801
        if not TestIdentifier(value):
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   802
            message = _("\"%s\" is not a valid identifier!") % value
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   803
        elif value.upper() in IEC_KEYWORDS:
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   804
            message = _("\"%s\" is a keyword. It can't be used!") % value
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   805
        elif value.upper() in self.PouNames:
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   806
            message = _("A POU named \"%s\" already exists!") % value
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   807
        elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]:
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   808
            message = _("A variable with \"%s\" as name already exists in this pou!") % value
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   809
        else:
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   810
            return None
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   811
        return message
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   812
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   813
    def OnVariablesGridCellChange(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   814
        row, col = event.GetRow(), event.GetCol()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   815
        colname = self.Table.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   816
        value = self.Table.GetValue(row, col)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   817
        message = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   818
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   819
        if colname == "Name" and value != "":
2574
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   820
            message = self.CheckVariableName(value, row)
48a486000e84 LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
Edouard Tisserant
parents: 2573
diff changeset
   821
            if message is None:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   822
                self.SaveValues(False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   823
                old_value = self.Table.GetOldValue()
2573
071d10c7ab8f LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
Edouard Tisserant
parents: 2554
diff changeset
   824
                self.OnVariableNameChange(old_value, value)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   825
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   826
            self.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   827
            if colname == "Class":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   828
                self.ClearLocation(row, col, value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   829
                wx.CallAfter(self.ParentWindow.RefreshView)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   830
            elif colname == "Location":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   831
                wx.CallAfter(self.ParentWindow.RefreshView)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   832
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   833
        if message is not None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   834
            wx.CallAfter(self.ShowErrorMessage, message)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   835
            event.Veto()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   836
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   837
            event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   838
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   839
    def ClearLocation(self, row, col, value):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   840
        if self.Values[row].Location != '':
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   841
            if self.Table.GetColLabelValue(col, False) == 'Class' and value not in ["Local", "Global"] or \
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   842
               self.Table.GetColLabelValue(col, False) == 'Type' and not self.Controler.IsLocatableType(value):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   843
                self.Values[row].Location = ''
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   844
                self.RefreshValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   845
                self.SaveValues()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   846
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   847
    def BuildStdIECTypesMenu(self, type_menu):
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   848
        # build a submenu containing standard IEC types
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   849
        base_menu = wx.Menu(title='')
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   850
        for base_type in self.Controler.GetBaseTypes():
2554
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   851
            item = base_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=base_type)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   852
            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), item)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   853
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   854
        type_menu.AppendMenu(wx.ID_ANY, _("Base Types"), base_menu)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   855
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   856
    def BuildUserTypesMenu(self, type_menu):
1838
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   857
        # build a submenu containing user-defined types
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   858
        datatype_menu = wx.Menu(title='')
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   859
        datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False)
646245c1c0d9 fix pylint warning (bad-indentation) Bad indentation. Found X spaces, expected Y
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1834
diff changeset
   860
        for datatype in datatypes:
2554
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   861
            item = datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   862
            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   863
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   864
        type_menu.AppendMenu(wx.ID_ANY, _("User Data Types"), datatype_menu)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   865
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   866
    def BuildLibsTypesMenu(self, type_menu):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   867
        for category in self.Controler.GetConfNodeDataTypes():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   868
            if len(category["list"]) > 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   869
                # build a submenu containing confnode types
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   870
                confnode_datatype_menu = wx.Menu(title='')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   871
                for datatype in category["list"]:
2554
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   872
                    item = confnode_datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   873
                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   874
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   875
                type_menu.AppendMenu(wx.ID_ANY, category["name"], confnode_datatype_menu)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   876
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   877
    def BuildProjectTypesMenu(self, type_menu, classtype):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   878
        # build a submenu containing function block types
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   879
        bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   880
        _pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   881
        if classtype in ["Input", "Output", "InOut", "External", "Global"] or \
1776
81aa8aaccdd4 clean-up: fix PEP8 E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1774
diff changeset
   882
           poutype != "function" and bodytype in ["ST", "IL"]:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   883
            functionblock_menu = wx.Menu(title='')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   884
            fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   885
            for functionblock_type in fbtypes:
2554
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   886
                item = functionblock_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=functionblock_type)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   887
                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), item)
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   888
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   889
            type_menu.AppendMenu(wx.ID_ANY, _("Function Block Types"), functionblock_menu)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   890
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   891
    def BuildArrayTypesMenu(self, type_menu):
2554
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   892
        item = type_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=_("Array"))
45d4f9a84c60 VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
Edouard Tisserant
parents: 2450
diff changeset
   893
        self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, item)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   894
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   895
    def OnVariablesGridEditorShown(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   896
        row, col = event.GetRow(), event.GetCol()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   897
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   898
        label_value = self.Table.GetColLabelValue(col, False)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   899
        if label_value == "Type":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   900
            old_value = self.Values[row].Type
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   901
            classtype = self.Table.GetValueByName(row, "Class")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   902
            type_menu = wx.Menu(title='')   # the root menu
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   903
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   904
            self.BuildStdIECTypesMenu(type_menu)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   905
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   906
            self.BuildUserTypesMenu(type_menu)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   907
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   908
            self.BuildLibsTypesMenu(type_menu)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   909
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   910
            self.BuildProjectTypesMenu(type_menu, classtype)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   911
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   912
            self.BuildArrayTypesMenu(type_menu)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   913
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   914
            rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   915
            corner_x = rect.x + rect.width
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   916
            corner_y = rect.y + self.VariablesGrid.GetColLabelSize()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   917
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   918
            # pop up this new menu
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   919
            self.VariablesGrid.PopupMenuXY(type_menu, corner_x, corner_y)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   920
            type_menu.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   921
            event.Veto()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   922
            value = self.Values[row].Type
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   923
            if old_value != value:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   924
                self.ClearLocation(row, col, value)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   925
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   926
            event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   927
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   928
    def GetVariableTypeFunction(self, base_type):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   929
        def VariableTypeFunction(event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   930
            row = self.VariablesGrid.GetGridCursorRow()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   931
            self.Table.SetValueByName(row, "Type", base_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   932
            self.Table.ResetView(self.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   933
            self.SaveValues(False)
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   934
            self.ParentWindow.RefreshView(variablepanel=False)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   935
            self.Controler.BufferProject()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   936
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   937
        return VariableTypeFunction
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   938
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   939
    def VariableArrayTypeFunction(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   940
        row = self.VariablesGrid.GetGridCursorRow()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   941
        dialog = ArrayTypeDialog(self,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   942
                                 self.Controler.GetDataTypes(self.TagName),
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   943
                                 self.Table.GetValueByName(row, "Type"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   944
        if dialog.ShowModal() == wx.ID_OK:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   945
            self.Table.SetValueByName(row, "Type", dialog.GetValue())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   946
            self.Table.ResetView(self.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   947
            self.SaveValues(False)
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   948
            self.ParentWindow.RefreshView(variablepanel=False)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   949
            self.Controler.BufferProject()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   950
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   951
        dialog.Destroy()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   952
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   953
    def OnVariablesGridCellLeftClick(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   954
        row = event.GetRow()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   955
        if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   956
            var_name = self.Table.GetValueByName(row, "Name")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   957
            var_class = self.Table.GetValueByName(row, "Class")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   958
            var_type = self.Table.GetValueByName(row, "Type")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   959
            data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   960
            dragSource = wx.DropSource(self.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   961
            dragSource.SetData(data)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   962
            dragSource.DoDragDrop()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   963
        event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   964
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   965
    def RefreshValues(self):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   966
        data = []
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   967
        for num, variable in enumerate(self.Values):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   968
            if variable.Class in self.ClassList:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   969
                variable.Number = num + 1
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   970
                data.append(variable)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   971
        self.Table.SetData(data)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   972
        self.Table.ResetView(self.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   973
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   974
    def SaveValues(self, buffer=True):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   975
        words = self.TagName.split("::")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   976
        if self.ElementType == "config":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   977
            self.Controler.SetConfigurationGlobalVars(words[1], self.Values)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   978
        elif self.ElementType == "resource":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   979
            self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   980
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   981
            if self.ReturnType.IsEnabled():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   982
                self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   983
            self.Controler.SetPouInterfaceVars(words[1], self.Values)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   984
        if buffer:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   985
            self.Controler.BufferProject()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   986
            self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   987
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   988
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   989
    #                        Highlights showing functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   990
    # -------------------------------------------------------------------------------
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   991
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   992
    def OnRefreshHighlightsTimer(self, event):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   993
        self.Table.ResetView(self.VariablesGrid)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   994
        event.Skip()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   995
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   996
    def AddVariableHighlight(self, infos, highlight_type):
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
   997
        if isinstance(infos[0], tuple):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   998
            for i in xrange(*infos[0]):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   999
                self.Table.AddHighlight((i,) + infos[1:], highlight_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1000
            cell_visible = infos[0][0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1001
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1002
            self.Table.AddHighlight(infos, highlight_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1003
            cell_visible = infos[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1004
        colnames = [colname.lower() for colname in self.Table.colnames]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1005
        self.VariablesGrid.MakeCellVisible(cell_visible, colnames.index(infos[1]))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1006
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1007
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1008
    def RemoveVariableHighlight(self, infos, highlight_type):
2450
5024c19ca8f0 python3 support: pylint, W1652 # (deprecated-types-field) Accessing a deprecated fields on the types module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2439
diff changeset
  1009
        if isinstance(infos[0], tuple):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1010
            for i in xrange(*infos[0]):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1011
                self.Table.RemoveHighlight((i,) + infos[1:], highlight_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1012
        else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1013
            self.Table.RemoveHighlight(infos, highlight_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1014
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1015
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1016
    def ClearHighlights(self, highlight_type=None):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1017
        self.Table.ClearHighlights(highlight_type)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
  1018
        self.Table.ResetView(self.VariablesGrid)