dialogs/FBDVariableDialog.py
author Laurent Bessard
Fri, 13 Jul 2012 12:42:02 +0200
changeset 724 57b6446d54f8
parent 714 131ea7f237b9
child 741 330f578e228d
permissions -rw-r--r--
Adding support for using middle button for moving debug graph
Adding button for resetting zoom and of position of debug graph
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 *
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    28
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    29
#-------------------------------------------------------------------------------
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    30
#                                    Helpers
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    31
#-------------------------------------------------------------------------------
409
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
VARIABLE_CLASSES_DICT = {INPUT : _("Input"),
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    34
                         INOUT : _("InOut"),
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    35
                         OUTPUT : _("Output")}
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    36
VARIABLE_CLASSES_DICT_REVERSE = dict(
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    37
    [(value, key) for key, value in VARIABLE_CLASSES_DICT.iteritems()])
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    38
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    39
#-------------------------------------------------------------------------------
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    40
#                          Create New Variable Dialog
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    41
#-------------------------------------------------------------------------------
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    42
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
    43
class FBDVariableDialog(wx.Dialog):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    44
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    45
    def __init__(self, parent, controller, transition = ""):
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    46
        wx.Dialog.__init__(self, parent,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    47
              size=wx.Size(400, 380), title=_('Variable Properties'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    48
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    49
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    50
        main_sizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    51
        main_sizer.AddGrowableRow(2)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    52
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    53
        column_sizer = wx.BoxSizer(wx.HORIZONTAL)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    54
        main_sizer.AddSizer(column_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    55
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    56
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    57
        left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    58
        left_gridsizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    59
        column_sizer.AddSizer(left_gridsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    60
              flag=wx.GROW|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    61
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    62
        class_label = wx.StaticText(self, label=_('Class:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    63
        left_gridsizer.AddWindow(class_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    64
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    65
        self.Class = wx.ComboBox(self, style=wx.CB_READONLY)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    66
        self.Bind(wx.EVT_COMBOBOX, self.OnClassChanged, self.Class)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    67
        left_gridsizer.AddWindow(self.Class, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    68
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    69
        expression_label = wx.StaticText(self, label=_('Expression:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    70
        left_gridsizer.AddWindow(expression_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    71
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    72
        self.Expression = wx.TextCtrl(self)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    73
        self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, self.Expression)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    74
        left_gridsizer.AddWindow(self.Expression, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    75
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    76
        execution_order_label = wx.StaticText(self, label=_('Execution Order:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    77
        left_gridsizer.AddWindow(execution_order_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    78
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    79
        self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    80
        self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, self.ExecutionOrder)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    81
        left_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    82
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    83
        right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    84
        right_gridsizer.AddGrowableCol(0)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    85
        right_gridsizer.AddGrowableRow(1)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    86
        column_sizer.AddSizer(right_gridsizer, 1, border=5, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    87
              flag=wx.GROW|wx.LEFT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    88
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    89
        name_label = wx.StaticText(self, label=_('Name:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    90
        right_gridsizer.AddWindow(name_label, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    91
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    92
        self.VariableName = wx.ListBox(self, style=wx.LB_SINGLE|wx.LB_SORT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    93
        self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    94
        right_gridsizer.AddWindow(self.VariableName, flag=wx.GROW)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    95
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    96
        preview_label = wx.StaticText(self, label=_('Preview:'))
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    97
        main_sizer.AddWindow(preview_label, border=20,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    98
              flag=wx.GROW|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
    99
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   100
        self.Preview = wx.Panel(self, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   101
              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
   102
        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
   103
        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
   104
        setattr(self.Preview, "GetScaling", lambda:None)
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   105
        setattr(self.Preview, "IsOfType", controller.IsOfType)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   106
        self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   107
        main_sizer.AddWindow(self.Preview, border=20,
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   108
              flag=wx.GROW|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   109
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   110
        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   111
        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   112
        main_sizer.AddSizer(button_sizer, border=20, 
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   113
              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   114
        
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   115
        self.SetSizer(main_sizer)
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   116
        
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   117
        self.Transition = transition
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   118
        self.Variable = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   119
        self.VarList = []
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   120
        self.MinVariableSize = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   121
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   122
        for choice in VARIABLE_CLASSES_DICT.itervalues():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   123
            self.Class.Append(choice)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   124
        self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[INPUT])
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   125
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   126
        self.RefreshNameList()
577
9dbb79722fbc Adding support for giving keyboard focus to the first control of every dialogs
laurent
parents: 534
diff changeset
   127
        self.Class.SetFocus()
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   128
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   129
    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
   130
        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
   131
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   132
    def RefreshNameList(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   133
        selected = self.VariableName.GetStringSelection()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   134
        var_class = VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   135
        self.VariableName.Clear()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   136
        self.VariableName.Append("")
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   137
        for name, var_type, value_type in self.VarList:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   138
            if var_type != "Input" or var_class == INPUT:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   139
                self.VariableName.Append(name)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   140
        if selected != "" and self.VariableName.FindString(selected) != wx.NOT_FOUND:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   141
            self.VariableName.SetStringSelection(selected)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   142
            self.Expression.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   143
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   144
            self.VariableName.SetStringSelection("")
488
93bf600bae11 Bug not refreshing FileMenu when Undo/Redo fixed
laurent
parents: 409
diff changeset
   145
            #self.Expression.Enable(var_class == INPUT)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   146
        self.VariableName.Enable(self.VariableName.GetCount() > 0)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   147
            
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   148
    def SetMinVariableSize(self, size):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   149
        self.MinVariableSize = size
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   150
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   151
    def SetVariables(self, vars):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   152
        self.VarList = vars
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   153
        self.RefreshNameList()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   154
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   155
    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
   156
        value_type = 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
   157
        value_name = values.get("name", None)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   158
        if value_type:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   159
            self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[value_type])
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   160
            self.RefreshNameList()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   161
        if value_name:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   162
            if self.VariableName.FindString(value_name) != wx.NOT_FOUND:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   163
                self.VariableName.SetStringSelection(value_name)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   164
                self.Expression.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   165
            else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   166
                self.Expression.SetValue(value_name)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   167
                self.VariableName.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   168
        if "executionOrder" in values:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   169
            self.ExecutionOrder.SetValue(values["executionOrder"])
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   170
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   171
        
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   172
    def GetValues(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   173
        values = {}
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   174
        values["type"] = VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   175
        expression = self.Expression.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   176
        if self.Expression.IsEnabled() and expression != "":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   177
            values["name"] = expression
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   178
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   179
            values["name"] = self.VariableName.GetStringSelection()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   180
        values["value_type"] = None
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   181
        for var_name, var_type, value_type in self.VarList:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   182
            if var_name == values["name"]:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   183
                values["value_type"] = value_type
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   184
        values["width"], values["height"] = self.Variable.GetSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   185
        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
   186
        return values
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   187
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   188
    def OnOK(self, event):
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   189
        message = None
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   190
        expression = self.Expression.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   191
        if self.Expression.IsEnabled():
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   192
            value = expression
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   193
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   194
            value = self.VariableName.GetStringSelection()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   195
        if value == "":
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   196
            message = _("At least a variable or an expression 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
   197
        elif value.upper() in IEC_KEYWORDS:
714
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   198
            message = _("\"%s\" is a keyword. It can't be used!") % value
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   199
        if message is not None:
131ea7f237b9 Replacing buttons with text by buttons with icons
Laurent Bessard
parents: 577
diff changeset
   200
            message = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   201
            message.ShowModal()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   202
            message.Destroy()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   203
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   204
            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
   205
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   206
    def OnClassChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   207
        self.RefreshNameList()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   208
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   209
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   210
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   211
    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
   212
        if self.VariableName.GetStringSelection() != "":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   213
            self.Expression.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   214
        elif VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()] == INPUT:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   215
            self.Expression.Enable(True)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   216
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   217
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   218
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   219
    def OnExpressionChanged(self, event):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   220
        if self.Expression.GetValue() != "":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   221
            self.VariableName.Enable(False)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   222
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   223
            self.VariableName.Enable(True)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   224
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   225
        event.Skip()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   226
    
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   227
    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
   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 RefreshPreview(self):
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   232
        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
   233
        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
   234
        dc.Clear()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   235
        expression = self.Expression.GetValue()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   236
        if self.Expression.IsEnabled() and expression != "":
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   237
            name = expression
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   238
        else:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   239
            name = self.VariableName.GetStringSelection()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   240
        type = ""
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   241
        for var_name, var_type, value_type in self.VarList:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   242
            if var_name == name:
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   243
                type = value_type
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   244
        classtype = VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()]
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   245
        self.Variable = FBD_Variable(self.Preview, classtype, name, type, 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
   246
        width, height = self.MinVariableSize
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   247
        min_width, min_height = self.Variable.GetMinSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   248
        width, height = max(min_width, width), max(min_height, height)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   249
        self.Variable.SetSize(width, height)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   250
        clientsize = self.Preview.GetClientSize()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   251
        x = (clientsize.width - width) / 2
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   252
        y = (clientsize.height - height) / 2
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   253
        self.Variable.SetPosition(x, y)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   254
        self.Variable.Draw(dc)
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   255
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   256
    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
   257
        self.RefreshPreview()
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents:
diff changeset
   258
        event.Skip()