Dialogs.py
author lbessard
Thu, 19 Jul 2007 15:04:41 +0200
changeset 46 4379e98a30aa
parent 45 42637f721b5b
child 56 7187e1c00975
permissions -rw-r--r--
Bug on SFC generation fixed
Adding Action and Transition remove functions
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     3
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     6
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     7
#Copyright (C): Edouard TISSERANT and Laurent BESSARD
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     8
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    10
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    15
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    19
#Lesser General Public License for more details.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    20
#
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    24
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    25
from wxPython.wx import *
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    26
from wxPython.grid import *
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    27
import wx
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    28
45
42637f721b5b Bugs fixed
lbessard
parents: 42
diff changeset
    29
from graphics import *
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    30
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    31
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    32
#                          Create New Block Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    34
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    35
[wxID_BLOCKPROPERTIESDIALOG, wxID_BLOCKPROPERTIESDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    36
 wxID_BLOCKPROPERTIESDIALOGNAME, wxID_BLOCKPROPERTIESDIALOGTYPETREE, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    37
 wxID_BLOCKPROPERTIESDIALOGTYPEDESC, wxID_BLOCKPROPERTIESDIALOGINPUTS, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    38
 wxID_BLOCKPROPERTIESDIALOGPREVIEW, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    39
 wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT3, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    40
 wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    41
] = [wx.NewId() for _init_ctrls in range(11)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    42
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    43
[CATEGORY, BLOCK] = range(2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    44
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    45
class BlockPropertiesDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    46
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    47
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    48
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    49
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    50
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    51
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    52
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    53
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    54
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    55
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    56
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    57
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    58
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    59
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    60
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    61
        wx.Dialog.__init__(self, id=wxID_BLOCKPROPERTIESDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    62
              name='BlockPropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    63
              size=wx.Size(600, 360), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    64
              title='Block Properties')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    65
        self.SetClientSize(wx.Size(600, 360))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    66
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    67
        self.MainPanel = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    68
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    69
              size=wx.Size(600, 320), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    70
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    71
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    72
        self.staticbox1 = wx.StaticBox(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    73
              label='Type:', name='staticBox1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    74
              pos=wx.Point(24, 24), size=wx.Size(245, 280), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    75
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    76
        self.staticText2 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    77
              label='Name:', name='staticText2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    78
              pos=wx.Point(274, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    79
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    80
        self.staticText3 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    81
              label='Inputs:', name='staticText4', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    82
              pos=wx.Point(424, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    83
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    84
        self.staticText4 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    85
              label='Preview:', name='staticText4', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    86
              pos=wx.Point(274, 80), size=wx.Size(100, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    87
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    88
        self.TypeTree = wx.TreeCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPETREE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    89
              name='TypeTree', parent=self.MainPanel, pos=wx.Point(34, 44),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    90
              size=wx.Size(225, 180), style=wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    91
        EVT_TREE_SEL_CHANGED(self, wxID_BLOCKPROPERTIESDIALOGTYPETREE, self.OnTypeTreeItemSelected)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    92
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    93
        self.TypeDesc = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPEDESC,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    94
              name='TypeDesc', parent=self.MainPanel, pos=wx.Point(34, 230),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    95
              size=wx.Size(225, 65), style=wx.TE_READONLY|wx.TE_MULTILINE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    96
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    97
        self.Name = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGNAME, value='',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    98
              name='Name', parent=self.MainPanel, pos=wx.Point(274, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
    99
              size=wx.Size(145, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   100
        EVT_TEXT(self, wxID_BLOCKPROPERTIESDIALOGNAME, self.OnNameChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   101
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   102
        self.Inputs = wx.SpinCtrl(id=wxID_BLOCKPROPERTIESDIALOGINPUTS,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   103
              name='Inputs', parent=self.MainPanel, pos=wx.Point(424, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   104
              size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=2, max=20)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   105
        EVT_SPINCTRL(self, wxID_BLOCKPROPERTIESDIALOGINPUTS, self.OnInputsChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   106
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   107
        self.Preview = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   108
              name='Preview', parent=self.MainPanel, pos=wx.Point(274, 104),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   109
              size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   110
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   111
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   112
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   113
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   114
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   115
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   116
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   117
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   118
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   119
        self.Name.SetValue("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   120
        self.Name.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   121
        self.Inputs.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   122
        self.Block = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   123
        self.MinBlockSize = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   124
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   125
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   126
        EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   127
    
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   128
    def FindTreeItem(self, root, name, inputs = None):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   129
        if root.IsOk():
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   130
            pydata = self.TypeTree.GetPyData(root)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   131
            if inputs and "inputs" in pydata:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   132
                same_inputs = pydata["inputs"] == inputs
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   133
            else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   134
                same_inputs = True
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   135
            if self.TypeTree.GetItemText(root) == name and same_inputs:
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   136
                return root
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   137
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   138
                item, root_cookie = self.TypeTree.GetFirstChild(root)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   139
                while item.IsOk():
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   140
                    result = self.FindTreeItem(item, name, inputs)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   141
                    if result:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   142
                        return result
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   143
                    item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   144
        return None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   145
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   146
    def OnOK(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   147
        error = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   148
        selected = self.TypeTree.GetSelection()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   149
        if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   150
            message = wxMessageDialog(self, "Form isn't complete. Valid block type must be selected!", "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   151
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   152
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   153
        elif self.Name.IsEnabled() and self.Name.GetValue() == "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   154
            message = wxMessageDialog(self, "Form isn't complete. Name must be filled!", "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   155
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   156
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   157
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   158
            self.EndModal(wxID_OK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   159
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   160
    def SetBlockList(self, blocktypes):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   161
        root = self.TypeTree.AddRoot("")
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   162
        self.TypeTree.SetPyData(root, {"type" : CATEGORY})
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   163
        for category in blocktypes:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   164
            category_item = self.TypeTree.AppendItem(root, category["name"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   165
            self.TypeTree.SetPyData(category_item, {"type" : CATEGORY})
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   166
            for blocktype in category["list"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   167
                blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   168
                self.TypeTree.SetPyData(blocktype_item, {"type" : BLOCK, "inputs" : tuple([type for name, type, modifier in blocktype["inputs"]])})
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   169
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   170
    def SetMinBlockSize(self, size):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   171
        self.MinBlockSize = size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   172
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   173
    def SetValues(self, values):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   174
        for name, value in values.items():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   175
            if name == "type":
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   176
                inputs = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   177
                if "inputs" in values:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   178
                    inputs = values["inputs"]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   179
                item = self.FindTreeItem(self.TypeTree.GetRootItem(), value, inputs)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   180
                if item:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   181
                    self.TypeTree.SelectItem(item)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   182
            elif name == "name":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   183
                self.Name.SetValue(value)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   184
            elif name == "extension":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   185
                self.Inputs.SetValue(value)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   186
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   187
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   188
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   189
        values = {}
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   190
        item = self.TypeTree.GetSelection()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   191
        values["type"] = self.TypeTree.GetItemText(item)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   192
        values["inputs"] = self.TypeTree.GetPyData(item)["inputs"]
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   193
        if self.Name.GetValue() != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   194
            values["name"] = self.Name.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   195
        values["width"], values["height"] = self.Block.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   196
        values["extension"] = self.Inputs.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   197
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   198
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   199
    def OnTypeTreeItemSelected(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   200
        self.Name.SetValue("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   201
        selected = event.GetItem()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   202
        pydata = self.TypeTree.GetPyData(selected)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   203
        if pydata["type"] != CATEGORY:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   204
            blocktype = GetBlockType(self.TypeTree.GetItemText(selected), pydata["inputs"])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   205
            if blocktype:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   206
                self.Inputs.SetValue(len(blocktype["inputs"]))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   207
                self.Inputs.Enable(blocktype["extensible"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   208
                self.Name.Enable(blocktype["type"] != "function")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   209
                self.TypeDesc.SetValue(blocktype["comment"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   210
                wxCallAfter(self.RefreshPreview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   211
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   212
                self.Name.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   213
                self.Inputs.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   214
                self.Inputs.SetValue(2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   215
                self.TypeDesc.SetValue("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   216
                wxCallAfter(self.ErasePreview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   217
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   218
            self.Name.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   219
            self.Inputs.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   220
            self.Inputs.SetValue(2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   221
            self.TypeDesc.SetValue("")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   222
            wxCallAfter(self.ErasePreview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   223
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   224
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   225
    def OnNameChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   226
        if self.Name.IsEnabled():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   227
            self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   228
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   229
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   230
    def OnInputsChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   231
        if self.Inputs.IsEnabled():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   232
            self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   233
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   234
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   235
    def ErasePreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   236
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   237
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   238
        self.Block = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   239
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   240
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   241
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   242
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   243
        item = self.TypeTree.GetSelection()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   244
        pydata = self.TypeTree.GetPyData(item)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   245
        if pydata["type"] == CATEGORY:
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   246
            self.Block = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   247
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   248
            blocktype = self.TypeTree.GetItemText(item)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   249
            if blocktype:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   250
                self.Block = FBD_Block(self.Preview, blocktype, self.Name.GetValue(), extension = self.Inputs.GetValue(), inputs = pydata["inputs"])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   251
                width, height = self.MinBlockSize
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   252
                min_width, min_height = self.Block.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   253
                width, height = max(min_width, width), max(min_height, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   254
                self.Block.SetSize(width, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   255
                clientsize = self.Preview.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   256
                x = (clientsize.width - width) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   257
                y = (clientsize.height - height) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   258
                self.Block.SetPosition(x, y)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   259
                self.Block.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   260
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   261
                self.Block = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   262
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   263
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   264
        if self.Block:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   265
            self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   266
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   267
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   268
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   269
#                          Create New Variable Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   270
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   271
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   272
[wxID_VARIABLEPROPERTIESDIALOG, wxID_VARIABLEPROPERTIESDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   273
 wxID_VARIABLEPROPERTIESDIALOGNAME, wxID_VARIABLEPROPERTIESDIALOGCLASS, 
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   274
 wxID_VARIABLEPROPERTIESDIALOGPREVIEW, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   275
 wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   276
 wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   277
] = [wx.NewId() for _init_ctrls in range(10)]
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   278
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   279
class VariablePropertiesDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   280
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   281
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   282
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   283
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   284
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   285
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   286
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   287
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   288
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   289
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   290
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   291
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   292
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   293
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   294
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   295
        wx.Dialog.__init__(self, id=wxID_VARIABLEPROPERTIESDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   296
              name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   297
              size=wx.Size(400, 380), style=wx.DEFAULT_DIALOG_STYLE,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   298
              title='Variable Properties')
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   299
        self.SetClientSize(wx.Size(400, 380))
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   300
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   301
        self.MainPanel = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   302
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   303
              size=wx.Size(400, 280), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   304
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   305
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   306
        self.staticText1 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   307
              label='Class:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   308
              pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   309
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   310
        self.staticText2 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2,
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   311
              label='Expression:', name='staticText2', parent=self.MainPanel,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   312
              pos=wx.Point(24, 90), size=wx.Size(100, 17), style=0)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   313
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   314
        self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   315
              label='Name:', name='staticText3', parent=self.MainPanel,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   316
              pos=wx.Point(204, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   317
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   318
        self.staticText4 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   319
              label='Preview:', name='staticText4', parent=self.MainPanel,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   320
              pos=wx.Point(24, 144), size=wx.Size(100, 17), style=0)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   321
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   322
        self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   323
              name='Class', parent=self.MainPanel, pos=wx.Point(24, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   324
              size=wx.Size(145, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   325
        EVT_CHOICE(self, wxID_VARIABLEPROPERTIESDIALOGCLASS, self.OnClassChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   326
        
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   327
        self.Name = wx.ListBox(id=wxID_VARIABLEPROPERTIESDIALOGNAME,
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   328
              name='Name', parent=self.MainPanel, pos=wx.Point(204, 48),
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   329
              size=wx.Size(145, 90), style=wx.LB_SINGLE)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   330
        EVT_LISTBOX(self, wxID_VARIABLEPROPERTIESDIALOGNAME, self.OnNameChanged)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   331
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   332
        self.Expression = wx.TextCtrl(id=wxID_VARIABLEPROPERTIESDIALOGEXPRESSION,
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   333
              name='Expression', parent=self.MainPanel, pos=wx.Point(24, 114),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   334
              size=wx.Size(145, 24), style=0)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   335
        EVT_TEXT(self, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, self.OnExpressionChanged)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   336
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   337
        self.Preview = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGPREVIEW,
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   338
              name='Preview', parent=self.MainPanel, pos=wx.Point(24, 170),
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   339
              size=wx.Size(350, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   340
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   341
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   342
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   343
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   344
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   345
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   346
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   347
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   348
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   349
        self.Variable = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   350
        self.VarList = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   351
        self.MinVariableSize = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   352
        self.RefreshNameList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   353
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   354
        for choice in ["Input", "Output", "InOut"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   355
            self.Class.Append(choice)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   356
        self.Class.SetStringSelection("Input")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   357
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   358
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   359
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   360
    def RefreshNameList(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   361
        selected = self.Name.GetStringSelection()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   362
        self.Name.Clear()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   363
        self.Name.Append("")
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   364
        for name, var_type, value_type in self.VarList:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   365
            if var_type in ["Local","Temp","Global","External"]:
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   366
                self.Name.Append(name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   367
            elif var_type == "Input" and self.Class.GetStringSelection() == "Input":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   368
                self.Name.Append(name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   369
            elif var_type == "Output" and self.Class.GetStringSelection() == "Output":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   370
                self.Name.Append(name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   371
            elif var_type == "InOut" and self.Class.GetStringSelection() == "InOut":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   372
                self.Name.Append(name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   373
        if self.Name.FindString(selected) != wxNOT_FOUND:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   374
            self.Name.SetStringSelection(selected)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   375
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   376
            self.Name.SetStringSelection("")
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   377
        self.Name.Enable(self.Name.GetCount() > 0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   378
            
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   379
    def SetMinVariableSize(self, size):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   380
        self.MinVariableSize = size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   381
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   382
    def SetVariables(self, vars):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   383
        self.VarList = vars
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   384
        self.RefreshNameList()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   385
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   386
    def SetValues(self, values):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   387
        for name, value in values.items():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   388
            if name == "type":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   389
                if value == INPUT:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   390
                    self.Class.SetStringSelection("Input")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   391
                if value == OUTPUT:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   392
                    self.Class.SetStringSelection("Output")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   393
                if value == INOUT:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   394
                    self.Class.SetStringSelection("InOut")
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   395
            elif name == "name" and value != "":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   396
                if self.Name.FindString(value) != wxNOT_FOUND:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   397
                    self.Name.SetStringSelection(value)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   398
                    self.Expression.Enable(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   399
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   400
                    self.Expression.SetValue(value)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   401
                    self.Name.Enable(False)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   402
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   403
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   404
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   405
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   406
        classtype = self.Class.GetStringSelection()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   407
        if classtype == "Input":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   408
            values["type"] = INPUT
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   409
        elif classtype == "Output":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   410
            values["type"] = OUTPUT
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   411
        elif classtype == "InOut":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   412
            values["type"] = INOUT
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   413
        expression = self.Expression.GetValue()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   414
        if self.Expression.IsEnabled() and expression != "":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   415
            values["name"] = expression
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   416
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   417
            values["name"] = self.Name.GetStringSelection()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   418
        values["value_type"] = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   419
        for var_name, var_type, value_type in self.VarList:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   420
            if var_name == values["name"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   421
                values["value_type"] = value_type
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   422
        values["width"], values["height"] = self.Variable.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   423
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   424
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   425
    def OnClassChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   426
        self.RefreshNameList()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   427
        if self.Class.GetStringSelection() == "Input":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   428
            self.Expression.Enable(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   429
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   430
            self.Expression.Enable(False)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   431
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   432
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   433
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   434
    def OnNameChanged(self, event):
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   435
        if self.Name.GetStringSelection() != "":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   436
            self.Expression.Enable(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   437
        elif self.Class.GetStringSelection() == "Input":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   438
            self.Expression.Enable(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   439
        self.RefreshPreview()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   440
        event.Skip()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   441
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   442
    def OnExpressionChanged(self, event):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   443
        if self.Expression.GetValue() != "":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   444
            self.Name.Enable(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   445
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   446
            self.Name.Enable(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   447
        self.RefreshPreview()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   448
        event.Skip()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   449
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   450
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   451
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   452
        dc.Clear()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   453
        expression = self.Expression.GetValue()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   454
        if self.Expression.IsEnabled() and expression != "":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   455
            name = expression
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   456
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   457
            name = self.Name.GetStringSelection()
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   458
        type = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   459
        for var_name, var_type, value_type in self.VarList:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   460
            if var_name == name:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   461
                type = value_type
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   462
        classtype = self.Class.GetStringSelection()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   463
        if classtype == "Input":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   464
            self.Variable = FBD_Variable(self.Preview, INPUT, name, type)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   465
        elif classtype == "Output":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   466
            self.Variable = FBD_Variable(self.Preview, OUTPUT, name, type)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   467
        elif classtype == "InOut":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   468
            self.Variable = FBD_Variable(self.Preview, INOUT, name, type)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   469
        width, height = self.MinVariableSize
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   470
        min_width, min_height = self.Variable.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   471
        width, height = max(min_width, width), max(min_height, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   472
        self.Variable.SetSize(width, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   473
        clientsize = self.Preview.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   474
        x = (clientsize.width - width) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   475
        y = (clientsize.height - height) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   476
        self.Variable.SetPosition(x, y)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   477
        self.Variable.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   478
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   479
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   480
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   481
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   482
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   483
#                          Create New Connection Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   484
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   485
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   486
[wxID_CONNECTIONPROPERTIESDIALOG, wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   487
 wxID_CONNECTIONPROPERTIESDIALOGNAME, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   488
 wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, wxID_CONNECTIONPROPERTIESDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   489
 wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   490
 wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   491
] = [wx.NewId() for _init_ctrls in range(9)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   492
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   493
class ConnectionPropertiesDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   494
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   495
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   496
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   497
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   498
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   499
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   500
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   501
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   502
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   503
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   504
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   505
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   506
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   507
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   508
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   509
        wx.Dialog.__init__(self, id=wxID_CONNECTIONPROPERTIESDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   510
              name='ConnectionPropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   511
              size=wx.Size(350, 220), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   512
              title='Connection Properties')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   513
        self.SetClientSize(wx.Size(350, 220))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   514
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   515
        self.MainPanel = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   516
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   517
              size=wx.Size(340, 360), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   518
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   519
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   520
        self.staticText1 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   521
              label='Type:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   522
              pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   523
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   524
        self.staticText2 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   525
              label='Name:', name='staticText2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   526
              pos=wx.Point(24, 104), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   527
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   528
        self.staticText3 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   529
              label='Preview:', name='staticText3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   530
              pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   531
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   532
        self.radioButton1 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   533
              label='Connector', name='radioButton1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   534
              pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   535
        EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   536
        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   537
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   538
        self.radioButton2 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   539
              label='Continuation', name='radioButton2', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   540
              pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   541
        EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   542
        self.radioButton2.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   543
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   544
        self.Name = wx.TextCtrl(id=wxID_CONNECTIONPROPERTIESDIALOGNAME,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   545
              name='Name', parent=self.MainPanel, pos=wx.Point(24, 130),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   546
              size=wx.Size(145, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   547
        EVT_TEXT(self, wxID_CONNECTIONPROPERTIESDIALOGNAME, self.OnNameChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   548
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   549
        self.Preview = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   550
              name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   551
              size=wx.Size(150, 100), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   552
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   553
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   554
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   555
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   556
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   557
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   558
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   559
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   560
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   561
        self.Connection = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   562
        self.MinConnectionSize = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   563
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   564
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   565
            
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   566
    def SetMinConnectionSize(self, size):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   567
        self.MinConnectionSize = size
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   568
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   569
    def SetValues(self, values):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   570
        for name, value in values.items():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   571
            if name == "type":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   572
                if value == CONNECTOR:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   573
                    self.radioButton1.SetValue(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   574
                elif value == CONTINUATION:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   575
                    self.radioButton2.SetValue(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   576
            elif name == "name":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   577
                self.Name.SetValue(value)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   578
        self.RefreshPreview()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   579
    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   580
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   581
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   582
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   583
            values["type"] = CONNECTOR
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   584
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   585
            values["type"] = CONTINUATION
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   586
        values["name"] = self.Name.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   587
        values["width"], values["height"] = self.Connection.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   588
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   589
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   590
    def OnTypeChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   591
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   592
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   593
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   594
    def OnNameChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   595
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   596
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   597
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   598
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   599
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   600
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   601
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   602
            self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.Name.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   603
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   604
            self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.Name.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   605
        width, height = self.MinConnectionSize
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   606
        min_width, min_height = self.Connection.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   607
        width, height = max(min_width, width), max(min_height, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   608
        self.Connection.SetSize(width, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   609
        clientsize = self.Preview.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   610
        x = (clientsize.width - width) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   611
        y = (clientsize.height - height) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   612
        self.Connection.SetPosition(x, y)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   613
        self.Connection.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   614
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   615
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   616
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   617
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   618
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   619
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   620
#                        Edit Ladder Element Properties Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   621
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   622
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   623
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   624
[wxID_LDELEMENTDIALOG, wxID_LDELEMENTDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   625
 wxID_LDELEMENTDIALOGNAME, wxID_LDELEMENTDIALOGRADIOBUTTON1, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   626
 wxID_LDELEMENTDIALOGRADIOBUTTON2, wxID_LDELEMENTDIALOGRADIOBUTTON3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   627
 wxID_LDELEMENTDIALOGRADIOBUTTON4, wxID_LDELEMENTDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   628
 wxID_LDELEMENTDIALOGSTATICTEXT1, wxID_LDELEMENTDIALOGSTATICTEXT2, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   629
 wxID_LDELEMENTDIALOGSTATICTEXT3, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   630
] = [wx.NewId() for _init_ctrls in range(11)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   631
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   632
class LDElementDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   633
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   634
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   635
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   636
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   637
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   638
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   639
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   640
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   641
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   642
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   643
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   644
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   645
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   646
    def _init_ctrls(self, prnt, title, labels):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   647
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   648
        wx.Dialog.__init__(self, id=wxID_LDELEMENTDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   649
              name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   650
              size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   651
              title=title)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   652
        self.SetClientSize(wx.Size(350, 260))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   653
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   654
        self.MainPanel = wx.Panel(id=wxID_LDELEMENTDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   655
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   656
              size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   657
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   658
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   659
        self.staticText1 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   660
              label='Modifier:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   661
              pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   662
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   663
        self.staticText2 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   664
              label='Name:', name='staticText2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   665
              pos=wx.Point(24, 150), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   666
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   667
        self.staticText3 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   668
              label='Preview:', name='staticText3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   669
              pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   670
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   671
        self.radioButton1 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   672
              label=labels[0], name='radioButton1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   673
              pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   674
        EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON1, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   675
        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   676
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   677
        self.radioButton2 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   678
              label=labels[1], name='radioButton2', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   679
              pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   680
        EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON2, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   681
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   682
        self.radioButton3 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   683
              label=labels[2], name='radioButton3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   684
              pos=wx.Point(24, 96), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   685
        EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON3, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   686
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   687
        self.radioButton4 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON4,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   688
              label=labels[3], name='radioButton4', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   689
              pos=wx.Point(24, 120), size=wx.Size(128, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   690
        EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON4, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   691
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   692
        self.Name = wx.Choice(id=wxID_LDELEMENTDIALOGNAME,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   693
              name='Name', parent=self.MainPanel, pos=wx.Point(24, 174),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   694
              size=wx.Size(145, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   695
        EVT_CHOICE(self, wxID_LDELEMENTDIALOGNAME, self.OnNameChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   696
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   697
        self.Preview = wx.Panel(id=wxID_LDELEMENTDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   698
              name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   699
              size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   700
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   701
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   702
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   703
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   704
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   705
    def __init__(self, parent, type):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   706
        self.Type = type
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   707
        if type == "contact":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   708
            self._init_ctrls(parent, "Edit Contact Values", ['Normal','Negate','Rising Edge','Falling Edge'])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   709
            self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   710
        elif type == "coil":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   711
            self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset'])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   712
            self.Element = LD_Coil(self.Preview, COIL_NORMAL, "")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   713
        self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   714
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   715
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   716
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   717
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   718
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   719
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   720
    def SetElementSize(self, size):
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   721
        min_width, min_height = self.Element.GetMinSize()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   722
        width, height = max(min_width, size[0]), max(min_height, size[1])
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   723
        self.Element.SetSize(width, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   724
        self.Element.SetPosition((150 - width) / 2, (150 - height) / 2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   725
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   726
    def SetVariables(self, vars):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   727
        self.Name.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   728
        for name in vars:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   729
            self.Name.Append(name)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   730
        self.Name.Enable(self.Name.GetCount() > 0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   731
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   732
    def SetValues(self, values):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   733
        for name, value in values.items():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   734
            if name == "name":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   735
                self.Element.SetName(value)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   736
                self.Name.SetStringSelection(value)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   737
            elif name == "type":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   738
                self.Element.SetType(value)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   739
                if self.Type == "contact":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   740
                    if value == CONTACT_NORMAL:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   741
                        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   742
                    elif value == CONTACT_REVERSE:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   743
                        self.radioButton2.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   744
                    elif value == CONTACT_RISING:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   745
                        self.radioButton3.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   746
                    elif value == CONTACT_FALLING:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   747
                        self.radioButton4.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   748
                elif self.Type == "coil":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   749
                    if value == COIL_NORMAL:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   750
                        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   751
                    elif value == COIL_REVERSE:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   752
                        self.radioButton2.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   753
                    elif value == COIL_SET:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   754
                        self.radioButton3.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   755
                    elif value == COIL_RESET:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   756
                        self.radioButton4.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   757
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   758
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   759
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   760
        values["name"] = self.Element.GetName()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   761
        values["type"] = self.Element.GetType()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   762
        values["width"], values["height"] = self.Element.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   763
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   764
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   765
    def OnTypeChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   766
        if self.Type == "contact":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   767
            if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   768
                self.Element.SetType(CONTACT_NORMAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   769
            elif self.radioButton2.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   770
                self.Element.SetType(CONTACT_REVERSE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   771
            elif self.radioButton3.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   772
                self.Element.SetType(CONTACT_RISING)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   773
            elif self.radioButton4.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   774
                self.Element.SetType(CONTACT_FALLING)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   775
        elif self.Type == "coil":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   776
            if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   777
                self.Element.SetType(COIL_NORMAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   778
            elif self.radioButton2.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   779
                self.Element.SetType(COIL_REVERSE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   780
            elif self.radioButton3.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   781
                self.Element.SetType(COIL_SET)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   782
            elif self.radioButton4.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   783
                self.Element.SetType(COIL_RESET)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   784
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   785
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   786
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   787
    def OnNameChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   788
        self.Element.SetName(self.Name.GetStringSelection())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   789
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   790
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   791
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   792
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   793
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   794
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   795
        self.Element.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   796
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   797
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   798
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   799
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   800
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   801
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   802
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   803
#                      Edit Ladder Power Rail Properties Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   804
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   805
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   806
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   807
[wxID_LDPOWERRAILDIALOG, wxID_LDPOWERRAILDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   808
 wxID_LDPOWERRAILDIALOGTYPE, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   809
 wxID_LDPOWERRAILDIALOGRADIOBUTTON2, wxID_LDPOWERRAILDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   810
 wxID_LDPOWERRAILDIALOGSTATICTEXT1, wxID_LDPOWERRAILDIALOGSTATICTEXT2, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   811
 wxID_LDPOWERRAILDIALOGSTATICTEXT3, wxID_LDPOWERRAILDIALOGPINNUMBER,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   812
] = [wx.NewId() for _init_ctrls in range(10)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   813
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   814
class LDPowerRailDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   815
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   816
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   817
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   818
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   819
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   820
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   821
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   822
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   823
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   824
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   825
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   826
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   827
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   828
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   829
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   830
        wx.Dialog.__init__(self, id=wxID_LDPOWERRAILDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   831
              name='PowerRailDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   832
              size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   833
              title='Power Rail Properties')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   834
        self.SetClientSize(wx.Size(350, 260))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   835
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   836
        self.MainPanel = wx.Panel(id=wxID_LDPOWERRAILDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   837
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   838
              size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   839
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   840
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   841
        self.staticText1 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   842
              label='Type:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   843
              pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   844
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   845
        self.staticText2 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   846
              label='Pin number:', name='staticText2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   847
              pos=wx.Point(24, 100), size=wx.Size(70, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   848
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   849
        self.staticText3 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   850
              label='Preview:', name='staticText3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   851
              pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   852
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   853
        self.radioButton1 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   854
              label='Left PowerRail', name='radioButton1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   855
              pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   856
        EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   857
        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   858
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   859
        self.radioButton2 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   860
              label='Right PowerRail', name='radioButton2', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   861
              pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   862
        EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON2, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   863
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   864
        self.PinNumber = wx.SpinCtrl(id=wxID_LDPOWERRAILDIALOGPINNUMBER,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   865
              name='PinNumber', parent=self.MainPanel, pos=wx.Point(24, 124),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   866
              size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=1, max=20)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   867
        EVT_SPINCTRL(self, wxID_LDPOWERRAILDIALOGPINNUMBER, self.OnPinNumberChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   868
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   869
        self.Preview = wx.Panel(id=wxID_LDPOWERRAILDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   870
              name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   871
              size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   872
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   873
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   874
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   875
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   876
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   877
    def __init__(self, parent, type = LEFTRAIL, number = 1):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   878
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   879
        self.Type = type
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   880
        if type == LEFTRAIL:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   881
            self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   882
        elif type == RIGHTRAIL:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   883
            self.radioButton2.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   884
        self.PinNumber.SetValue(number)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   885
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   886
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   887
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   888
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   889
        self.PowerRailMinSize = (0, 0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   890
        self.PowerRail = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   891
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   892
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   893
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   894
    def SetMinSize(self, size):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   895
        self.PowerRailMinSize = size
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   896
        self.RefreshPreview()    
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   897
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   898
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   899
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   900
        values["type"] = self.Type
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   901
        values["number"] = self.PinNumber.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   902
        values["width"], values["height"] = self.PowerRail.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   903
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   904
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   905
    def OnTypeChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   906
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   907
            self.Type = LEFTRAIL
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   908
        elif self.radioButton2.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   909
            self.Type = RIGHTRAIL
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   910
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   911
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   912
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   913
    def OnPinNumberChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   914
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   915
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   916
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   917
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   918
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   919
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   920
        self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = [True for i in xrange(self.PinNumber.GetValue())])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   921
        min_width, min_height = self.PowerRail.GetMinSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   922
        width, height = max(min_width, self.PowerRailMinSize[0]), max(min_height, self.PowerRailMinSize[1])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   923
        self.PowerRail.SetSize(width, height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   924
        self.PowerRail.RefreshConnectors()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   925
        self.PowerRail.SetPosition((150 - width) / 2, (150 - height) / 2)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   926
        self.PowerRail.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   927
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   928
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   929
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   930
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   931
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   932
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   933
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   934
#                          Edit Transition Content Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   935
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   936
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   937
[wxID_TRANSITIONCONTENTDIALOG, wxID_TRANSITIONCONTENTDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   938
 wxID_TRANSITIONCONTENTDIALOGREFERENCE, wxID_TRANSITIONCONTENTDIALOGINLINE, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   939
 wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   940
] = [wx.NewId() for _init_ctrls in range(6)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   941
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   942
class TransitionContentDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   943
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   944
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   945
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   946
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   947
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   948
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   949
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   950
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   951
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   952
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   953
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   954
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   955
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   956
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   957
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   958
        wx.Dialog.__init__(self, id=wxID_TRANSITIONCONTENTDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   959
              name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   960
              size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   961
              title='Edit transition')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   962
        self.SetClientSize(wx.Size(300, 200))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   963
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   964
        self.MainPanel = wx.Panel(id=wxID_TRANSITIONCONTENTDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   965
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   966
              size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   967
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   968
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   969
        self.radioButton1 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   970
              label='Reference', name='radioButton1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   971
              pos=wx.Point(24, 24), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   972
        EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   973
        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   974
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   975
        self.Reference = wx.Choice(id=wxID_TRANSITIONCONTENTDIALOGREFERENCE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   976
              name='Reference', parent=self.MainPanel, pos=wx.Point(48, 48), 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   977
              size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   978
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   979
        self.radioButton2 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   980
              label='Inline', name='radioButton2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   981
              pos=wx.Point(24, 72), size=wx.Size(114, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   982
        EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   983
        self.radioButton2.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   984
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   985
        self.Inline = wx.TextCtrl(id=wxID_TRANSITIONCONTENTDIALOGINLINE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   986
              name='Inline', parent=self.MainPanel, pos=wx.Point(48, 96),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   987
              size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   988
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   989
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   990
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   991
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   992
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   993
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   994
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   995
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   996
        EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   997
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   998
    def OnOK(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
   999
        error = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1000
        if self.radioButton1.GetValue() and self.Reference.GetStringSelection() == "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1001
            error.append("Reference")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1002
        if self.radioButton2.GetValue() and self.Inline.GetValue() == "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1003
            error.append("Inline")
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1004
        if len(error) > 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1005
            text = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1006
            for i, item in enumerate(error):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1007
                if i == 0:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1008
                    text += item
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1009
                elif i == len(error) - 1:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1010
                    text += " and %s"%item
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1011
                else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1012
                    text += ", %s"%item 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1013
            message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1014
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1015
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1016
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1017
            self.EndModal(wxID_OK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1018
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1019
    def OnTypeChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1020
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1021
            self.Reference.Enable(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1022
            self.Inline.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1023
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1024
            self.Reference.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1025
            self.Inline.Enable(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1026
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1027
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1028
    def SetTransitions(self, transitions):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1029
        for transition in transitions:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1030
            self.Reference.Append(transition)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1031
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1032
    def SetValues(self, values):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1033
        if values["type"] == "reference":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1034
            self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1035
            self.radioButton2.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1036
            self.Reference.Enable(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1037
            self.Inline.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1038
            self.Reference.SetStringSelection(values["value"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1039
        elif values["type"] == "inline":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1040
            self.radioButton1.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1041
            self.radioButton2.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1042
            self.Reference.Enable(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1043
            self.Inline.Enable(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1044
            self.Inline.SetValue(values["value"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1045
                
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1046
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1047
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1048
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1049
            values["type"] = "reference"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1050
            values["value"] = self.Reference.GetStringSelection()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1051
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1052
            values["type"] = "inline"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1053
            values["value"] = self.Inline.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1054
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1055
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1056
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1057
#                         Create New Divergence Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1058
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1059
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1060
[wxID_DIVERGENCECREATEDIALOG, wxID_DIVERGENCECREATEDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1061
 wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1062
 wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1063
 wxID_DIVERGENCECREATEDIALOGSEQUENCES, wxID_DIVERGENCECREATEDIALOGPREVIEW, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1064
 wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1065
 wxID_DIVERGENCECREATEDIALOGSTATICTEXT3,  
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1066
] = [wx.NewId() for _init_ctrls in range(11)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1067
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1068
class DivergenceCreateDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1069
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1070
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1071
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1072
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1073
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1074
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1075
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1076
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1077
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1078
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1079
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1080
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1081
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1082
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1083
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1084
        wx.Dialog.__init__(self, id=wxID_DIVERGENCECREATEDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1085
              name='DivergencePropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1086
              size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1087
              title='Create a new divergence or convergence')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1088
        self.SetClientSize(wx.Size(500, 260))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1089
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1090
        self.MainPanel = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1091
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1092
              size=wx.Size(600, 220), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1093
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1094
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1095
        self.staticText1 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1096
              label='Type:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1097
              pos=wx.Point(24, 24), size=wx.Size(200, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1098
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1099
        self.radioButton1 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1100
              label='Selection Divergence', name='radioButton1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1101
              pos=wx.Point(24, 48), size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1102
        EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1103
        self.radioButton1.SetValue(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1104
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1105
        self.radioButton2 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1106
              label='Selection Convergence', name='radioButton2', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1107
              pos=wx.Point(24, 72), size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1108
        EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1109
        self.radioButton2.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1110
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1111
        self.radioButton3 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1112
              label='Simultaneous Divergence', name='radioButton3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1113
              pos=wx.Point(24, 96), size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1114
        EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1115
        self.radioButton3.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1116
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1117
        self.radioButton4 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1118
              label='Simultaneous Convergence', name='radioButton4', parent=self.MainPanel, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1119
              pos=wx.Point(24, 120), size=wx.Size(200, 24), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1120
        EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, self.OnTypeChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1121
        self.radioButton4.SetValue(False)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1122
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1123
        self.staticText2 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT2,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1124
              label='Number of sequences:', name='staticText2', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1125
              pos=wx.Point(24, 150), size=wx.Size(200, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1126
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1127
        self.Sequences = wx.SpinCtrl(id=wxID_DIVERGENCECREATEDIALOGSEQUENCES,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1128
              name='Sequences', parent=self.MainPanel, pos=wx.Point(24, 174),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1129
              size=wx.Size(200, 24), style=0, min=2, max=20)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1130
        EVT_SPINCTRL(self, wxID_DIVERGENCECREATEDIALOGSEQUENCES, self.OnSequencesChanged)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1131
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1132
        self.staticText3 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT3,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1133
              label='Preview:', name='staticText3', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1134
              pos=wx.Point(250, 24), size=wx.Size(100, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1135
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1136
        self.Preview = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGPREVIEW,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1137
              name='Preview', parent=self.MainPanel, pos=wx.Point(250, 48),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1138
              size=wx.Size(225, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1139
        self.Preview.SetBackgroundColour(wxColour(255,255,255))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1140
        setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
27
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1141
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1142
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1143
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1144
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1145
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1146
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1147
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1148
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1149
        self.Divergence = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1150
        self.MinSize = (0, 0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1151
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1152
        EVT_PAINT(self, self.OnPaint)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1153
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1154
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1155
        values = {}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1156
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1157
            values["type"] = SELECTION_DIVERGENCE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1158
        elif self.radioButton2.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1159
            values["type"] = SELECTION_CONVERGENCE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1160
        elif self.radioButton3.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1161
            values["type"] = SIMULTANEOUS_DIVERGENCE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1162
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1163
            values["type"] = SIMULTANEOUS_CONVERGENCE
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1164
        values["number"] = self.Sequences.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1165
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1166
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1167
    def SetMinSize(self, size):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1168
        self.MinSize = size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1169
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1170
    def OnTypeChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1171
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1172
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1173
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1174
    def OnSequencesChanged(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1175
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1176
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1177
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1178
    def RefreshPreview(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1179
        dc = wxClientDC(self.Preview)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1180
        dc.Clear()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1181
        if self.radioButton1.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1182
            self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1183
        elif self.radioButton2.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1184
            self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1185
        elif self.radioButton3.GetValue():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1186
            self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1187
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1188
            self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1189
        width, height = self.Divergence.GetSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1190
        min_width, min_height = max(width, self.MinSize[0]), max(height, self.MinSize[1])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1191
        self.Divergence.SetSize(min_width, min_height)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1192
        clientsize = self.Preview.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1193
        x = (clientsize.width - min_width) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1194
        y = (clientsize.height - min_height) / 2
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1195
        self.Divergence.SetPosition(x, y)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1196
        self.Divergence.Draw(dc)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1197
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1198
    def OnPaint(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1199
        self.RefreshPreview()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1200
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1201
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1202
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1203
#                            Action Block Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1204
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1205
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1206
class ActionTable(wxPyGridTableBase):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1207
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1208
    """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1209
    A custom wxGrid Table using user supplied data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1210
    """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1211
    def __init__(self, parent, data, colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1212
        # The base class must be initialized *first*
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1213
        wxPyGridTableBase.__init__(self)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1214
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1215
        self.colnames = colnames
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1216
        self.Parent = parent
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1217
        # XXX
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1218
        # we need to store the row length and collength to
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1219
        # see if the table has changed size
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1220
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1221
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1222
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1223
    def GetNumberCols(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1224
        return len(self.colnames)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1225
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1226
    def GetNumberRows(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1227
        return len(self.data)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1228
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1229
    def GetColLabelValue(self, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1230
        if col < len(self.colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1231
            return self.colnames[col]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1232
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1233
    def GetRowLabelValues(self, row):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1234
        return row
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1235
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1236
    def GetValue(self, row, col):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1237
        if row < self.GetNumberRows():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1238
            name = str(self.data[row].get(self.GetColLabelValue(col), ""))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1239
            return name
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1240
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1241
    def GetValueByName(self, row, colname):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1242
        return self.data[row].get(colname)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1243
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1244
    def SetValue(self, row, col, value):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1245
        if col < len(self.colnames):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1246
            self.data[row][self.GetColLabelValue(col)] = value
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1247
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1248
    def ResetView(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1249
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1250
        (wxGrid) -> Reset the grid view.   Call this to
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1251
        update the grid if rows and columns have been added or deleted
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1252
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1253
        grid.BeginBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1254
        for current, new, delmsg, addmsg in [
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1255
            (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1256
            (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1257
        ]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1258
            if new < current:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1259
                msg = wxGridTableMessage(self,delmsg,new,current-new)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1260
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1261
            elif new > current:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1262
                msg = wxGridTableMessage(self,addmsg,new-current)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1263
                grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1264
                self.UpdateValues(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1265
        grid.EndBatch()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1266
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1267
        self._rows = self.GetNumberRows()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1268
        self._cols = self.GetNumberCols()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1269
        # update the column rendering scheme
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1270
        self._updateColAttrs(grid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1271
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1272
        # update the scrollbars and the displayed part of the grid
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1273
        grid.AdjustScrollbars()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1274
        grid.ForceRefresh()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1275
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1276
    def UpdateValues(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1277
        """Update all displayed values"""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1278
        # This sends an event to the grid table to update all of the values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1279
        msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1280
        grid.ProcessTableMessage(msg)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1281
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1282
    def _updateColAttrs(self, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1283
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1284
        wxGrid -> update the column attributes to add the
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1285
        appropriate renderer given the column name.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1286
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1287
        Otherwise default to the default renderer.
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1288
        """
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1289
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1290
        for col in range(self.GetNumberCols()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1291
            attr = wxGridCellAttr()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1292
            attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1293
            grid.SetColAttr(col, attr)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1294
            grid.SetColSize(col, self.Parent.ColSizes[col])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1295
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1296
        typelist = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1297
        accesslist = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1298
        for row in range(self.GetNumberRows()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1299
            for col in range(self.GetNumberCols()):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1300
                editor = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1301
                renderer = None
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1302
                readonly = False
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1303
                colname = self.GetColLabelValue(col)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1304
                if colname == "Qualifier":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1305
                    editor = wxGridCellChoiceEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1306
                    editor.SetParameters(self.Parent.QualifierList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1307
                if colname == "Duration":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1308
                    editor = wxGridCellTextEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1309
                    renderer = wxGridCellStringRenderer()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1310
                    if self.Parent.DurationList[self.data[row]["Qualifier"]]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1311
                        readonly = False
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1312
                    else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1313
                        readonly = True
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1314
                        self.data[row]["Duration"] = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1315
                elif colname == "Type":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1316
                    editor = wxGridCellChoiceEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1317
                    editor.SetParameters(self.Parent.TypeList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1318
                elif colname == "Value":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1319
                    type = self.data[row]["Type"]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1320
                    if type == "Action":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1321
                        editor = wxGridCellChoiceEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1322
                        editor.SetParameters(self.Parent.ActionList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1323
                    elif type == "Variable":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1324
                        editor = wxGridCellChoiceEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1325
                        editor.SetParameters(self.Parent.VariableList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1326
                    elif type == "Inline":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1327
                        editor = wxGridCellTextEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1328
                        renderer = wxGridCellStringRenderer()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1329
                elif colname == "Indicator":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1330
                    editor = wxGridCellChoiceEditor()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1331
                    editor.SetParameters(self.Parent.VariableList)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1332
                    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1333
                grid.SetCellEditor(row, col, editor)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1334
                grid.SetCellRenderer(row, col, renderer)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1335
                grid.SetReadOnly(row, col, readonly)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1336
                
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1337
                grid.SetCellBackgroundColour(row, col, wxWHITE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1338
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1339
    def SetData(self, data):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1340
        self.data = data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1341
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1342
    def GetData(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1343
        return self.data
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1344
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1345
    def GetCurrentIndex(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1346
        return self.CurrentIndex
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1347
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1348
    def SetCurrentIndex(self, index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1349
        self.CurrentIndex = index
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1350
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1351
    def AppendRow(self, row_content):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1352
        self.data.append(row_content)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1353
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1354
    def RemoveRow(self, row_index):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1355
        self.data.pop(row_index)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1356
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1357
    def MoveRow(self, row_index, move, grid):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1358
        new_index = max(0, min(row_index + move, len(self.data) - 1))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1359
        if new_index != row_index:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1360
            self.data.insert(new_index, self.data.pop(row_index))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1361
            grid.SetGridCursor(new_index, grid.GetGridCursorCol())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1362
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1363
    def Empty(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1364
        self.data = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1365
        self.editors = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1366
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1367
[wxID_ACTIONBLOCKDIALOG, wxID_ACTIONBLOCKDIALOGMAINPANEL, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1368
 wxID_ACTIONBLOCKDIALOGVARIABLESGRID, wxID_ACTIONBLOCKDIALOGSTATICTEXT1, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1369
 wxID_ACTIONBLOCKDIALOGADDBUTTON,wxID_ACTIONBLOCKDIALOGDELETEBUTTON, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1370
 wxID_ACTIONBLOCKDIALOGUPBUTTON, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1371
] = [wx.NewId() for _init_ctrls in range(8)]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1372
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1373
class ActionBlockDialog(wx.Dialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1374
    def _init_coll_flexGridSizer1_Items(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1375
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1376
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1377
        parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1378
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1379
    def _init_sizers(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1380
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1381
        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1382
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1383
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1384
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1385
        self.SetSizer(self.flexGridSizer1)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1386
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1387
    def _init_ctrls(self, prnt):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1388
        # generated method, don't edit
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1389
        wx.Dialog.__init__(self, id=wxID_ACTIONBLOCKDIALOG,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1390
              name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1391
              size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1392
              title='Edit action block properties')
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1393
        self.SetClientSize(wx.Size(500, 300))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1394
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1395
        self.MainPanel = wx.Panel(id=wxID_ACTIONBLOCKDIALOGMAINPANEL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1396
              name='MainPanel', parent=self, pos=wx.Point(0, 0),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1397
              size=wx.Size(500, 300), style=wx.TAB_TRAVERSAL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1398
        self.MainPanel.SetAutoLayout(True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1399
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1400
        self.staticText1 = wx.StaticText(id=wxID_ACTIONBLOCKDIALOGSTATICTEXT1,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1401
              label='Actions:', name='staticText1', parent=self.MainPanel,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1402
              pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1403
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1404
        self.ActionsGrid = wx.grid.Grid(id=wxID_ACTIONBLOCKDIALOGVARIABLESGRID,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1405
              name='ActionsGrid', parent=self.MainPanel, pos=wx.Point(24, 44), 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1406
              size=wx.Size(450, 150), style=wxVSCROLL)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1407
        self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1408
              'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1409
        self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL,
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1410
              False, 'Sans'))
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1411
        self.ActionsGrid.DisableDragGridSize()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1412
        self.ActionsGrid.EnableScrolling(False, True)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1413
        EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1414
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1415
        self.AddButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGADDBUTTON, label='Add',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1416
              name='AddButton', parent=self.MainPanel, pos=wx.Point(245, 204),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1417
              size=wx.Size(72, 32), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1418
        EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGADDBUTTON, self.OnAddButton)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1419
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1420
        self.DeleteButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1421
              name='DeleteButton', parent=self.MainPanel, pos=wx.Point(325, 204),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1422
              size=wx.Size(72, 32), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1423
        EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDELETEBUTTON, self.OnDeleteButton)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1424
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1425
        self.UpButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGUPBUTTON, label='^',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1426
              name='UpButton', parent=self.MainPanel, pos=wx.Point(405, 204),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1427
              size=wx.Size(32, 32), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1428
        EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGUPBUTTON, self.OnUpButton)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1429
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1430
        self.DownButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v',
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1431
              name='DownButton', parent=self.MainPanel, pos=wx.Point(445, 204),
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1432
              size=wx.Size(32, 32), style=0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1433
        EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, self.OnDownButton)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1434
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1435
        self._init_sizers()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1436
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1437
    def __init__(self, parent):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1438
        self._init_ctrls(parent)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1439
        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1440
        self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1441
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1442
        self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1443
        self.Table = ActionTable(self, [], ["Qualifier","Duration","Type","Value","Indicator"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1444
        self.TypeList = "Action,Variable,Inline"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1445
        self.ColSizes = [60, 90, 80, 110, 80]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1446
        self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1447
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1448
        self.ActionsGrid.SetTable(self.Table)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1449
        self.ActionsGrid.SetRowLabelSize(0)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1450
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1451
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1452
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1453
    def OnAddButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1454
        self.Table.AppendRow(self.DefaultValue.copy())
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1455
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1456
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1457
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1458
    def OnDeleteButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1459
        row = self.ActionsGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1460
        self.Table.RemoveRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1461
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1462
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1463
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1464
    def OnUpButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1465
        row = self.ActionsGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1466
        self.Table.MoveRow(row, -1, self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1467
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1468
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1469
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1470
    def OnDownButton(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1471
        row = self.ActionsGrid.GetGridCursorRow()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1472
        self.Table.MoveRow(row, 1, self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1473
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1474
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1475
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1476
    def OnActionsGridCellChange(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1477
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1478
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1479
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1480
    def SetQualifierList(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1481
        self.QualifierList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1482
        sep = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1483
        for qualifier in list.keys():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1484
            self.QualifierList += "%s%s"%(sep, qualifier)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1485
            sep = ","
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1486
        self.DurationList = list
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1487
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1488
    def SetVariableList(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1489
        self.VariableList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1490
        sep = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1491
        for variable in list:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1492
            self.VariableList += "%s%s"%(sep, variable["Name"])
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1493
            sep = ","
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1494
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1495
    def SetActionList(self, list):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1496
        self.ActionList = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1497
        sep = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1498
        for action in list:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1499
            self.ActionList += "%s%s"%(sep, action)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1500
            sep = ","
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1501
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1502
    def SetValues(self, actions):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1503
        for action in actions:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1504
            row = {"Qualifier" : action["qualifier"], "Value" : action["value"]}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1505
            if action["type"] == "reference":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1506
                if action["value"] in self.ActionList:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1507
                    row["Type"] = "Action"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1508
                elif action["value"] in self.VariableList:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1509
                    row["Type"] = "Variable"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1510
                else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1511
                    row["Type"] = "Inline"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1512
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1513
                row["Type"] = "Inline"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1514
            if "duration" in action:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1515
                row["Duration"] = action["duration"]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1516
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1517
                row["Duration"] = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1518
            if "indicator" in action:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1519
                row["Indicator"] = action["indicator"]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1520
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1521
                row["Indicator"] = ""
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1522
            self.Table.AppendRow(row)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1523
        self.Table.ResetView(self.ActionsGrid)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1524
    
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1525
    def GetValues(self):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1526
        values = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1527
        for data in self.Table.GetData():
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1528
            action = {"qualifier" : data["Qualifier"], "value" : data["Value"]}
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1529
            if data["Type"] in ["Action", "Variable"]:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1530
                action["type"] = "reference"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1531
            else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1532
                action["type"] = "inline"
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1533
            if data["Duration"] != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1534
                action["duration"] = data["Duration"]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1535
            if data["Indicator"] != "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1536
                action["indicator"] = data["Indicator"]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1537
            values.append(action)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1538
        return values
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1539
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1540
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1541
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1542
#                          Edit Step Name Dialog
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1543
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1544
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1545
class StepNameDialog(wxTextEntryDialog):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1546
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1547
    def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", 
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1548
                       style = wxOK|wxCANCEL|wxCENTRE, pos = wxDefaultPosition):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1549
        wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1550
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1551
        self.PouNames = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1552
        self.Variables = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1553
        self.StepNames = []
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1554
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1555
        EVT_BUTTON(self, self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId(), self.OnOK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1556
        
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1557
    def OnOK(self, event):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1558
        step_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1559
        if step_name == "":
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1560
            message = wxMessageDialog(self, "You must type a name!", "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1561
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1562
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1563
        elif not TestIdentifier(step_name):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1564
            message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1565
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1566
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1567
        elif step_name.upper() in IEC_KEYWORDS:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1568
            message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1569
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1570
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1571
        elif step_name.upper() in self.PouNames:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1572
            message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1573
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1574
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1575
        elif step_name.upper() in self.Variables:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1576
            message = wxMessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1577
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1578
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1579
        elif step_name.upper() in self.StepNames:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1580
            message = wxMessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wxOK|wxICON_ERROR)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1581
            message.ShowModal()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1582
            message.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1583
        else:
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1584
            self.EndModal(wxID_OK)
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1585
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1586
    def SetPouNames(self, pou_names):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1587
        self.PouNames = [pou_name.upper() for pou_name in pou_names]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1588
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1589
    def SetVariables(self, variables):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1590
        self.Variables = [var["Name"].upper() for var in variables]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1591
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1592
    def SetStepNames(self, step_names):
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1593
        self.StepNames = [step_name.upper() for step_name in step_names]
dae55dd9ee14 Current developping version
lbessard
parents:
diff changeset
  1594
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1595
    def GetValue(self):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1596
        return self.GetSizer().GetItem(1).GetWindow().GetValue()