dialogs/SFCDivergenceDialog.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 20 Oct 2020 00:23:52 +0200
branchsvghmi
changeset 3063 466c3df67835
parent 2591 5f685bcd3ad6
child 3303 0ffb41625592
permissions -rw-r--r--
PY_EXT: OnChange is now a coma separated list of callables. Updated tests/python accordingly.
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1259
diff changeset
     1
#!/usr/bin/env python
814
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: 1259
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: 1259
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: 1259
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: 1585
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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: 1259
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
from __future__ import absolute_import
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    29
from graphics.GraphicCommons import SELECTION_DIVERGENCE, \
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    30
    SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    31
from graphics.SFC_Objects import SFC_Divergence
1853
47a3f39bead0 fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    32
from dialogs.BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    34
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
#                         Create New Divergence Dialog
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    36
# -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    38
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    39
class SFCDivergenceDialog(BlockPreviewDialog):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    40
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    41
    Class that implements a dialog for defining parameters for creating a new
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    42
    divergence graphic element
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    43
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    44
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    45
    def __init__(self, parent, controller, tagname, poss_div_types=None):
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    46
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    47
        Constructor
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    48
        @param parent: Parent wx.Window of dialog for modal
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    49
        @param controller: Reference to project controller
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    50
        @param tagname: Tagname of project POU edited
1584
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    51
        @param poss_div_types: Types of divergence that will be available in the dialog window
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    52
        """
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1585
diff changeset
    53
        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: 1757
diff changeset
    54
                                    title=_('Create a new divergence or convergence'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    55
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    56
        # Init common sizers
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    57
        self._init_sizers(2, 0, 7, None, 2, 1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    58
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    59
        # Create label for divergence type
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    60
        type_label = wx.StaticText(self, label=_('Type:'))
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    61
        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
    62
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    63
        # Create radio buttons for selecting divergence type
1584
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    64
        divergence_buttons = [
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    65
            (SELECTION_DIVERGENCE, _('Selection Divergence')),
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    66
            (SELECTION_CONVERGENCE, _('Selection Convergence')),
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    67
            (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')),
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    68
            (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))]
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    69
        poss_div_btns = []
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    70
        if poss_div_types is not None:
1757
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
    71
            for val in poss_div_types:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
    72
                poss_div_btns.append(divergence_buttons[val])
1584
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    73
        else:
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    74
            poss_div_btns = divergence_buttons
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    75
        self.TypeRadioButtons = {}
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    76
        first = True
1584
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    77
        focusbtn = None
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
    78
        for type, label in poss_div_btns:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    79
            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: 1757
diff changeset
    80
                                          style=(wx.RB_GROUP if first else 0))
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    81
            radio_button.SetValue(first)
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    82
            self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    83
            self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    84
            self.TypeRadioButtons[type] = radio_button
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    85
            if first:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
    86
                focusbtn = type
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    87
            first = False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    89
        # Create label for number of divergence sequences
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    90
        sequences_label = wx.StaticText(self,
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
    91
                                        label=_('Number of sequences:'))
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    92
        self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    93
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    94
        # Create spin control for defining number of divergence sequences
1585
60c0db313ec9 fix initial(equal to the min) number of sequences in SFC Divergence dialog.
Sergey Surkov <surkovsv93@gmail.com>
parents: 1584
diff changeset
    95
        self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences)
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    97
        self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    98
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
    99
        # Add preview panel and associated label to sizers
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   100
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   101
        self.RightGridSizer.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
   102
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   103
        # 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: 1757
diff changeset
   104
        self.MainSizer.AddSizer(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
   105
            self.ButtonSizer, border=20,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
   106
            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: 1696
diff changeset
   107
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1585
diff changeset
   108
        self.Fit()
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1585
diff changeset
   109
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   110
        # Selection divergence radio button is default control having keyboard
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   111
        # focus
1584
431f4ef34bde make only correct blocks(by IEC 61131-3 standard) available in wire popup menu in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents: 1571
diff changeset
   112
        self.TypeRadioButtons[focusbtn].SetFocus()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   113
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   114
    def GetMinElementSize(self):
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   115
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   116
        Get minimal graphic element size
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   117
        @return: Tuple containing minimal size (width, height) or None if no
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   118
        element defined
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   119
        """
1259
8350222a81c3 Added support for adding graphic element when dropping wire in midair
Laurent Bessard
parents: 1251
diff changeset
   120
        return self.Element.GetMinSize(True)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   121
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   122
    def GetDivergenceType(self):
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   123
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   124
        Return type selected for SFC divergence
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   125
        @return: Type selected (None if not found)
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   126
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   127
        # Go through radio buttons and return type associated to the one that
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   128
        # is selected
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   129
        for type, control in self.TypeRadioButtons.iteritems():
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   130
            if control.GetValue():
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   131
                return type
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   132
        return None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   133
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
    def GetValues(self):
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   135
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   136
        Set default SFC divergence parameters
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   137
        @param values: Divergence parameters values
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   138
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   139
        return {"type": self.GetDivergenceType(),
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   140
                "number": self.Sequences.GetValue()}
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 OnTypeChanged(self, event):
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   143
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   144
        Called when SFC divergence type changed
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   145
        @param event: wx.RadioButtonEvent
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   146
        """
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
   147
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
    def OnSequencesChanged(self, event):
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   151
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   152
        Called when SFC divergence number of sequences changed
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   153
        @param event: wx.SpinEvent
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   154
        """
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
   155
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   157
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: 1853
diff changeset
   158
    def DrawPreview(self):
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   159
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   160
        Refresh preview panel of graphic element
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   161
        Override BlockPreviewDialog function
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   162
        """
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   163
        # Set graphic element displayed, creating a SFC divergence
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   164
        self.Element = SFC_Divergence(self.Preview,
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   165
                                      self.GetDivergenceType(),
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   166
                                      self.Sequences.GetValue())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   167
1251
d9ed42e44a50 Rewrite SFCDivergenceDialog
Laurent Bessard
parents: 814
diff changeset
   168
        # 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: 1853
diff changeset
   169
        BlockPreviewDialog.DrawPreview(self)