dialogs/FBDBlockDialog.py
author Laurent Bessard
Tue, 17 Jul 2012 21:20:09 +0200
changeset 726 300ced19d03c
parent 725 7c44fc339889
child 741 330f578e228d
permissions -rw-r--r--
Fixing bug with wheel mouse on GraphicViewer
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     3
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     5
#based on the plcopen standard. 
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     6
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     8
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
     9
#See COPYING file for copyrights details.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    10
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    15
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    19
#General Public License for more details.
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    20
#
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    24
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    25
import wx
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    26
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    27
from graphics import *
725
7c44fc339889 Fix bug with FBDBlockDialog on Beremiz
Laurent Bessard
parents: 714
diff changeset
    28
from controls.LibraryPanel import LibraryPanel
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    29
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    30
#-------------------------------------------------------------------------------
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    31
#                          Create New Block Dialog
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    32
#-------------------------------------------------------------------------------
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    33
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    34
class FBDBlockDialog(wx.Dialog):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    35
    
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    36
    def __init__(self, parent, controller):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    37
        wx.Dialog.__init__(self, parent,
725
7c44fc339889 Fix bug with FBDBlockDialog on Beremiz
Laurent Bessard
parents: 714
diff changeset
    38
              size=wx.Size(600, 450), title=_('Block Properties'))
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    39
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    40
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    41
        main_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    42
        main_sizer.AddGrowableRow(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    43
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    44
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    45
        main_sizer.AddSizer(column_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    46
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    47
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    48
        type_staticbox = wx.StaticBox(self, label=_('Type:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    49
        left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    50
        column_sizer.AddSizer(left_staticboxsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    51
              flag=wx.GROW|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    52
        
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
    53
        self.LibraryPanel = LibraryPanel(self)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    54
        self.LibraryPanel.SetController(controller)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    55
        setattr(self.LibraryPanel, "_OnTreeItemSelected", 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    56
              self.OnLibraryTreeItemSelected)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    57
        left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    58
              flag=wx.GROW|wx.TOP)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    59
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    60
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    61
        right_gridsizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    62
        right_gridsizer.AddGrowableRow(2)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    63
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    64
              flag=wx.GROW|wx.LEFT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    65
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    66
        top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    67
        top_right_gridsizer.AddGrowableCol(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    68
        right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    69
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    70
        name_label = wx.StaticText(self, label=_('Name:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    71
        top_right_gridsizer.AddWindow(name_label, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    72
              flag=wx.ALIGN_CENTER_VERTICAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    73
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    74
        self.BlockName = wx.TextCtrl(self)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    75
        self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    76
        top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    77
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    78
        inputs_label = wx.StaticText(self, label=_('Inputs:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    79
        top_right_gridsizer.AddWindow(inputs_label, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    80
              flag=wx.ALIGN_CENTER_VERTICAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    81
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    82
        self.Inputs = wx.SpinCtrl(self, min=2, max=20,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    83
              style=wx.SP_ARROW_KEYS)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    84
        self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    85
        top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    86
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    87
        execution_order_label = wx.StaticText(self, label=_('Execution Order:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    88
        top_right_gridsizer.AddWindow(execution_order_label, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    89
              flag=wx.ALIGN_CENTER_VERTICAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    90
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    91
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    92
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, self.ExecutionOrder)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    93
        top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    94
                
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    95
        execution_control_label = wx.StaticText(self, label=_('Execution Control:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    96
        top_right_gridsizer.AddWindow(execution_control_label, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    97
              flag=wx.ALIGN_CENTER_VERTICAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    98
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
    99
        self.ExecutionControl = wx.CheckBox(self)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   100
        self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, self.ExecutionControl)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   101
        top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   102
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   103
        preview_label = wx.StaticText(self, label=_('Preview:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   104
        right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   105
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   106
        self.Preview = wx.Panel(self,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   107
              style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   108
        self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   109
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   110
        setattr(self.Preview, "GetScaling", lambda:None)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   111
        setattr(self.Preview, "GetBlockType", controller.GetBlockType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   112
        setattr(self.Preview, "IsOfType", controller.IsOfType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   113
        self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   114
        right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   115
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   116
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   117
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   118
        main_sizer.AddSizer(button_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   119
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   120
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   121
        self.SetSizer(main_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   122
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   123
        self.Controller = controller
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   124
        
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   125
        self.BlockName.SetValue("")
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   126
        self.BlockName.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   127
        self.Inputs.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   128
        self.Block = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   129
        self.MinBlockSize = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   130
        self.First = True
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   131
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   132
        self.PouNames = []
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   133
        self.PouElementNames = []
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   134
        
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   135
        self.LibraryPanel.SetFocus()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   136
    
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   137
    def SetBlockList(self, blocklist):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   138
        self.LibraryPanel.SetBlockList(blocklist)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
   139
    
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   140
    def SetPreviewFont(self, font):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   141
        self.Preview.SetFont(font)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   142
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   143
    def OnOK(self, event):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   144
        message = None
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   145
        selected = self.LibraryPanel.GetSelectedBlock()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   146
        block_name = self.BlockName.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   147
        name_enabled = self.BlockName.IsEnabled()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   148
        if selected is None:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   149
            message = _("Form isn't complete. Valid block type must be selected!")
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   150
        elif name_enabled and block_name == "":
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   151
            message = _("Form isn't complete. Name must be filled!")
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   152
        elif name_enabled and not TestIdentifier(block_name):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   153
            message = _("\"%s\" is not a valid identifier!") % block_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   154
        elif name_enabled and block_name.upper() in IEC_KEYWORDS:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   155
            message = _("\"%s\" is a keyword. It can't be used!") % block_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   156
        elif name_enabled and block_name.upper() in self.PouNames:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   157
            message = _("\"%s\" pou already exists!") % block_name
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   158
        elif name_enabled and block_name.upper() in self.PouElementNames:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   159
            message = _("\"%s\" element for this pou already exists!") % block_name
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   160
        if message is not None:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   161
            dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   162
            dialog.ShowModal()
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   163
            dialog.Destroy()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   164
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   165
            self.EndModal(wx.ID_OK)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   166
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   167
    def SetMinBlockSize(self, size):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   168
        self.MinBlockSize = size
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   169
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   170
    def SetPouNames(self, pou_names):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   171
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   172
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   173
    def SetPouElementNames(self, element_names):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   174
        self.PouElementNames = [element_name.upper() for element_name in element_names]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   175
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   176
    def SetValues(self, values):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   177
        blocktype = values.get("type", None)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   178
        if blocktype is not None:
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   179
            self.LibraryPanel.SelectTreeItem(blocktype, values.get("inputs", None))
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   180
        for name, value in values.items():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   181
            if name == "name":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   182
                self.BlockName.SetValue(value)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   183
            elif name == "extension":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   184
                self.Inputs.SetValue(value)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   185
            elif name == "executionOrder":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   186
                self.ExecutionOrder.SetValue(value)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   187
            elif name == "executionControl":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   188
                   self.ExecutionControl.SetValue(value)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   189
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   190
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   191
    def GetValues(self):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   192
        values = self.LibraryPanel.GetSelectedBlock()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   193
        if self.BlockName.GetValue() != "":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   194
            values["name"] = self.BlockName.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   195
        values["width"], values["height"] = self.Block.GetSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   196
        values["extension"] = self.Inputs.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   197
        values["executionOrder"] = self.ExecutionOrder.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   198
        values["executionControl"] = self.ExecutionControl.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   199
        return values
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   200
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   201
    def OnLibraryTreeItemSelected(self, event):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   202
        values = self.LibraryPanel.GetSelectedBlock()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   203
        if values is not None:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   204
            blocktype = self.Controller.GetBlockType(values["type"], values["inputs"])
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   205
        else:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   206
            blocktype = None
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   207
        if blocktype is not None:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   208
            self.Inputs.SetValue(len(blocktype["inputs"]))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   209
            self.Inputs.Enable(blocktype["extensible"])
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   210
            self.BlockName.Enable(blocktype["type"] != "function")
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   211
            wx.CallAfter(self.RefreshPreview)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   212
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   213
            self.BlockName.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   214
            self.Inputs.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   215
            self.Inputs.SetValue(2)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   216
            wx.CallAfter(self.ErasePreview)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   217
    
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   218
    def OnNameChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   219
        if self.BlockName.IsEnabled():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   220
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   221
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   222
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   223
    def OnInputsChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   224
        if self.Inputs.IsEnabled():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   225
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   226
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   227
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   228
    def OnExecutionOrderChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   229
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   230
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   231
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   232
    def OnExecutionControlChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   233
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   234
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   235
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   236
    def ErasePreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   237
        dc = wx.ClientDC(self.Preview)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   238
        dc.Clear()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   239
        self.Block = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   240
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   241
    def RefreshPreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   242
        dc = wx.ClientDC(self.Preview)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   243
        dc.SetFont(self.Preview.GetFont())
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   244
        dc.Clear()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   245
        values = self.LibraryPanel.GetSelectedBlock()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   246
        if values is not None:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   247
            self.Block = FBD_Block(self.Preview, values["type"], 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   248
                    self.BlockName.GetValue(), 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   249
                    extension = self.Inputs.GetValue(), 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   250
                    inputs = values["inputs"], 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   251
                    executionControl = self.ExecutionControl.GetValue(), 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   252
                    executionOrder = self.ExecutionOrder.GetValue())
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   253
            width, height = self.MinBlockSize
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   254
            min_width, min_height = self.Block.GetMinSize()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   255
            width, height = max(min_width, width), max(min_height, height)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   256
            self.Block.SetSize(width, height)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   257
            clientsize = self.Preview.GetClientSize()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   258
            x = (clientsize.width - width) / 2
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   259
            y = (clientsize.height - height) / 2
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   260
            self.Block.SetPosition(x, y)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   261
            self.Block.Draw(dc)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   262
        else:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   263
            self.Block = None        
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   264
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   265
    def OnPaint(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   266
        if self.Block is not None:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   267
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   268
        event.Skip()