editors/DataTypeEditor.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 05 Oct 2017 16:38:49 +0300
changeset 1847 6198190bc121
parent 1833 2269739dd098
child 1853 47a3f39bead0
permissions -rw-r--r--
explicitly mark unused variables found by pylint with _ or dummy

pylint don't ignores unused variables with '_' in the name, even when
they are started with '_'. This bug is already fixed upstream, to fix
this in all versions of pylint custom dummy-variables-rgx is used
'_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy'
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    10
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    15
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    20
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import re
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    27
from types import TupleType
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
import wx.grid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx.lib.buttons
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    32
from plcopen.structures import IEC_KEYWORDS, TestIdentifier, DefaultType
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    34
from controls import CustomEditableListBox, CustomGrid, CustomTable, CustomIntCtrl
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    35
from dialogs import ArrayTypeDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
from EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
from util.BitmapLibrary import GetBitmap
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
    38
from util.TranslationCatalogs import NoTranslate
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    40
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
#                                    Helpers
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    42
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    46
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    50
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
def GetElementsTableColnames():
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
    52
    _ = NoTranslate
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
    return ["#", _("Name"), _("Type"), _("Initial Value")]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    55
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
def GetDatatypeTypes():
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
    57
    _ = NoTranslate
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    return [_("Directly"), _("Subrange"), _("Enumerated"), _("Array"), _("Structure")]
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
    59
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
    60
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    61
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
#                            Structure Elements Table
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    63
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    65
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
class ElementsTable(CustomTable):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    67
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
    """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
    A custom wx.grid.Grid Table using user supplied data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
    """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
    def __init__(self, parent, data, colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        # The base class must be initialized *first*
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        CustomTable.__init__(self, parent, data, colnames)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        self.old_value = None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    75
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    def GetValue(self, row, col):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        if row < self.GetNumberRows():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
            if col == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
                return row + 1
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    80
            colname = self.GetColLabelValue(col, False)
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    81
            value = self.data[row].get(colname, "")
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    82
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    83
            if colname == "Type" and isinstance(value, TupleType):
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
    84
                if value[0] == "array":
1833
2269739dd098 fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1821
diff changeset
    85
                    return "ARRAY [%s] OF %s" % (",".join(map("..".join, value[2])), value[1])
1508
4c645e6b8c98 fix error if non-latin character was entered in initial value in
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1412
diff changeset
    86
            return value
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    87
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
    def SetValue(self, row, col, value):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        if col < len(self.colnames):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
            colname = self.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
            if colname == "Name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
                self.old_value = self.data[row][colname]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
            self.data[row][colname] = value
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    94
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
    def GetOldValue(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        return self.old_value
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
    97
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
    def _updateColAttrs(self, grid):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        """
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        wx.grid.Grid -> update the column attributes to add the
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        appropriate renderer given the column name.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
        Otherwise default to the default renderer.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        """
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   105
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        for row in range(self.GetNumberRows()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
            row_highlights = self.Highlights.get(row, {})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
            for col in range(self.GetNumberCols()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
                editor = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
                renderer = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
                colname = self.GetColLabelValue(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
                if col != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
                    grid.SetReadOnly(row, col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
                    if colname == "Name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
                        editor = wx.grid.GridCellTextEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
                        renderer = wx.grid.GridCellStringRenderer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
                    elif colname == "Initial Value":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                        editor = wx.grid.GridCellTextEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
                        renderer = wx.grid.GridCellStringRenderer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
                    elif colname == "Type":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
                        editor = wx.grid.GridCellTextEditor()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
                    grid.SetReadOnly(row, col, True)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   124
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
                grid.SetCellEditor(row, col, editor)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
                grid.SetCellRenderer(row, col, renderer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   127
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
                grid.SetCellTextColour(row, col, highlight_colours[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
            self.ResizeRow(grid, row)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   132
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
    def AddHighlight(self, infos, highlight_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        row_highlights = self.Highlights.setdefault(infos[0], {})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
        if infos[1] == "initial":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
            col_highlights = row_highlights.setdefault("initial value", [])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
            col_highlights = row_highlights.setdefault(infos[1], [])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        col_highlights.append(highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   141
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
#                          Datatype Editor class
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   143
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   145
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
class DataTypeEditor(EditorPanel):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   147
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
    def _init_Editor(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
        self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   150
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        self.MainSizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.MainSizer.AddGrowableRow(1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   154
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        top_sizer = wx.BoxSizer(wx.HORIZONTAL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   156
        self.MainSizer.AddSizer(top_sizer, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   157
                                flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   158
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        derivation_type_label = wx.StaticText(self.Editor, label=_('Derivation Type:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   160
        top_sizer.AddWindow(derivation_type_label, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   161
                            flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   162
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        self.DerivationType = wx.ComboBox(self.Editor,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   164
                                          size=wx.Size(200, -1), style=wx.CB_READONLY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
        self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, self.DerivationType)
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   166
        top_sizer.AddWindow(self.DerivationType, border=5, flag=wx.GROW | wx.RIGHT)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   167
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
        typeinfos_staticbox = wx.StaticBox(self.Editor, label=_('Type infos:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
        typeinfos_sizer = wx.StaticBoxSizer(typeinfos_staticbox, wx.HORIZONTAL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   170
        self.MainSizer.AddSizer(typeinfos_sizer, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   171
                                flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   172
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
        # Panel for Directly derived data types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        self.DirectlyPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
        typeinfos_sizer.AddWindow(self.DirectlyPanel, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   177
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        directly_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   179
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   180
        directly_basetype_label = wx.StaticText(self.DirectlyPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   181
                                                label=_('Base Type:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   182
        directly_panel_sizer.AddWindow(directly_basetype_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   183
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   184
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
        self.DirectlyBaseType = wx.ComboBox(self.DirectlyPanel, style=wx.CB_READONLY)
947
82e2a155a3ce Fix bugs in DataTypeEditor
Laurent Bessard
parents: 864
diff changeset
   186
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.DirectlyBaseType)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   187
        directly_panel_sizer.AddWindow(self.DirectlyBaseType, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   188
                                       flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   189
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
        directly_initialvalue_label = wx.StaticText(self.DirectlyPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   191
                                                    label=_('Initial Value:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   192
        directly_panel_sizer.AddWindow(directly_initialvalue_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   193
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   194
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   195
        self.DirectlyInitialValue = wx.TextCtrl(self.DirectlyPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   196
                                                style=wx.TE_PROCESS_ENTER | wx.TE_RICH)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.DirectlyInitialValue)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   198
        directly_panel_sizer.AddWindow(self.DirectlyInitialValue, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   199
                                       flag=wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   200
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
        self.DirectlyPanel.SetSizer(directly_panel_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   202
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
        # Panel for Subrange data types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
        self.SubrangePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
        typeinfos_sizer.AddWindow(self.SubrangePanel, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   207
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
        subrange_panel_sizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   209
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
        subrange_basetype_label = wx.StaticText(self.SubrangePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   211
                                                label=_('Base Type:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   212
        subrange_panel_sizer.AddWindow(subrange_basetype_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   213
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   214
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
        self.SubrangeBaseType = wx.ComboBox(self.SubrangePanel, style=wx.CB_READONLY)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   216
        self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   217
                  self.SubrangeBaseType)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   218
        subrange_panel_sizer.AddWindow(self.SubrangeBaseType, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   219
                                       flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   220
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
        subrange_initialvalue_label = wx.StaticText(self.SubrangePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   222
                                                    label=_('Initial Value:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   223
        subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   224
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   225
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   226
        self.SubrangeInitialValue = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   227
        self.SubrangeInitialValue.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnInfosChanged)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   228
        subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   229
                                       flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   230
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   232
        subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   233
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   234
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   235
        self.SubrangeMinimum = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   236
        self.SubrangeMinimum.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnSubrangeMinimumChanged)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   237
        subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   238
                                       flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   239
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1833
diff changeset
   240
        for dummy in xrange(2):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   242
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
        subrange_maximum_label = wx.StaticText(self.SubrangePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   244
                                               label=_('Maximum:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   245
        subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   246
                                       flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   247
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   248
        self.SubrangeMaximum = CustomIntCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   249
        self.SubrangeMaximum.Bind(CustomIntCtrl.EVT_CUSTOM_INT, self.OnSubrangeMaximumChanged)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   250
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   251
        subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   252
                                       flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   253
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
        self.SubrangePanel.SetSizer(subrange_panel_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   255
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
        # Panel for Enumerated data types
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   257
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
        self.EnumeratedPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
        typeinfos_sizer.AddWindow(self.EnumeratedPanel, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   260
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
        enumerated_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   262
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   263
        self.EnumeratedValues = CustomEditableListBox(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   264
                self.EnumeratedPanel,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   265
                label=_("Values:"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   266
                style=(wx.gizmos.EL_ALLOW_NEW |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   267
                       wx.gizmos.EL_ALLOW_EDIT |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   268
                       wx.gizmos.EL_ALLOW_DELETE))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
        setattr(self.EnumeratedValues, "_OnLabelEndEdit", self.OnEnumeratedValueEndEdit)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
        for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
            setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   272
        enumerated_panel_sizer.AddWindow(self.EnumeratedValues, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   273
                                         flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   274
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
        enumerated_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
        enumerated_panel_sizer.AddSizer(enumerated_panel_rightsizer, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   277
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
        enumerated_initialvalue_label = wx.StaticText(self.EnumeratedPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   279
                                                      label=_('Initial Value:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   280
        enumerated_panel_rightsizer.AddWindow(enumerated_initialvalue_label, 1,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   281
                                              border=5,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   282
                                              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   283
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   284
        self.EnumeratedInitialValue = wx.ComboBox(self.EnumeratedPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   285
                                                  style=wx.CB_READONLY)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.EnumeratedInitialValue)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   287
        enumerated_panel_rightsizer.AddWindow(self.EnumeratedInitialValue, 1,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   288
                                              border=5, flag=wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   289
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
        self.EnumeratedPanel.SetSizer(enumerated_panel_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   291
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
        # Panel for Array data types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        self.ArrayPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
        typeinfos_sizer.AddWindow(self.ArrayPanel, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   296
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
        array_panel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
        array_panel_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
        array_panel_sizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
        array_panel_sizer.AddGrowableRow(1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   301
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
        array_panel_leftSizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
        array_panel_sizer.AddSizer(array_panel_leftSizer, flag=wx.GROW)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   304
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
        array_basetype_label = wx.StaticText(self.ArrayPanel, label=_('Base Type:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   306
        array_panel_leftSizer.AddWindow(array_basetype_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   307
                                        flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   308
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
        self.ArrayBaseType = wx.ComboBox(self.ArrayPanel, style=wx.CB_READONLY)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.ArrayBaseType)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   311
        array_panel_leftSizer.AddWindow(self.ArrayBaseType, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   312
                                        flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   313
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
        array_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
        array_panel_sizer.AddSizer(array_panel_rightsizer, flag=wx.GROW)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   316
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
        array_initialvalue_label = wx.StaticText(self.ArrayPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   318
                                                 label=_('Initial Value:'))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   319
        array_panel_rightsizer.AddWindow(array_initialvalue_label, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   320
                                         flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   321
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        self.ArrayInitialValue = wx.TextCtrl(self.ArrayPanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   323
                                             style=wx.TE_PROCESS_ENTER | wx.TE_RICH)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.ArrayInitialValue)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   325
        array_panel_rightsizer.AddWindow(self.ArrayInitialValue, 1, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   326
                                         flag=wx.ALL)
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   327
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   328
        self.ArrayDimensions = CustomEditableListBox(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   329
                self.ArrayPanel,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   330
                label=_("Dimensions:"),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   331
                style=(wx.gizmos.EL_ALLOW_NEW |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   332
                       wx.gizmos.EL_ALLOW_EDIT |
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   333
                       wx.gizmos.EL_ALLOW_DELETE))
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   334
        for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
                     "_OnUpButton", "_OnDownButton"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
            setattr(self.ArrayDimensions, func, self.OnDimensionsChanged)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   337
        array_panel_sizer.AddWindow(self.ArrayDimensions, 0, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   338
                                    flag=wx.GROW | wx.ALL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   339
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
        self.ArrayPanel.SetSizer(array_panel_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   341
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
        # Panel for Structure data types
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   343
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
        self.StructurePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
        typeinfos_sizer.AddWindow(self.StructurePanel, 1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   346
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
        structure_panel_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
        structure_panel_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
        structure_panel_sizer.AddGrowableRow(1)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   350
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
        structure_button_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
        structure_button_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
        structure_button_sizer.AddGrowableRow(0)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   354
        structure_panel_sizer.AddSizer(structure_button_sizer, 0, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   355
                                       flag=wx.ALL | wx.GROW)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   356
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
        structure_elements_label = wx.StaticText(self.StructurePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   358
                                                 label=_('Elements :'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
        structure_button_sizer.AddWindow(structure_elements_label, flag=wx.ALIGN_BOTTOM)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   360
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
        for name, bitmap, help in [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
                ("StructureAddButton", "add_element", _("Add element")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
                ("StructureDeleteButton", "remove_element", _("Remove element")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
                ("StructureUpButton", "up", _("Move element up")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
                ("StructureDownButton", "down", _("Move element down"))]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
            button = wx.lib.buttons.GenBitmapButton(self.StructurePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   367
                                                    bitmap=GetBitmap(bitmap),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   368
                                                    size=wx.Size(28, 28),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   369
                                                    style=wx.NO_BORDER)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
            button.SetToolTipString(help)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
            setattr(self, name, button)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
            structure_button_sizer.AddWindow(button)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   373
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   374
        self.StructureElementsGrid = CustomGrid(self.StructurePanel,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   375
                                                size=wx.Size(0, 150), style=wx.VSCROLL)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   376
        self.StructureElementsGrid.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: 1762
diff changeset
   377
                                        self.OnStructureElementsGridCellChange)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   378
        self.StructureElementsGrid.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: 1762
diff changeset
   379
                                        self.OnStructureElementsGridEditorShown)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        structure_panel_sizer.AddWindow(self.StructureElementsGrid, flag=wx.GROW)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   381
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
        self.StructurePanel.SetSizer(structure_panel_sizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   383
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
        self.Editor.SetSizer(self.MainSizer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   385
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
    def __init__(self, parent, tagname, window, controler):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
        EditorPanel.__init__(self, parent, tagname, window, controler)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   388
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   389
        self.StructureElementDefaultValue = {"Name": "", "Type": DefaultType, "Initial Value": ""}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
        self.StructureElementsTable = ElementsTable(self, [], GetElementsTableColnames())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
        self.StructureColSizes = [40, 150, 100, 250]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        self.StructureColAlignements = [wx.ALIGN_CENTER, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   393
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
        self.StructureElementsGrid.SetTable(self.StructureElementsTable)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
        self.StructureElementsGrid.SetButtons({"Add": self.StructureAddButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
                                               "Delete": self.StructureDeleteButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
                                               "Up": self.StructureUpButton,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
                                               "Down": self.StructureDownButton})
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   399
1821
44a47d255d36 fix problem if DataTypeEditor was imported before localization is
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1812
diff changeset
   400
        self.DATATYPE_TYPES_DICT = dict([(_(datatype), datatype) for datatype in GetDatatypeTypes()])
44a47d255d36 fix problem if DataTypeEditor was imported before localization is
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1812
diff changeset
   401
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
        def _AddStructureElement(new_row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
            self.StructureElementsTable.InsertRow(new_row, self.StructureElementDefaultValue.copy())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
            self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
            return new_row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
        setattr(self.StructureElementsGrid, "_AddRow", _AddStructureElement)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   408
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
        def _DeleteStructureElement(row):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
            self.StructureElementsTable.RemoveRow(row)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
            self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
        setattr(self.StructureElementsGrid, "_DeleteRow", _DeleteStructureElement)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   414
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
        def _MoveStructureElement(row, move):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
            new_row = self.StructureElementsTable.MoveRow(row, move)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
            if new_row != row:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
                self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
                self.StructureElementsTable.ResetView(self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
            return new_row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
        setattr(self.StructureElementsGrid, "_MoveRow", _MoveStructureElement)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   422
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
        self.StructureElementsGrid.SetRowLabelSize(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
        for col in range(self.StructureElementsTable.GetNumberCols()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
            attr = wx.grid.GridCellAttr()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
            attr.SetAlignment(self.StructureColAlignements[col], wx.ALIGN_CENTRE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
            self.StructureElementsGrid.SetColAttr(col, attr)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
            self.StructureElementsGrid.SetColMinimalWidth(col, self.StructureColSizes[col])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
            self.StructureElementsGrid.AutoSizeColumn(col, False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
        self.StructureElementsGrid.RefreshButtons()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   431
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
        for datatype in GetDatatypeTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
            self.DerivationType.Append(_(datatype))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
        self.SubrangePanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
        self.EnumeratedPanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
        self.ArrayPanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
        self.StructurePanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
        self.CurrentPanel = "Directly"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
        self.Highlights = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
        self.Initializing = False
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   441
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
        self.HighlightControls = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
            ("Directly", "base"): self.DirectlyBaseType,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
            ("Directly", "initial"): self.DirectlyInitialValue,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
            ("Subrange", "base"): self.SubrangeBaseType,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
            ("Subrange", "lower"): self.SubrangeMinimum,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
            ("Subrange", "upper"): self.SubrangeMaximum,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
            ("Subrange", "initial"): self.SubrangeInitialValue,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
            ("Enumerated", "value"): self.EnumeratedValues,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
            ("Enumerated", "initial"): self.EnumeratedInitialValue,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
            ("Array", "initial"): self.ArrayInitialValue,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
            ("Array", "base"): self.ArrayBaseType,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
            ("Array", "range"): self.ArrayDimensions,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
        }
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   455
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   458
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
        self.RefreshHighlightsTimer.Stop()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   461
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
    def GetBufferState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   463
        return self.Controler.GetBufferState()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   464
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
    def Undo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
        self.Controler.LoadPrevious()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
        self.ParentWindow.CloseTabsWithoutModel()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   468
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
    def Redo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
        self.Controler.LoadNext()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
        self.ParentWindow.CloseTabsWithoutModel()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   472
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
    def HasNoModel(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
        return self.Controler.GetEditedElement(self.TagName) is None
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   475
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
    def RefreshView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
        self.Initializing = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
        self.DirectlyBaseType.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
        self.ArrayBaseType.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
        for datatype in self.Controler.GetDataTypes(self.TagName):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
            self.DirectlyBaseType.Append(datatype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
            self.ArrayBaseType.Append(datatype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
        self.DirectlyBaseType.SetSelection(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
        self.SubrangeBaseType.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
        words = self.TagName.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
        for base_type in self.Controler.GetSubrangeBaseTypes(words[1]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
            self.SubrangeBaseType.Append(base_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
        self.SubrangeBaseType.SetSelection(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
        self.RefreshBoundsRange()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
        if type_infos is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
            datatype = type_infos["type"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
            self.DerivationType.SetStringSelection(_(datatype))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
            if type_infos["type"] == "Directly":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
                self.DirectlyBaseType.SetStringSelection(type_infos["base_type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
                self.DirectlyInitialValue.SetValue(type_infos["initial"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
            elif type_infos["type"] == "Subrange":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
                self.SubrangeBaseType.SetStringSelection(type_infos["base_type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
                self.RefreshBoundsRange()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
                self.SubrangeMinimum.SetValue(int(type_infos["min"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
                self.SubrangeMaximum.SetValue(int(type_infos["max"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
                self.RefreshSubrangeInitialValueRange()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
                if type_infos["initial"] != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
                    self.SubrangeInitialValue.SetValue(int(type_infos["initial"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
                    self.SubrangeInitialValue.SetValue(type_infos["min"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
            elif type_infos["type"] == "Enumerated":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
                self.EnumeratedValues.SetStrings(type_infos["values"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
                self.RefreshEnumeratedValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
                self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
            elif type_infos["type"] == "Array":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
                self.ArrayBaseType.SetStringSelection(type_infos["base_type"])
1833
2269739dd098 fix unnecessary lambda and enable corresponding pylint check
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1821
diff changeset
   513
                self.ArrayDimensions.SetStrings(map("..".join, type_infos["dimensions"]))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
                self.ArrayInitialValue.SetValue(type_infos["initial"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
            elif type_infos["type"] == "Structure":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
                self.StructureElementsTable.SetData(type_infos["elements"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
            self.RefreshDisplayedInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
        self.ShowHighlights()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
        self.StructureElementsTable.ResetView(self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
        self.StructureElementsGrid.RefreshButtons()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
        self.Initializing = False
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   522
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
    def OnDerivationTypeChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
        wx.CallAfter(self.RefreshDisplayedInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
        wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
    def OnReturnKeyPressed(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
        self.RefreshTypeInfos()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   530
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
    def OnInfosChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
    def OnSubrangeBaseTypeChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
        self.RefreshBoundsRange()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
        self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
    def OnSubrangeMinimumChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
        if not self.Initializing:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
            wx.CallAfter(self.SubrangeMinimum.SetValue, min(self.SubrangeMaximum.GetValue(), self.SubrangeMinimum.GetValue()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
            wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
    def OnSubrangeMaximumChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
        if not self.Initializing:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
            wx.CallAfter(self.SubrangeMaximum.SetValue, max(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
            wx.CallAfter(self.RefreshSubrangeInitialValueRange)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
            wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
    def OnDimensionsChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
        wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
    def OnEnumeratedValueEndEdit(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
        text = event.GetText()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
        values = self.EnumeratedValues.GetStrings()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        index = event.GetIndex()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
        if index >= len(values) or values[index].upper() != text.upper():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
            if text.upper() in [value.upper() for value in values]:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   564
                message = wx.MessageDialog(self, _("\"%s\" value already defined!") % text, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
                message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
                message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
                event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
            elif text.upper() in IEC_KEYWORDS:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   569
                message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!") % text, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
                message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
                message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
                initial_selected = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
                if index < len(values) and self.EnumeratedInitialValue.GetStringSelection() == values[index]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
                    initial_selected = text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
                wx.CallAfter(self.RefreshEnumeratedValues, initial_selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
                wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
                event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
            event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   581
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
    def OnEnumeratedValuesChanged(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
        wx.CallAfter(self.RefreshEnumeratedValues)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
        wx.CallAfter(self.RefreshTypeInfos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
        event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   586
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   587
    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: 1742
diff changeset
   588
        dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   589
        dialog.ShowModal()
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   590
        dialog.Destroy()
1735
c02818d7e29f clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   591
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
    def OnStructureElementsGridCellChange(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
        row, col = event.GetRow(), event.GetCol()
947
82e2a155a3ce Fix bugs in DataTypeEditor
Laurent Bessard
parents: 864
diff changeset
   594
        colname = self.StructureElementsTable.GetColLabelValue(col, False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
        value = self.StructureElementsTable.GetValue(row, col)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
        if colname == "Name":
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   597
            message = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
            if not TestIdentifier(value):
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1658
diff changeset
   599
                message = _("\"%s\" is not a valid identifier!") % value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
            elif value.upper() in IEC_KEYWORDS:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1658
diff changeset
   601
                message = _("\"%s\" is a keyword. It can't be used!") % value
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   602
#            elif value.upper() in self.PouNames:
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   603
#                message = _("A pou with \"%s\" as name exists!")%value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
            elif value.upper() in [var["Name"].upper() for idx, var in enumerate(self.StructureElementsTable.GetData()) if idx != row]:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1658
diff changeset
   605
                message = _("An element named \"%s\" already exists in this structure!") % value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
                self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
                wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid)
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   609
#                old_value = self.Table.GetOldValue()
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   610
#                if old_value != "":
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   611
#                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   612
#                self.Controler.BufferProject()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                event.Skip()
1658
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   614
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   615
            if message is not None:
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   616
                event.Veto()
ba6a6d6e989c fix twice shown error message box, when wrong non-valid IEC identifier entered
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   617
                wx.CallAfter(self.ShowErrorMessage, message)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
            self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
            wx.CallAfter(self.StructureElementsTable.ResetView, self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
            event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   622
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
    def OnStructureElementsGridSelectCell(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
        wx.CallAfter(self.RefreshStructureButtons)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
        event.Skip()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   626
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
    def OnStructureElementsGridEditorShown(self, event):
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   628
        row, col = event.GetRow(), event.GetCol()
947
82e2a155a3ce Fix bugs in DataTypeEditor
Laurent Bessard
parents: 864
diff changeset
   629
        if self.StructureElementsTable.GetColLabelValue(col, False) == "Type":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
            type_menu = wx.Menu(title='')
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   631
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
            base_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
            for base_type in self.Controler.GetBaseTypes():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
                AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
            type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   638
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
            datatype_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
            for datatype in self.Controler.GetDataTypes(self.TagName, False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
                self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
            type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   645
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   646
            new_id = wx.NewId()
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   647
            AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   648
            self.Bind(wx.EVT_MENU, self.ElementArrayTypeFunction, id=new_id)
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   649
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   650
#            functionblock_menu = wx.Menu(title='')
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   651
#            bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   652
#            pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   653
#            if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   654
#                for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName):
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   655
#                    new_id = wx.NewId()
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   656
#                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   657
#                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   658
#                type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   659
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
            rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
            self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
            type_menu.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
            event.Veto()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
            event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
    def GetElementTypeFunction(self, base_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
        def ElementTypeFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
            row = self.StructureElementsGrid.GetGridCursorRow()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
            self.StructureElementsTable.SetValueByName(row, "Type", base_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
            self.RefreshTypeInfos()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
        return ElementTypeFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   675
    def ElementArrayTypeFunction(self, event):
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   676
        row = self.StructureElementsGrid.GetGridCursorRow()
1412
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   677
        dialog = ArrayTypeDialog(self,
50192dd2f5ff Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents: 947
diff changeset
   678
                                 self.Controler.GetDataTypes(self.TagName),
864
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   679
                                 self.StructureElementsTable.GetValueByName(row, "Type"))
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   680
        if dialog.ShowModal() == wx.ID_OK:
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   681
            self.StructureElementsTable.SetValueByName(row, "Type", dialog.GetValue())
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   682
            self.RefreshTypeInfos()
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   683
            self.StructureElementsTable.ResetView(self.StructureElementsGrid)
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   684
        dialog.Destroy()
bf4f7f0801b9 Adding support for direct array declaration in structure element declaration
Laurent Bessard
parents: 814
diff changeset
   685
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
    def RefreshDisplayedInfos(self):
1821
44a47d255d36 fix problem if DataTypeEditor was imported before localization is
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1812
diff changeset
   687
        selected = self.DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
        if selected != self.CurrentPanel:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
            if self.CurrentPanel == "Directly":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
                self.DirectlyPanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
            elif self.CurrentPanel == "Subrange":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
                self.SubrangePanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            elif self.CurrentPanel == "Enumerated":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
                self.EnumeratedPanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            elif self.CurrentPanel == "Array":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
                self.ArrayPanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
            elif self.CurrentPanel == "Structure":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
                self.StructurePanel.Hide()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
            self.CurrentPanel = selected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
            if selected == "Directly":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
                self.DirectlyPanel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
            elif selected == "Subrange":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
                self.SubrangePanel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
            elif selected == "Enumerated":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
                self.EnumeratedPanel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
            elif selected == "Array":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
                self.ArrayPanel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
            elif selected == "Structure":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
                self.StructurePanel.Show()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
            self.MainSizer.Layout()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
    def RefreshEnumeratedValues(self, initial_selected=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
        if initial_selected is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
            initial_selected = self.EnumeratedInitialValue.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
        self.EnumeratedInitialValue.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
        self.EnumeratedInitialValue.Append("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
        for value in self.EnumeratedValues.GetStrings():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
            self.EnumeratedInitialValue.Append(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
        self.EnumeratedInitialValue.SetStringSelection(initial_selected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
    def RefreshBoundsRange(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
        range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
        if range is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
            min_value, max_value = range
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   725
            self.SubrangeMinimum.SetBounds(min_value, max_value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
            self.SubrangeMinimum.SetValue(min(max(min_value, self.SubrangeMinimum.GetValue()), max_value))
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   727
            self.SubrangeMaximum.SetBounds(min_value, max_value)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
            self.SubrangeMaximum.SetValue(min(max(min_value, self.SubrangeMaximum.GetValue()), max_value))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
    def RefreshSubrangeInitialValueRange(self):
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   731
        self.SubrangeInitialValue.SetBounds(self.SubrangeMinimum.GetValue(), self.SubrangeMaximum.GetValue())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
    def RefreshTypeInfos(self):
1821
44a47d255d36 fix problem if DataTypeEditor was imported before localization is
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1812
diff changeset
   734
        selected = self.DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()]
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   735
        infos = {"type": selected}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
        if selected == "Directly":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
            infos["base_type"] = self.DirectlyBaseType.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
            infos["initial"] = self.DirectlyInitialValue.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
        elif selected == "Subrange":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
            infos["base_type"] = self.SubrangeBaseType.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
            infos["min"] = str(self.SubrangeMinimum.GetValue())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
            infos["max"] = str(self.SubrangeMaximum.GetValue())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
            initial_value = self.SubrangeInitialValue.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
            if initial_value == infos["min"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
                infos["initial"] = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
                infos["initial"] = str(initial_value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
        elif selected == "Enumerated":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
            infos["values"] = self.EnumeratedValues.GetStrings()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
            infos["initial"] = self.EnumeratedInitialValue.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
        elif selected == "Array":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
            infos["base_type"] = self.ArrayBaseType.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
            infos["dimensions"] = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
            for dimensions in self.ArrayDimensions.GetStrings():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
                result = DIMENSION_MODEL.match(dimensions)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
                if result is None:
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   757
                    message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!") % dimensions, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
                    message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                    message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
                    self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                bounds = result.groups()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
                if int(bounds[0]) >= int(bounds[1]):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   764
                    message = wx.MessageDialog(self, _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.") % dimensions, _("Error"), wx.OK | wx.ICON_ERROR)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
                    message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
                    message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
                    self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                infos["dimensions"].append(bounds)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
            infos["initial"] = self.ArrayInitialValue.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
        elif selected == "Structure":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
            infos["elements"] = self.StructureElementsTable.GetData()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
            infos["initial"] = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
        self.Controler.SetDataTypeInfos(self.TagName, infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
        self.ParentWindow.RefreshTitle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
        self.ParentWindow.RefreshFileMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
        self.ParentWindow.RefreshEditMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   779
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   780
    #                        Highlights showing functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
   781
    # -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   782
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
    def OnRefreshHighlightsTimer(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
    def ClearHighlights(self, highlight_type=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
        if highlight_type is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
            self.Highlights = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
            self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
        for control in self.HighlightControls.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
            if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
                control.SetBackgroundColour(wx.NullColour)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
                control.SetForegroundColour(wx.NullColour)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
            elif isinstance(control, wx.TextCtrl):
1812
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   797
                value = control.GetValueStr() if isinstance(control, CustomIntCtrl) else \
8626a4948d5e use CustomIntCtrl instead of wx.SpinCtrl because it doesn't support
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   798
                        control.GetValue()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
                control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
            elif isinstance(control, wx.gizmos.EditableListBox):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
                listctrl = control.GetListCtrl()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
                for i in xrange(listctrl.GetItemCount()):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
                    listctrl.SetItemBackgroundColour(i, wx.NullColour)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
                    listctrl.SetItemTextColour(i, wx.NullColour)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   805
        self.StructureElementsTable.ClearHighlights(highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   806
        self.RefreshView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   807
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   808
    def AddHighlight(self, infos, start, end, highlight_type):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
        self.Highlights.append((infos, start, end, highlight_type))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
    def ShowHighlights(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
        type_infos = self.Controler.GetDataTypeInfos(self.TagName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
        for infos, start, end, highlight_type in self.Highlights:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
            if infos[0] == "struct":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
                self.StructureElementsTable.AddHighlight(infos[1:], highlight_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
                control = self.HighlightControls.get((type_infos["type"], infos[0]), None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
                if control is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
                    if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
                        control.SetBackgroundColour(highlight_type[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
                        control.SetForegroundColour(highlight_type[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
                    elif isinstance(control, wx.TextCtrl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
                        control.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
                    elif isinstance(control, wx.gizmos.EditableListBox):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
                        listctrl = control.GetListCtrl()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
                        listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
                        listctrl.SetItemTextColour(infos[1], highlight_type[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
                        listctrl.Select(listctrl.FocusedItem, False)