dialogs/ConnectionDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 18 Aug 2017 20:14:38 +0300
changeset 1768 691083b5682a
parent 1745 f9d32913bad4
child 1782 5b6ad7a7fd9d
permissions -rwxr-xr-x
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
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: 1487
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: 1487
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
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>
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
     9
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
    10
# See COPYING file for copyrights details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
    11
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
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: 1487
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: 1487
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: 1487
diff changeset
    15
# of the License, or (at your option) any later version.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
    16
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
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: 1487
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: 1487
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: 1487
diff changeset
    20
# GNU General Public License for more details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
diff changeset
    21
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1487
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: 1487
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: 1487
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 wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    28
from graphics.GraphicCommons import CONNECTOR, CONTINUATION
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    29
from graphics.FBD_Objects import FBD_Connector
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    30
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
#-------------------------------------------------------------------------------
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    33
#                       Set Connection Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
    36
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    37
class ConnectionDialog(BlockPreviewDialog):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    39
    Class that implements a dialog for defining parameters of a connection graphic
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    40
    element
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    41
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    42
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    43
    def __init__(self, parent, controller, tagname, apply_button=False):
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    44
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    45
        Constructor
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    46
        @param parent: Parent wx.Window of dialog for modal
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    47
        @param controller: Reference to project controller
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    48
        @param tagname: Tagname of project POU edited
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    49
        @param apply_button: Enable button for applying connector modification
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    50
        to all connector having the same name in POU (default: False)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    51
        """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    52
        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: 1745
diff changeset
    53
                                    title=_('Connection Properties'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    54
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1249
diff changeset
    55
        # Init common sizers
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    56
        self._init_sizers(2, 0, 7, 1, 0, None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    57
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    58
        # Create label for connection type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        type_label = wx.StaticText(self, label=_('Type:'))
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1249
diff changeset
    60
        self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    61
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    62
        # Create radio buttons for selecting connection type
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
    63
        self.TypeRadioButtons = {}
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    64
        first = True
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    65
        for type, label in [(CONNECTOR, _('Connector')),
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    66
                            (CONTINUATION, _('Continuation'))]:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    67
            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: 1745
diff changeset
    68
                                          style=(wx.RB_GROUP if first else 0))
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    69
            radio_button.SetValue(first)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    70
            self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1249
diff changeset
    71
            self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
    72
            self.TypeRadioButtons[type] = radio_button
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    73
            first = False
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    74
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    75
        # Create label for connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
        name_label = wx.StaticText(self, label=_('Name:'))
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1249
diff changeset
    77
        self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    78
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    79
        # Create text control for defining connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        self.ConnectionName = wx.TextCtrl(self)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    81
        self.ConnectionName.SetMinSize(wx.Size(200, -1))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1249
diff changeset
    83
        self.LeftGridSizer.AddWindow(self.ConnectionName, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    84
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    85
        # Add preview panel and associated label to sizers
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    86
        self.Preview.SetMinSize(wx.Size(-1, 100))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    87
        self.LeftGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    88
        self.LeftGridSizer.AddWindow(self.Preview, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    89
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    90
        # Add buttons sizer to sizers
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    91
        self.MainSizer.AddSizer(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    92
            self.ButtonSizer, border=20,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    93
            flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    94
        self.ColumnSizer.RemoveSizer(self.RightGridSizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    95
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    96
        # Add button for applying connection name modification to all connection
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
    97
        # of POU
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
    98
        if apply_button:
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
    99
            self.ApplyToAllButton = wx.Button(self, label=_("Propagate Name"))
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   100
            self.ApplyToAllButton.SetToolTipString(
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   101
                _("Apply name modification to all continuations with the same name"))
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   102
            self.Bind(wx.EVT_BUTTON, self.OnApplyToAll, self.ApplyToAllButton)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   103
            self.ButtonSizer.AddWindow(self.ApplyToAllButton, flag=wx.LEFT)
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   104
        else:
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   105
            self.ConnectionName.ChangeValue(
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   106
                controller.GenerateNewName(
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   107
                        tagname, None, "Connection%d", 0))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   108
        self.Fit()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   109
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   110
        # Connector radio button is default control having keyboard focus
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
   111
        self.TypeRadioButtons[CONNECTOR].SetFocus()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   112
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   113
    def GetConnectionType(self):
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   114
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   115
        Return type selected for connection
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   116
        @return: Type selected (CONNECTOR or CONTINUATION)
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   117
        """
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   118
        return (CONNECTOR
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   119
                if self.TypeRadioButtons[CONNECTOR].GetValue()
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   120
                else CONTINUATION)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   121
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    def SetValues(self, values):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   123
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   124
        Set default connection parameters
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   125
        @param values: Connection parameters values
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   126
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   127
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        for name, value in values.items():
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   129
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   130
            # Parameter is connection type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
            if name == "type":
