dialogs/FBDBlockDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 16 Aug 2017 12:53:23 +0300
changeset 1750 acf02488f37f
parent 1745 f9d32913bad4
child 1768 691083b5682a
permissions -rwxr-xr-x
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
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: 1327
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: 1327
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: 1327
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
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: 1327
diff changeset
     9
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
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: 1327
diff changeset
    11
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
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: 1327
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: 1327
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: 1327
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: 1327
diff changeset
    16
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
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: 1327
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: 1327
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: 1327
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: 1327
diff changeset
    21
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1327
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: 1327
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: 1327
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
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    26
import re
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
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
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    30
from graphics.FBD_Objects import FBD_Block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
from controls.LibraryPanel import LibraryPanel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    32
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
#-------------------------------------------------------------------------------
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    35
#                                    Helpers
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    36
#-------------------------------------------------------------------------------
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    37
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    39
def GetBlockTypeDefaultNameModel(blocktype):
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    40
    return re.compile("%s[0-9]+" % blocktype if blocktype is not None else ".*")
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    41
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
    42
#-------------------------------------------------------------------------------
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    43
#                         Set Block Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    46
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    47
class FBDBlockDialog(BlockPreviewDialog):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    48
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    49
    Class that implements a dialog for defining parameters of a FBD block graphic
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    50
    element
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    51
    """
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    52
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    53
    def __init__(self, parent, controller, tagname):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    54
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    55
        Constructor
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    56
        @param parent: Parent wx.Window of dialog for modal
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    57
        @param controller: Reference to project controller
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    58
        @param tagname: Tagname of project POU edited
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    59
        """
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    60
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    61
              title=_('Block Properties'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    62
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    63
        # Init common sizers
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    64
        self._init_sizers(2, 0, 1, 0, 3, 2)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    65
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    66
        # Create static box around library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
        left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    69
        self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    70
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    71
        # Create Library panel and add it to static box
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
        self.LibraryPanel = LibraryPanel(self)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    73
        self.LibraryPanel.SetInitialSize(wx.Size(-1, 400))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    74
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    75
        # Set function to call when selection in Library panel changed
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    76
        setattr(self.LibraryPanel, "_OnTreeItemSelected",
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
              self.OnLibraryTreeItemSelected)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    78
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
    79
              flag=wx.GROW | wx.TOP)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    80
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    81
        # Create sizer for other block parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        top_right_gridsizer.AddGrowableCol(1)
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
    84
        self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    85
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    86
        # Create label for block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        name_label = wx.StaticText(self, label=_('Name:'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    88
        top_right_gridsizer.AddWindow(name_label,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
              flag=wx.ALIGN_CENTER_VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    90
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    91
        # Create text control for defining block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        self.BlockName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    95
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    96
        # Create label for extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    98
        top_right_gridsizer.AddWindow(inputs_label,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
              flag=wx.ALIGN_CENTER_VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   100
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   101
        # Create spin control for defining extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   106
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   107
        # Create label for block execution order
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   108
        execution_order_label = wx.StaticText(self,
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   109
              label=_('Execution Order:'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   110
        top_right_gridsizer.AddWindow(execution_order_label,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
              flag=wx.ALIGN_CENTER_VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   112
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   113
        # Create spin control for defining block execution order
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   115
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged,
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   116
                  self.ExecutionOrder)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   118
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   119
        # Create label for block execution control
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   120
        execution_control_label = wx.StaticText(self,
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   121
              label=_('Execution Control:'))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   122
        top_right_gridsizer.AddWindow(execution_control_label,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
              flag=wx.ALIGN_CENTER_VERTICAL)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   124
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   125
        # Create check box to enable block execution control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        self.ExecutionControl = wx.CheckBox(self)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   127
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged,
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   128
                  self.ExecutionControl)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   130
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   131
        # Add preview panel and associated label to sizers
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   132
        self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   133
        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
   134
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   135
        # Add buttons sizer to sizers
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   136
        self.MainSizer.AddSizer(self.ButtonSizer, border=20,
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   137
              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
   138
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   139
        # Dictionary containing correspondence between parameter exchanged and
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   140
        # control to fill with parameter value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   141
        self.ParamsControl = {
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   142
            "extension": self.Inputs,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   143
            "executionOrder": self.ExecutionOrder,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   144
            "executionControl": self.ExecutionControl
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   145
        }
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   146
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   147
        # Init controls value and sensibility
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
        self.BlockName.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
        self.BlockName.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        self.Inputs.Enable(False)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   151
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   152
        # Variable containing last name typed
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   153
        self.CurrentBlockName = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   154
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   155
        # Refresh Library panel values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   156
        self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   157
        self.Fit()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        self.LibraryPanel.SetFocus()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   159
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
    def SetValues(self, values):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   161
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   162
        Set default block parameters
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   163
        @param values: Block parameters values
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   164
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   165
        # Extract block type defined in parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
        blocktype = values.get("type", None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   167
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   168
        # Select block type in library panel
1327
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   169
        if blocktype is not None:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   170
            self.LibraryPanel.SelectTreeItem(blocktype,
1327
632780979432 Fixed bug when editing block information of an extended standard function
Laurent Bessard
parents: 1250
diff changeset
   171
                                             values.get("inputs", None))
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   172
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   173
        # Define regular expression for determine if block name is block
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   174
        # default name
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   175
        default_name_model = GetBlockTypeDefaultNameModel(blocktype)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   176
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   177
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        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
   179
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   180
            # Parameter is block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
            if name == "name":
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   182
                if value != "":
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   183
                    # Set default graphic element name for testing
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   184
                    self.DefaultElementName = value
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   185
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   186
                    # Test if block name is type default block name and save
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   187
                    # block name if not (name have been typed by user)
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   188
                    if default_name_model.match(value) is None:
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   189
                        self.CurrentBlockName = value
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   190
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   191
                self.BlockName.ChangeValue(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   192
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   193
            # Set value of other controls
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   194
            else:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   195
                control = self.ParamsControl.get(name, None)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   196
                if control is not None:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   197
                    control.SetValue(value)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   198
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   199
        # Refresh preview panel
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
    def GetValues(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   203
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   204
        Return block parameters defined in dialog
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   205
        @return: {parameter_name: parameter_value,...}
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   206
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
            values["name"] = self.BlockName.GetValue()
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   210
        values["width"], values["height"] = self.Element.GetSize()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   211
        values.update({
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   212
            name: control.GetValue()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   213
            for name, control in self.ParamsControl.iteritems()})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
        return values
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   215
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   216
    def OnOK(self, event):
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   217
        """
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   218
        Called when dialog OK button is pressed
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   219
        Test if parameters defined are valid
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   220
        @param event: wx.Event from OK button
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   221
        """
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   222
        message = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   223
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   224
        # Get block type selected
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   225
        selected = self.LibraryPanel.GetSelectedBlock()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   226
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   227
        # Get block type name and if block is a function block
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   228
        block_name = self.BlockName.GetValue()
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   229
        name_enabled = self.BlockName.IsEnabled()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   230
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   231
        # Test that a type has been selected for block
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   232
        if selected is None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   233
            message = _("Form isn't complete. Valid block type must be selected!")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   234
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   235
        # Test, if block is a function block, that a name have been defined
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   236
        elif name_enabled and block_name == "":
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   237
            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
   238
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   239
        # Show error message if an error is detected
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   240
        if message is not None:
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   241
            self.ShowErrorMessage(message)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   242
1250
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   243
        # Test block name validity if necessary
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   244
        elif not name_enabled or self.TestElementName(block_name):
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   245
            # Call BlockPreviewDialog function
7e6de17c687a Rewrite SFCStepDialog and factorize code for creating common dialog sizers
Laurent Bessard
parents: 1244
diff changeset
   246
            BlockPreviewDialog.OnOK(self, event)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   247
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
    def OnLibraryTreeItemSelected(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   249
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   250
        Called when block type selected in library panel
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   251
        @param event: wx.TreeEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   252
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   253
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
        values = self.LibraryPanel.GetSelectedBlock()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   255
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   256
        # Get block type informations
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   257
        blocktype = (self.Controller.GetBlockType(values["type"],
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   258
                                                  values["inputs"])
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   259
                     if values is not None else None)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   260
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   261
        # Set input number spin control according to block type informations
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
        if blocktype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
            self.Inputs.SetValue(len(blocktype["inputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
            self.Inputs.Enable(blocktype["extensible"])
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   265
        else:
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   266
            self.Inputs.SetValue(2)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   267
            self.Inputs.Enable(False)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   268
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   269
        # Update block name with default value if block type is a function and
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   270
        # current block name wasn't typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   271
        if blocktype is not None and blocktype["type"] != "function":
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   272
            self.BlockName.Enable(True)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   273
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   274
            if self.CurrentBlockName is None:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   275
                # Generate new block name according to block type, taking
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   276
                # default element name if it was already a default name for this
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   277
                # block type
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   278
                default_name_model = GetBlockTypeDefaultNameModel(values["type"])
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   279
                block_name = (
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   280
                    self.DefaultElementName
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   281
                    if (self.DefaultElementName is not None and
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   282
                        default_name_model.match(self.DefaultElementName))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   283
                    else self.Controller.GenerateNewName(
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   284
                        self.TagName, None, values["type"]+"%d", 0))
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   285
            else:
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   286
                block_name = self.CurrentBlockName
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   287
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   288
            self.BlockName.ChangeValue(block_name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
            self.BlockName.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   291
            self.BlockName.ChangeValue("")
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   292
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   293
        # Refresh preview panel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   294
        self.RefreshPreview()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   295
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
    def OnNameChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   297
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   298
        Called when block name value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   299
        @param event: wx.TextEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   300
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
        if self.BlockName.IsEnabled():
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   302
            # Save block name typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   303
            self.CurrentBlockName = self.BlockName.GetValue()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   306
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
    def OnInputsChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   308
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   309
        Called when block inputs number changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   310
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   311
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
        if self.Inputs.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   315
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
    def OnExecutionOrderChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   317
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   318
        Called when block execution order value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   319
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   320
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   323
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
    def OnExecutionControlChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   325
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   326
        Called when block execution control value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   327
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   328
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
        event.Skip()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   331
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
    def RefreshPreview(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   333
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   334
        Refresh preview panel of graphic element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   335
        Override BlockPreviewDialog function
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   336
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   337
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
        values = self.LibraryPanel.GetSelectedBlock()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   339
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   340
        # If a block type is selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
        if values is not None:
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   342
            # Set graphic element displayed, creating a FBD block element
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   343
            self.Element = FBD_Block(self.Preview, values["type"],
1244
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   344
                    (self.BlockName.GetValue()
336d515096b1 Rewrite FBDVariableDialog
Laurent Bessard
parents: 1242
diff changeset
   345
                     if self.BlockName.IsEnabled()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   346
                     else ""),
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   347
                    extension=self.Inputs.GetValue(),
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   348
                    inputs=values["inputs"],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   349
                    executionControl=self.ExecutionControl.GetValue(),
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   350
                    executionOrder=self.ExecutionOrder.GetValue())
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   351
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   352
        # Reset graphic element displayed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
        else:
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   354
            self.Element = None
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   355
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   356
        # Call BlockPreviewDialog function
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   357
        BlockPreviewDialog.RefreshPreview(self)