dialogs/FBDBlockDialog.py
author Laurent Bessard
Tue, 04 Sep 2012 11:31:21 +0200
changeset 755 1d77d700761f
parent 746 963123fb4917
permissions -rw-r--r--
Fix bug when trying to launch Inkscape and not installed. No error message was displayed on Windows.
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)
743
75576aea4555 Fix bugs with Viewer objects dialogs
Laurent Bessard
parents: 741
diff changeset
   117
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
714
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
    
741
330f578e228d Fix bugs with Viewer objects dialogs
Laurent Bessard
parents: 725
diff changeset
   137
    def __del__(self):
330f578e228d Fix bugs with Viewer objects dialogs
Laurent Bessard
parents: 725
diff changeset
   138
        self.Controller = None
330f578e228d Fix bugs with Viewer objects dialogs
Laurent Bessard
parents: 725
diff changeset
   139
    
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   140
    def SetBlockList(self, blocklist):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   141
        self.LibraryPanel.SetBlockList(blocklist)
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
   142
    
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   143
    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
   144
        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
   145
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   146
    def OnOK(self, event):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   147
        message = None
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   148
        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
   149
        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
   150
        name_enabled = self.BlockName.IsEnabled()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   151
        if selected is None:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   152
            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
   153
        elif name_enabled and block_name == "":
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   154
            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
   155
        elif name_enabled and not TestIdentifier(block_name):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   156
            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
   157
        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
   158
            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
   159
        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
   160
            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
   161
        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
   162
            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
   163
        if message is not None:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   164
            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
   165
            dialog.ShowModal()
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   166
            dialog.Destroy()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   167
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   168
            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
   169
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   170
    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
   171
        self.MinBlockSize = size
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 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
   174
        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
   175
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   176
    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
   177
        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
   178
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   179
    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
   180
        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
   181
        if blocktype is not None:
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   182
            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
   183
        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
   184
            if name == "name":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   185
                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
   186
            elif name == "extension":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   187
                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
   188
            elif name == "executionOrder":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   189
                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
   190
            elif name == "executionControl":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   191
                   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
   192
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   193
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   194
    def GetValues(self):
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   195
        values = self.LibraryPanel.GetSelectedBlock()
746
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   196
        if self.BlockName.IsEnabled() and self.BlockName.GetValue() != "":
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   197
            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
   198
        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
   199
        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
   200
        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
   201
        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
   202
        return values
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   203
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   204
    def OnLibraryTreeItemSelected(self, event):
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   205
        values = self.LibraryPanel.GetSelectedBlock()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   206
        if values is not None:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 676
diff changeset
   207
            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
   208
        else:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   209
            blocktype = None
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   210
        if blocktype is not None:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   211
            self.Inputs.SetValue(len(blocktype["inputs"]))
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   212
            self.Inputs.Enable(blocktype["extensible"])
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   213
            self.BlockName.Enable(blocktype["type"] != "function")
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   214
            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
   215
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   216
            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
   217
            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
   218
            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
   219
            wx.CallAfter(self.ErasePreview)
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   220
    
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   221
    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
   222
        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
   223
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   224
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   225
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   226
    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
   227
        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
   228
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   229
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   230
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   231
    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
   232
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   233
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   234
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   235
    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
   236
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   237
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   238
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   239
    def ErasePreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   240
        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
   241
        dc.Clear()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   242
        self.Block = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   243
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   244
    def RefreshPreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   245
        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
   246
        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
   247
        dc.Clear()
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   248
        values = self.LibraryPanel.GetSelectedBlock()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   249
        if values is not None:
746
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   250
            if self.BlockName.IsEnabled():
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   251
                blockname = self.BlockName.GetValue()
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   252
            else:
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   253
                blockname = ""
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   254
            self.Block = FBD_Block(self.Preview, values["type"], 
746
963123fb4917 Fix bug name kept when changing a function block to a function
Laurent Bessard
parents: 743
diff changeset
   255
                    blockname, 
676
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   256
                    extension = self.Inputs.GetValue(), 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   257
                    inputs = values["inputs"], 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   258
                    executionControl = self.ExecutionControl.GetValue(), 
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   259
                    executionOrder = self.ExecutionOrder.GetValue())
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   260
            width, height = self.MinBlockSize
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   261
            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
   262
            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
   263
            self.Block.SetSize(width, height)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   264
            clientsize = self.Preview.GetClientSize()
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   265
            x = (clientsize.width - width) / 2
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   266
            y = (clientsize.height - height) / 2
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   267
            self.Block.SetPosition(x, y)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   268
            self.Block.Draw(dc)
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   269
        else:
0f10f5091245 Adding search field for finding function or function block in library tree
laurent
parents: 646
diff changeset
   270
            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
   271
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   272
    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
   273
        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
   274
            self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   275
        event.Skip()