1246
101625efb1c1 Rewrite LDElementDialog
Laurent Bessard
parents: 1245
diff changeset
   132
                self.TypeRadioButtons[value].SetValue(True)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   133
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   134
            # Parameter is connection name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
            elif name == "name":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
                self.ConnectionName.SetValue(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   137
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   138
        # Refresh preview panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        self.RefreshPreview()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   140
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
    def GetValues(self):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   142
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   143
        Return connection parameters defined in dialog
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   144
        @return: {parameter_name: parameter_value,...}
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   145
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   146
        values = {
1249
b956c924cbbd Rewrite LDPowerRailDialog
Laurent Bessard
parents: 1247
diff changeset
   147
            "type": self.GetConnectionType(),
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   148
            "name": self.ConnectionName.GetValue()}
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   149
        values["width"], values["height"] = self.Element.GetSize()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        return values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   152
    def TestConnectionName(self):
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   153
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   154
        Test that connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   155
        @return: True if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   156
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        message = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   158
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   159
        # Get connection name typed by user
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        connection_name = self.ConnectionName.GetValue()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   161
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   162
        # Test that a name have been defined
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
        if connection_name == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
            message = _("Form isn't complete. Name must be filled!")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   165
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   166
        # If an error have been identify, show error message dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        if message is not None:
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   168
            self.ShowErrorMessage(message)
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   169
            # Test failed
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   170
            return False
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   171
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   172
        # Return result of element name test
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   173
        return self.TestElementName(connection_name)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   174
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   175
    def OnOK(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   176
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   177
        Called when dialog OK button is pressed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   178
        Test if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   179
        @param event: wx.Event from OK button
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   180
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   181
        # Close dialog if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   182
        if self.TestConnectionName():
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
            self.EndModal(wx.ID_OK)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   185
    def OnApplyToAll(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   186
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   187
        Called when Apply To All button is pressed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   188
        Test if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   189
        @param event: wx.Event from OK button
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   190
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   191
        # Close dialog if connection name is valid
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   192
        if self.TestConnectionName():
856
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   193
            self.EndModal(wx.ID_YESTOALL)
b64e436f000e Adding button in ConnectionDialog to propagate connection name modification to all connections with the same name in POU
Laurent Bessard
parents: 814
diff changeset
   194
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
    def OnTypeChanged(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   196
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   197
        Called when connection type changed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   198
        @param event: wx.RadioButtonEvent
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   199
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
    def OnNameChanged(self, event):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   204
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   205
        Called when connection name value changed
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   206
        @param event: wx.TextEvent
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   207
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   210
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
    def RefreshPreview(self):
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   212
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   213
        Refresh preview panel of graphic element
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   214
        Override BlockPreviewDialog function
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   215
        """
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   216
        # Set graphic element displayed, creating a FBD connection element
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   217
        self.Element = FBD_Connector(self.Preview,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   218
                                     self.GetConnectionType(),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   219
                                     self.ConnectionName.GetValue())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   220
1245
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   221
        # Call BlockPreviewDialog function
d34ba528346b Rewrite ConnectionDialog
Laurent Bessard
parents: 856
diff changeset
   222
        BlockPreviewDialog.RefreshPreview(self)