dialogs/FBDBlockDialog.py
author Laurent Bessard
Tue, 11 Jun 2013 09:03:35 +0200
changeset 1243 e77c95c4c7fc
parent 1242 ec2c415fc65e
child 1244 336d515096b1
permissions -rw-r--r--
Fixed bug when drag'n dropping POU from project tree and POU is selected
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
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    25
import re
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    26
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    29
from graphics.FBD_Objects import FBD_Block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
from controls.LibraryPanel import LibraryPanel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    31
from BlockPreviewDialog import BlockPreviewDialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    34
#                         Set Block Parameters Dialog
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    37
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    38
Class that implements a dialog for defining parameters of a FBD block graphic
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    39
element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    40
"""
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    41
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    42
class FBDBlockDialog(BlockPreviewDialog):
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    43
    
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    44
    def __init__(self, parent, controller, tagname):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    45
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    46
        Constructor
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    47
        @param parent: Parent wx.Window of dialog for modal
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    48
        @param controller: Reference to project controller
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    49
        @param tagname: Tagname of project POU edited
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    50
        """
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
    51
        BlockPreviewDialog.__init__(self, parent, controller, tagname,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
              size=wx.Size(600, 450), title=_('Block Properties'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    54
        # Create dialog main sizer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        main_sizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
        main_sizer.AddGrowableRow(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    59
        # Create a sizer for dividing FBD block parameters in two columns
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        main_sizer.AddSizer(column_sizer, border=20, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    64
        # Create static box around library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
        left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
        column_sizer.AddSizer(left_staticboxsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
              flag=wx.GROW|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    70
        # Create Library panel and add it to static box
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
        self.LibraryPanel = LibraryPanel(self)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    72
        # Set function to call when selection in Library panel changed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
        setattr(self.LibraryPanel, "_OnTreeItemSelected", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
              self.OnLibraryTreeItemSelected)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
              flag=wx.GROW|wx.TOP)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    78
        # Create sizer for other block parameters and preview panle
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
        right_gridsizer.AddGrowableCol(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        right_gridsizer.AddGrowableRow(2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
              flag=wx.GROW|wx.LEFT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    85
        # Create sizer for other block parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
        top_right_gridsizer.AddGrowableCol(1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    90
        # Create label for block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        name_label = wx.StaticText(self, label=_('Name:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        top_right_gridsizer.AddWindow(name_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
    95
        # Create text control for defining block name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        self.BlockName = wx.TextCtrl(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   100
        # Create label for extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        top_right_gridsizer.AddWindow(inputs_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   105
        # Create spin control for defining extended block input number
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
              style=wx.SP_ARROW_KEYS)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   111
        # Create label for block execution order
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   112
        execution_order_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   113
              label=_('Execution Order:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        top_right_gridsizer.AddWindow(execution_order_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   117
        # Create spin control for defining block execution order
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   119
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   120
                  self.ExecutionOrder)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
                
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   123
        # Create label for block execution control
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   124
        execution_control_label = wx.StaticText(self, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   125
              label=_('Execution Control:'))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
        top_right_gridsizer.AddWindow(execution_control_label, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
              flag=wx.ALIGN_CENTER_VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   129
        # Create check box to enable block execution control
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
        self.ExecutionControl = wx.CheckBox(self)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   131
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, 
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   132
                  self.ExecutionControl)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   135
        # Add preview panel and associated label to sizers
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   136
        right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   139
        main_sizer.AddSizer(self.ButtonSizer, border=20, 
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        self.SetSizer(main_sizer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   144
        self.ParamsControl = {
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   145
            "extension": self.Inputs,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   146
            "executionOrder": self.ExecutionOrder,
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   147
            "executionControl": self.ExecutionControl
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   148
        }
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   149
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   150
        # Init controls value and sensibility
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
        self.BlockName.SetValue("")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        self.BlockName.Enable(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        self.Inputs.Enable(False)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   154
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   155
        # Variable containing last name typed
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   156
        self.CurrentBlockName = None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   157
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   158
        # Refresh Library panel values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   159
        self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
        self.LibraryPanel.SetFocus()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
    def OnOK(self, event):
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
        Called when dialog OK button is pressed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   165
        Test if parameters defined are valid
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   166
        @param event: wx.Event from OK button
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   167
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
        message = None
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   169
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   170
        # Get block type selected
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        selected = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   172
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   173
        # Get block type name and if block is a function block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
        block_name = self.BlockName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        name_enabled = self.BlockName.IsEnabled()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   176
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   177
        # Test that a type has been selected for block
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
        if selected is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
            message = _("Form isn't complete. Valid block type must be selected!")
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   180
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   181
        # Test, if block is a function block, that a name have been defined
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
        elif name_enabled and block_name == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
            message = _("Form isn't complete. Name must be filled!")
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   184
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   185
        # Show error message if an error is detected
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        if message is not None:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   187
            self.ShowMessage(message)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   188
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   189
        # Test block name validity if necessary
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   190
        elif not name_enabled or self.TestBlockName(block_name):
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   191
            BlockPreviewDialog.OnOK(self, event)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   192
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
    def SetValues(self, values):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   194
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   195
        Set default block parameters
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   196
        @param values: Block parameters values
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   197
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   198
        # Extract block type defined in parameters
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
        blocktype = values.get("type", None)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   200
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   201
        # Define regular expression for determine if block name is block
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   202
        # default name
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   203
        default_name_model = re.compile(
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   204
            "%s[0-9]+" % blocktype if blocktype is not None else ".*")
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   205
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   206
        # Select block type in library panel    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
        if blocktype is not None:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   208
            self.LibraryPanel.SelectTreeItem(blocktype, 
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   209
                                             values.get("inputs", None))
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   210
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   211
        # For each parameters defined, set corresponding control value
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
        for name, value in values.items():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
            if name == "name":
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   214
                # Parameter is block name
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   215
                if value != "":
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   216
                    # Set default block name for testing
1237
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   217
                    self.DefaultBlockName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   218
                    
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   219
                    # Test if block name is type default block name and save
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   220
                    # 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
   221
                    if default_name_model.match(value) is None:
0c8b8ef9559b Fixed support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1236
diff changeset
   222
                        self.CurrentBlockName = value
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   223
            
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   224
                self.BlockName.ChangeValue(value)
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   225
            
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   226
            else:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   227
                control = self.ParamsControl.get(name, None)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   228
                if control is not None:
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   229
                    control.SetValue(value)
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   230
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   231
        # Refresh preview panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
    def GetValues(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   235
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   236
        Return block parameters defined in dialog
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   237
        @return: {parameter_name: parameter_value,...}
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   238
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        values = self.LibraryPanel.GetSelectedBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
            values["name"] = self.BlockName.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
        values["width"], values["height"] = self.Block.GetSize()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   243
        values.update({
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   244
            name: control.GetValue()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   245
            for name, control in self.ParamsControl.iteritems()})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
        return values
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
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()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   255
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   256
        # Get block type informations
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   257
        blocktype = (self.Controller.GetBlockType(values["type"], 
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)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
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)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
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)
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   273
            self.BlockName.ChangeValue(
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   274
                self.CurrentBlockName
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   275
                if self.CurrentBlockName is not None
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   276
                else self.Controller.GenerateNewName(
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   277
                    self.TagName, None, values["type"]+"%d", 0))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
            self.BlockName.Enable(False)
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   280
            self.BlockName.ChangeValue("")
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   281
        
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   282
        # Refresh preview panel
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   283
        self.RefreshPreview()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
    def OnNameChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   286
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   287
        Called when block name value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   288
        @param event: wx.TextEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   289
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
        if self.BlockName.IsEnabled():
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   291
            # Save block name typed by user
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   292
            self.CurrentBlockName = self.BlockName.GetValue()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
    def OnInputsChanged(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 inputs number changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   299
        @param event: wx.SpinEvent
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.Inputs.IsEnabled():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
            self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
    def OnExecutionOrderChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   306
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   307
        Called when block execution order value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   308
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   309
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
    def OnExecutionControlChanged(self, event):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   314
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   315
        Called when block execution control value changed
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   316
        @param event: wx.SpinEvent
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   317
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
        self.RefreshPreview()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
    def RefreshPreview(self):
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   322
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   323
        Refresh preview panel of graphic element
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   324
        Override BlockPreviewDialog function
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   325
        """
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   326
        # Get type selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
        values = self.LibraryPanel.GetSelectedBlock()
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   328
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   329
        # If a block type is selected in library panel
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
        if values is not None:
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   331
            blockname = (self.BlockName.GetValue()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   332
                         if self.BlockName.IsEnabled()
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   333
                         else "")
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   334
            
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   335
            # Set graphic element displayed, creating a FBD block element
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
            self.Block = FBD_Block(self.Preview, values["type"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
                    blockname, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                    extension = self.Inputs.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
                    inputs = values["inputs"], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
                    executionControl = self.ExecutionControl.GetValue(), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
                    executionOrder = self.ExecutionOrder.GetValue())
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   342
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   343
        # Reset graphic element displayed
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
        else:
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   345
            self.Block = None 
1242
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   346
        
ec2c415fc65e Rewrite FBDBlockDialog and BlockPreviewDialog
Laurent Bessard
parents: 1237
diff changeset
   347
        # Call BlockPreviewDialog function
1236
a5d1d2a2f366 Added support for default function block name in FBDBlockDialog
Laurent Bessard
parents: 1230
diff changeset
   348
        BlockPreviewDialog.RefreshPreview(self)