dialogs/LDElementDialog.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 17 May 2023 23:59:45 +0200
changeset 3806 b57a38ce3f34
parent 3750 f62625418bff
permissions -rw-r--r--
IDE: Fix py_ext build with python3.10
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: 1493
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: 1493
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: 1493
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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: 1493
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
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    26
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3303
diff changeset
    27
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    30
from graphics.GraphicCommons import CONTACT_NORMAL, CONTACT_REVERSE, \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    31
    CONTACT_RISING, CONTACT_FALLING, COIL_NORMAL, COIL_REVERSE, COIL_SET, \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    32
    COIL_RESET, COIL_RISING, COIL_FALLING
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    33
from graphics.LD_Objects import LD_Contact, LD_Coil
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    34
from dialogs.BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    36
# -------------------------------------------------------------------------------
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    37
#                       Set Ladder Element Parmeters Dialog
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    38
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    40
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    41
class LDElementDialog(BlockPreviewDialog):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    42
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    43
    Class that implements a dialog for defining parameters of a LD contact or coil
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    44
    graphic element
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    46
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    47
    def __init__(self, parent, controller, tagname, type):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    48
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    49
        Constructor
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    50
        @param parent: Parent wx.Window of dialog for modal
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    51
        @param controller: Reference to project controller
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    52
        @param tagname: Tagname of project POU edited
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    53
        @param type: Type of LD element ('contact or 'coil')
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    54
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    55
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    56
                                    title=(_("Edit Contact Values")
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    57
                                           if type == "contact"
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    58
                                           else _("Edit Coil Values")))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    59
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1247
diff changeset
    60
        # Init common sizers
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    61
        self._init_sizers(2, 0, (7 if type == "contact" else 9),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    62
                          None, 2, 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    63
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    64
        # Create label for LD element modifier
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        modifier_label = wx.StaticText(self, label=_('Modifier:'))
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
    66
        self.LeftGridSizer.Add(modifier_label, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    67
                                     flag=wx.GROW | wx.BOTTOM)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    68
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    69
        # Create radio buttons for selecting LD element modifier
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    70
        self.ModifierRadioButtons = {}
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    71
        first = True
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    72
        element_modifiers = ([CONTACT_NORMAL, CONTACT_REVERSE,
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    73
                              CONTACT_RISING, CONTACT_FALLING]
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    74
                             if type == "contact"
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    75
                             else [COIL_NORMAL, COIL_REVERSE, COIL_SET,
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    76
                                   COIL_RESET, COIL_RISING, COIL_FALLING])
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    77
        modifiers_label = \
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    78
            [_("Normal"), _("Negated")] + \
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    79
            ([_("Set"), _("Reset")] if type == "coil" else []) + \
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    80
            [_("Rising Edge"), _("Falling Edge")]
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    81
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    82
        for modifier, label in zip(element_modifiers, modifiers_label):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    83
            radio_button = wx.RadioButton(self, label=label,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    84
                                          style=(wx.RB_GROUP if first else 0))
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    85
            radio_button.SetValue(first)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    86
            self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
    87
            self.LeftGridSizer.Add(radio_button, flag=wx.GROW)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    88
            self.ModifierRadioButtons[modifier] = radio_button
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    89
            first = False
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    90
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    91
        # Create label for LD element variable
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    92
        element_variable_label = wx.StaticText(self, label=_('Variable:'))
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
    93
        self.LeftGridSizer.Add(element_variable_label, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
    94
                                     flag=wx.GROW | wx.TOP)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    95
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    96
        # Create a combo box for defining LD element variable
1370
ee795a8d4404 Fixed coil and contact dialog to let user select a complex type variable for contact and coil expression
Laurent Bessard
parents: 1259
diff changeset
    97
        self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
    98
        self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged,
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
    99
                  self.ElementVariable)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   100
        self.Bind(wx.EVT_TEXT, self.OnVariableChanged,
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   101
                  self.ElementVariable)
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   102
        self.LeftGridSizer.Add(self.ElementVariable, border=5,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   103
                                     flag=wx.GROW | wx.TOP)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   104
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   105
        # Add preview panel and associated label to sizers
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   106
        self.RightGridSizer.Add(self.PreviewLabel, flag=wx.GROW)
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   107
        self.RightGridSizer.Add(self.Preview, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   108
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   109
        # Add buttons sizer to sizers
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   110
        self.MainSizer.Add(self.ButtonSizer, border=20,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   111
                                flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   112
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   113
        # Save LD element class
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   114
        self.ElementClass = (LD_Contact if type == "contact" else LD_Coil)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   115
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   116
        # Extract list of variables defined in POU
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   117
        self.RefreshVariableList()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   118
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   119
        # Set values in ElementVariable
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3303
diff changeset
   120
        for name, (var_type, value_type) in self.VariableList.items():
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   121
            # Only select BOOL variable and avoid input for coil
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   122
            if (type == "contact" or var_type != "Input") and \
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   123
               value_type == "BOOL":
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   124
                self.ElementVariable.Append(name)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   125
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   126
        self.Fit()
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   127
        # Normal radio button is default control having keyboard focus
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   128
        self.ModifierRadioButtons[element_modifiers[0]].SetFocus()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   129
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   130
    def GetElementModifier(self):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   131
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   132
        Return modifier selected for LD element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   133
        @return: Modifier selected (None if not found)
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   134
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   135
        # Go through radio buttons and return modifier associated to the one
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   136
        # that is selected
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3303
diff changeset
   137
        for modifier, control in self.ModifierRadioButtons.items():
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   138
            if control.GetValue():
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   139
                return modifier
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   140
        return None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
    def SetValues(self, values):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   143
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   144
        Set default LD element parameters
1252
18cd1357e8d3 Rewrite SFCTransitionDialog
Laurent Bessard
parents: 1250
diff changeset
   145
        @param values: LD element parameters values
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   146
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   147
        # For each parameters defined, set corresponding control value
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3303
diff changeset
   148
        for name, value in list(values.items()):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   149
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   150
            # Parameter is LD element variable
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   151
            if name == "variable":
1370
ee795a8d4404 Fixed coil and contact dialog to let user select a complex type variable for contact and coil expression
Laurent Bessard
parents: 1259
diff changeset
   152
                self.ElementVariable.SetValue(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   153
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   154
            # Set value of other controls
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   155
            elif name == "modifier":
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   156
                self.ModifierRadioButtons[value].SetValue(True)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   157
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   158
        # Refresh preview panel
2591
5f685bcd3ad6 Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents: 2587
diff changeset
   159
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
    def GetValues(self):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   162
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   163
        Return LD element parameters defined in dialog
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   164
        @return: {parameter_name: parameter_value,...}
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   165
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   166
        values = {
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   167
            "variable": self.ElementVariable.GetValue(),
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   168
            "modifier": self.GetElementModifier()}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
        values["width"], values["height"] = self.Element.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
        return values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   172
    def OnModifierChanged(self, event):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   173
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   174
        Called when LD element modifier changed
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   175
        @param event: wx.RadioButtonEvent
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   176
        """
2591
5f685bcd3ad6 Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents: 2587
diff changeset
   177
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   180
    def OnVariableChanged(self, event):
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   181
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   182
        Called when LD element associated variable changed
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   183
        @param event: wx.ComboBoxEvent
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   184
        """
2591
5f685bcd3ad6 Fixed refresh problem following 9c5f835b031e, 9622418ac28c, c67488bd8134 : force redraw only through EVT_PAINT event and use wxPaintDC, as described in wx documentation
Edouard Tisserant
parents: 2587
diff changeset
   185
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
2587
c67488bd8134 Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents: 1878
diff changeset
   188
    def DrawPreview(self):
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   189
        """
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   190
        Refresh preview panel of graphic element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   191
        Override BlockPreviewDialog function
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   192
        """
1698
ae3e819252fc disable empty coils and contacts in LD/SFC editors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   193
        value = self.ElementVariable.GetValue()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   194
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   195
        # Set graphic element displayed, creating a LD element
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   196
        self.Element = self.ElementClass(
1878
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   197
            self.Preview,
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   198
            self.GetElementModifier(),
fb73a6b6622d fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1853
diff changeset
   199
            value)
1698
ae3e819252fc disable empty coils and contacts in LD/SFC editors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   200
3303
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   201
        # FIXME : how to disable OK button when content is not valid
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   202
        # button = self.ButtonSizer.GetAffirmativeButton()
0ffb41625592 Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2591
diff changeset
   203
        # button.Enable(value != "")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   204
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 814
diff changeset
   205
        # Call BlockPreviewDialog function
2587
c67488bd8134 Fixed preview drawing/refresh problem in sfc/ld/fbd graphical element creation dialogs on windows (introduced in 9c5f835b031e, continuation of 9622418ac28c)
Edouard Tisserant
parents: 1878
diff changeset
   206
        BlockPreviewDialog.DrawPreview(self)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1698
diff changeset
   207
1698
ae3e819252fc disable empty coils and contacts in LD/SFC editors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   208
    def OnOK(self, event):
ae3e819252fc disable empty coils and contacts in LD/SFC editors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   209
        if self.ElementVariable.GetValue() != "":
ae3e819252fc disable empty coils and contacts in LD/SFC editors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   210
            self.EndModal(wx.ID_OK)