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