lbessard@27: #!/usr/bin/env python lbessard@27: # -*- coding: utf-8 -*- lbessard@27: lbessard@27: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor lbessard@27: #based on the plcopen standard. lbessard@27: # lbessard@27: #Copyright (C): Edouard TISSERANT and Laurent BESSARD lbessard@27: # lbessard@27: #See COPYING file for copyrights details. lbessard@27: # lbessard@27: #This library is free software; you can redistribute it and/or lbessard@27: #modify it under the terms of the GNU General Public lbessard@27: #License as published by the Free Software Foundation; either lbessard@27: #version 2.1 of the License, or (at your option) any later version. lbessard@27: # lbessard@27: #This library is distributed in the hope that it will be useful, lbessard@27: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@27: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@27: #Lesser General Public License for more details. lbessard@27: # lbessard@27: #You should have received a copy of the GNU General Public lbessard@27: #License along with this library; if not, write to the Free Software lbessard@27: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@27: lbessard@27: from wxPython.wx import * lbessard@27: from wxPython.grid import * lbessard@27: import wx lbessard@27: lbessard@45: from graphics import * lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Block Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: [wxID_BLOCKPROPERTIESDIALOG, wxID_BLOCKPROPERTIESDIALOGMAINPANEL, lbessard@27: wxID_BLOCKPROPERTIESDIALOGNAME, wxID_BLOCKPROPERTIESDIALOGTYPETREE, lbessard@27: wxID_BLOCKPROPERTIESDIALOGTYPEDESC, wxID_BLOCKPROPERTIESDIALOGINPUTS, lbessard@27: wxID_BLOCKPROPERTIESDIALOGPREVIEW, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1, lbessard@27: wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, wxID_BLOCKPROPERTIESDIALOGSTATICTEXT3, lbessard@27: wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@27: lbessard@27: [CATEGORY, BLOCK] = range(2) lbessard@27: lbessard@27: class BlockPropertiesDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_BLOCKPROPERTIESDIALOG, lbessard@27: name='BlockPropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(600, 360), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Block Properties') lbessard@27: self.SetClientSize(wx.Size(600, 360)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(600, 320), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticbox1 = wx.StaticBox(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT1, lbessard@27: label='Type:', name='staticBox1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(245, 280), style=0) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, lbessard@27: label='Name:', name='staticText2', parent=self.MainPanel, lbessard@27: pos=wx.Point(274, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText3 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT2, lbessard@27: label='Inputs:', name='staticText4', parent=self.MainPanel, lbessard@27: pos=wx.Point(424, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText4 = wx.StaticText(id=wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, lbessard@27: label='Preview:', name='staticText4', parent=self.MainPanel, lbessard@27: pos=wx.Point(274, 80), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.TypeTree = wx.TreeCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPETREE, lbessard@27: name='TypeTree', parent=self.MainPanel, pos=wx.Point(34, 44), lbessard@27: size=wx.Size(225, 180), style=wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER) lbessard@27: EVT_TREE_SEL_CHANGED(self, wxID_BLOCKPROPERTIESDIALOGTYPETREE, self.OnTypeTreeItemSelected) lbessard@27: lbessard@27: self.TypeDesc = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGTYPEDESC, lbessard@27: name='TypeDesc', parent=self.MainPanel, pos=wx.Point(34, 230), lbessard@27: size=wx.Size(225, 65), style=wx.TE_READONLY|wx.TE_MULTILINE) lbessard@27: lbessard@27: self.Name = wx.TextCtrl(id=wxID_BLOCKPROPERTIESDIALOGNAME, value='', lbessard@27: name='Name', parent=self.MainPanel, pos=wx.Point(274, 48), lbessard@27: size=wx.Size(145, 24), style=0) lbessard@27: EVT_TEXT(self, wxID_BLOCKPROPERTIESDIALOGNAME, self.OnNameChanged) lbessard@27: lbessard@27: self.Inputs = wx.SpinCtrl(id=wxID_BLOCKPROPERTIESDIALOGINPUTS, lbessard@27: name='Inputs', parent=self.MainPanel, pos=wx.Point(424, 48), lbessard@27: size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=2, max=20) lbessard@27: EVT_SPINCTRL(self, wxID_BLOCKPROPERTIESDIALOGINPUTS, self.OnInputsChanged) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_BLOCKPROPERTIESDIALOGPREVIEW, lbessard@27: name='Preview', parent=self.MainPanel, pos=wx.Point(274, 104), lbessard@27: size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: self.Name.SetValue("") lbessard@27: self.Name.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Block = None lbessard@27: self.MinBlockSize = None lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) lbessard@27: lbessard@28: def FindTreeItem(self, root, name, inputs = None): lbessard@27: if root.IsOk(): lbessard@28: pydata = self.TypeTree.GetPyData(root) lbessard@28: if inputs and "inputs" in pydata: lbessard@28: same_inputs = pydata["inputs"] == inputs lbessard@28: else: lbessard@28: same_inputs = True lbessard@28: if self.TypeTree.GetItemText(root) == name and same_inputs: lbessard@27: return root lbessard@27: else: lbessard@27: item, root_cookie = self.TypeTree.GetFirstChild(root) lbessard@27: while item.IsOk(): lbessard@28: result = self.FindTreeItem(item, name, inputs) lbessard@27: if result: lbessard@27: return result lbessard@27: item, root_cookie = self.TypeTree.GetNextChild(root, root_cookie) lbessard@27: return None lbessard@27: lbessard@27: def OnOK(self, event): lbessard@27: error = [] lbessard@27: selected = self.TypeTree.GetSelection() lbessard@27: if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem(): lbessard@27: message = wxMessageDialog(self, "Form isn't complete. Valid block type must be selected!", "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif self.Name.IsEnabled() and self.Name.GetValue() == "": lbessard@27: message = wxMessageDialog(self, "Form isn't complete. Name must be filled!", "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: else: lbessard@27: self.EndModal(wxID_OK) lbessard@27: lbessard@27: def SetBlockList(self, blocktypes): lbessard@27: root = self.TypeTree.AddRoot("") lbessard@28: self.TypeTree.SetPyData(root, {"type" : CATEGORY}) lbessard@27: for category in blocktypes: lbessard@27: category_item = self.TypeTree.AppendItem(root, category["name"]) lbessard@28: self.TypeTree.SetPyData(category_item, {"type" : CATEGORY}) lbessard@27: for blocktype in category["list"]: lbessard@27: blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"]) lbessard@28: self.TypeTree.SetPyData(blocktype_item, {"type" : BLOCK, "inputs" : tuple([type for name, type, modifier in blocktype["inputs"]])}) lbessard@27: lbessard@27: def SetMinBlockSize(self, size): lbessard@27: self.MinBlockSize = size lbessard@27: lbessard@27: def SetValues(self, values): lbessard@27: for name, value in values.items(): lbessard@27: if name == "type": lbessard@28: inputs = None lbessard@28: if "inputs" in values: lbessard@28: inputs = values["inputs"] lbessard@28: item = self.FindTreeItem(self.TypeTree.GetRootItem(), value, inputs) lbessard@27: if item: lbessard@27: self.TypeTree.SelectItem(item) lbessard@27: elif name == "name": lbessard@27: self.Name.SetValue(value) lbessard@27: elif name == "extension": lbessard@27: self.Inputs.SetValue(value) lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@28: item = self.TypeTree.GetSelection() lbessard@28: values["type"] = self.TypeTree.GetItemText(item) lbessard@28: values["inputs"] = self.TypeTree.GetPyData(item)["inputs"] lbessard@27: if self.Name.GetValue() != "": lbessard@27: values["name"] = self.Name.GetValue() lbessard@27: values["width"], values["height"] = self.Block.GetSize() lbessard@27: values["extension"] = self.Inputs.GetValue() lbessard@27: return values lbessard@27: lbessard@27: def OnTypeTreeItemSelected(self, event): lbessard@27: self.Name.SetValue("") lbessard@27: selected = event.GetItem() lbessard@28: pydata = self.TypeTree.GetPyData(selected) lbessard@28: if pydata["type"] != CATEGORY: lbessard@28: blocktype = GetBlockType(self.TypeTree.GetItemText(selected), pydata["inputs"]) lbessard@27: if blocktype: lbessard@27: self.Inputs.SetValue(len(blocktype["inputs"])) lbessard@27: self.Inputs.Enable(blocktype["extensible"]) lbessard@27: self.Name.Enable(blocktype["type"] != "function") lbessard@27: self.TypeDesc.SetValue(blocktype["comment"]) lbessard@27: wxCallAfter(self.RefreshPreview) lbessard@27: else: lbessard@27: self.Name.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Inputs.SetValue(2) lbessard@27: self.TypeDesc.SetValue("") lbessard@27: wxCallAfter(self.ErasePreview) lbessard@27: else: lbessard@27: self.Name.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Inputs.SetValue(2) lbessard@27: self.TypeDesc.SetValue("") lbessard@27: wxCallAfter(self.ErasePreview) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnNameChanged(self, event): lbessard@27: if self.Name.IsEnabled(): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnInputsChanged(self, event): lbessard@27: if self.Inputs.IsEnabled(): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def ErasePreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: self.Block = None lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: item = self.TypeTree.GetSelection() lbessard@28: pydata = self.TypeTree.GetPyData(item) lbessard@28: if pydata["type"] == CATEGORY: lbessard@27: self.Block = None lbessard@27: else: lbessard@27: blocktype = self.TypeTree.GetItemText(item) lbessard@27: if blocktype: lbessard@28: self.Block = FBD_Block(self.Preview, blocktype, self.Name.GetValue(), extension = self.Inputs.GetValue(), inputs = pydata["inputs"]) lbessard@27: width, height = self.MinBlockSize lbessard@27: min_width, min_height = self.Block.GetMinSize() lbessard@27: width, height = max(min_width, width), max(min_height, height) lbessard@27: self.Block.SetSize(width, height) lbessard@27: clientsize = self.Preview.GetClientSize() lbessard@27: x = (clientsize.width - width) / 2 lbessard@27: y = (clientsize.height - height) / 2 lbessard@27: self.Block.SetPosition(x, y) lbessard@27: self.Block.Draw(dc) lbessard@27: else: lbessard@27: self.Block = None lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: if self.Block: lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Variable Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: [wxID_VARIABLEPROPERTIESDIALOG, wxID_VARIABLEPROPERTIESDIALOGMAINPANEL, lbessard@27: wxID_VARIABLEPROPERTIESDIALOGNAME, wxID_VARIABLEPROPERTIESDIALOGCLASS, lbessard@28: wxID_VARIABLEPROPERTIESDIALOGPREVIEW, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, lbessard@28: wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, lbessard@28: wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, lbessard@28: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@27: lbessard@27: class VariablePropertiesDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_VARIABLEPROPERTIESDIALOG, lbessard@27: name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@28: size=wx.Size(400, 380), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Variable Properties') lbessard@28: self.SetClientSize(wx.Size(400, 380)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(400, 280), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, lbessard@27: label='Class:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, lbessard@28: label='Expression:', name='staticText2', parent=self.MainPanel, lbessard@28: pos=wx.Point(24, 90), size=wx.Size(100, 17), style=0) lbessard@28: lbessard@28: self.staticText3 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, lbessard@28: label='Name:', name='staticText3', parent=self.MainPanel, lbessard@27: pos=wx.Point(204, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@28: self.staticText4 = wx.StaticText(id=wxID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, lbessard@28: label='Preview:', name='staticText4', parent=self.MainPanel, lbessard@28: pos=wx.Point(24, 144), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.Class = wx.Choice(id=wxID_VARIABLEPROPERTIESDIALOGCLASS, lbessard@27: name='Class', parent=self.MainPanel, pos=wx.Point(24, 48), lbessard@27: size=wx.Size(145, 24), style=0) lbessard@27: EVT_CHOICE(self, wxID_VARIABLEPROPERTIESDIALOGCLASS, self.OnClassChanged) lbessard@27: lbessard@28: self.Name = wx.ListBox(id=wxID_VARIABLEPROPERTIESDIALOGNAME, lbessard@27: name='Name', parent=self.MainPanel, pos=wx.Point(204, 48), lbessard@28: size=wx.Size(145, 90), style=wx.LB_SINGLE) lbessard@28: EVT_LISTBOX(self, wxID_VARIABLEPROPERTIESDIALOGNAME, self.OnNameChanged) lbessard@28: lbessard@28: self.Expression = wx.TextCtrl(id=wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, lbessard@28: name='Expression', parent=self.MainPanel, pos=wx.Point(24, 114), lbessard@27: size=wx.Size(145, 24), style=0) lbessard@28: EVT_TEXT(self, wxID_VARIABLEPROPERTIESDIALOGEXPRESSION, self.OnExpressionChanged) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_VARIABLEPROPERTIESDIALOGPREVIEW, lbessard@28: name='Preview', parent=self.MainPanel, pos=wx.Point(24, 170), lbessard@27: size=wx.Size(350, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: self.Variable = None lbessard@27: self.VarList = [] lbessard@27: self.MinVariableSize = None lbessard@27: self.RefreshNameList() lbessard@27: lbessard@27: for choice in ["Input", "Output", "InOut"]: lbessard@27: self.Class.Append(choice) lbessard@27: self.Class.SetStringSelection("Input") lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: lbessard@27: def RefreshNameList(self): lbessard@27: selected = self.Name.GetStringSelection() lbessard@27: self.Name.Clear() lbessard@28: self.Name.Append("") lbessard@27: for name, var_type, value_type in self.VarList: lbessard@28: if var_type in ["Local","Temp","Global","External"]: lbessard@27: self.Name.Append(name) lbessard@27: elif var_type == "Input" and self.Class.GetStringSelection() == "Input": lbessard@27: self.Name.Append(name) lbessard@27: elif var_type == "Output" and self.Class.GetStringSelection() == "Output": lbessard@27: self.Name.Append(name) lbessard@27: elif var_type == "InOut" and self.Class.GetStringSelection() == "InOut": lbessard@27: self.Name.Append(name) lbessard@27: if self.Name.FindString(selected) != wxNOT_FOUND: lbessard@27: self.Name.SetStringSelection(selected) lbessard@28: else: lbessard@28: self.Name.SetStringSelection("") lbessard@27: self.Name.Enable(self.Name.GetCount() > 0) lbessard@27: lbessard@27: def SetMinVariableSize(self, size): lbessard@27: self.MinVariableSize = size lbessard@27: lbessard@27: def SetVariables(self, vars): lbessard@27: self.VarList = vars lbessard@27: self.RefreshNameList() lbessard@27: lbessard@27: def SetValues(self, values): lbessard@27: for name, value in values.items(): lbessard@27: if name == "type": lbessard@27: if value == INPUT: lbessard@27: self.Class.SetStringSelection("Input") lbessard@27: if value == OUTPUT: lbessard@27: self.Class.SetStringSelection("Output") lbessard@27: if value == INOUT: lbessard@27: self.Class.SetStringSelection("InOut") lbessard@28: elif name == "name" and value != "": lbessard@28: if self.Name.FindString(value) != wxNOT_FOUND: lbessard@28: self.Name.SetStringSelection(value) lbessard@28: self.Expression.Enable(False) lbessard@28: else: lbessard@28: self.Expression.SetValue(value) lbessard@28: self.Name.Enable(False) lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: classtype = self.Class.GetStringSelection() lbessard@27: if classtype == "Input": lbessard@27: values["type"] = INPUT lbessard@27: elif classtype == "Output": lbessard@27: values["type"] = OUTPUT lbessard@27: elif classtype == "InOut": lbessard@27: values["type"] = INOUT lbessard@28: expression = self.Expression.GetValue() lbessard@28: if self.Expression.IsEnabled() and expression != "": lbessard@28: values["name"] = expression lbessard@28: else: lbessard@28: values["name"] = self.Name.GetStringSelection() lbessard@27: values["value_type"] = "" lbessard@27: for var_name, var_type, value_type in self.VarList: lbessard@27: if var_name == values["name"]: lbessard@27: values["value_type"] = value_type lbessard@27: values["width"], values["height"] = self.Variable.GetSize() lbessard@27: return values lbessard@27: lbessard@27: def OnClassChanged(self, event): lbessard@27: self.RefreshNameList() lbessard@28: if self.Class.GetStringSelection() == "Input": lbessard@28: self.Expression.Enable(True) lbessard@28: else: lbessard@28: self.Expression.Enable(False) lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnNameChanged(self, event): lbessard@28: if self.Name.GetStringSelection() != "": lbessard@28: self.Expression.Enable(False) lbessard@28: elif self.Class.GetStringSelection() == "Input": lbessard@28: self.Expression.Enable(True) lbessard@28: self.RefreshPreview() lbessard@28: event.Skip() lbessard@28: lbessard@28: def OnExpressionChanged(self, event): lbessard@28: if self.Expression.GetValue() != "": lbessard@28: self.Name.Enable(False) lbessard@28: else: lbessard@28: self.Name.Enable(True) lbessard@28: self.RefreshPreview() lbessard@28: event.Skip() lbessard@28: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@28: expression = self.Expression.GetValue() lbessard@28: if self.Expression.IsEnabled() and expression != "": lbessard@28: name = expression lbessard@28: else: lbessard@28: name = self.Name.GetStringSelection() lbessard@27: type = "" lbessard@27: for var_name, var_type, value_type in self.VarList: lbessard@27: if var_name == name: lbessard@27: type = value_type lbessard@27: classtype = self.Class.GetStringSelection() lbessard@27: if classtype == "Input": lbessard@27: self.Variable = FBD_Variable(self.Preview, INPUT, name, type) lbessard@27: elif classtype == "Output": lbessard@27: self.Variable = FBD_Variable(self.Preview, OUTPUT, name, type) lbessard@27: elif classtype == "InOut": lbessard@27: self.Variable = FBD_Variable(self.Preview, INOUT, name, type) lbessard@27: width, height = self.MinVariableSize lbessard@27: min_width, min_height = self.Variable.GetMinSize() lbessard@27: width, height = max(min_width, width), max(min_height, height) lbessard@27: self.Variable.SetSize(width, height) lbessard@27: clientsize = self.Preview.GetClientSize() lbessard@27: x = (clientsize.width - width) / 2 lbessard@27: y = (clientsize.height - height) / 2 lbessard@27: self.Variable.SetPosition(x, y) lbessard@27: self.Variable.Draw(dc) lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Connection Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: [wxID_CONNECTIONPROPERTIESDIALOG, wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL, lbessard@27: wxID_CONNECTIONPROPERTIESDIALOGNAME, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, lbessard@27: wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, wxID_CONNECTIONPROPERTIESDIALOGPREVIEW, lbessard@27: wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, lbessard@27: wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(9)] lbessard@27: lbessard@27: class ConnectionPropertiesDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_CONNECTIONPROPERTIESDIALOG, lbessard@27: name='ConnectionPropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(350, 220), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Connection Properties') lbessard@27: self.SetClientSize(wx.Size(350, 220)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(340, 360), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, lbessard@27: label='Type:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, lbessard@27: label='Name:', name='staticText2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 104), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText3 = wx.StaticText(id=wxID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, lbessard@27: label='Preview:', name='staticText3', parent=self.MainPanel, lbessard@27: pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.radioButton1 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, lbessard@27: label='Connector', name='radioButton1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, self.OnTypeChanged) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@27: self.radioButton2 = wx.RadioButton(id=wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, lbessard@27: label='Continuation', name='radioButton2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, self.OnTypeChanged) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@27: self.Name = wx.TextCtrl(id=wxID_CONNECTIONPROPERTIESDIALOGNAME, lbessard@27: name='Name', parent=self.MainPanel, pos=wx.Point(24, 130), lbessard@27: size=wx.Size(145, 24), style=0) lbessard@27: EVT_TEXT(self, wxID_CONNECTIONPROPERTIESDIALOGNAME, self.OnNameChanged) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_CONNECTIONPROPERTIESDIALOGPREVIEW, lbessard@27: name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), lbessard@27: size=wx.Size(150, 100), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: self.Connection = None lbessard@27: self.MinConnectionSize = None lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: lbessard@27: def SetMinConnectionSize(self, size): lbessard@27: self.MinConnectionSize = size lbessard@28: lbessard@28: def SetValues(self, values): lbessard@28: for name, value in values.items(): lbessard@28: if name == "type": lbessard@28: if value == CONNECTOR: lbessard@28: self.radioButton1.SetValue(True) lbessard@28: elif value == CONTINUATION: lbessard@28: self.radioButton2.SetValue(True) lbessard@28: elif name == "name": lbessard@28: self.Name.SetValue(value) lbessard@28: self.RefreshPreview() lbessard@28: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: if self.radioButton1.GetValue(): lbessard@27: values["type"] = CONNECTOR lbessard@27: else: lbessard@27: values["type"] = CONTINUATION lbessard@27: values["name"] = self.Name.GetValue() lbessard@27: values["width"], values["height"] = self.Connection.GetSize() lbessard@27: return values lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnNameChanged(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.Name.GetValue()) lbessard@27: else: lbessard@27: self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.Name.GetValue()) lbessard@27: width, height = self.MinConnectionSize lbessard@27: min_width, min_height = self.Connection.GetMinSize() lbessard@27: width, height = max(min_width, width), max(min_height, height) lbessard@27: self.Connection.SetSize(width, height) lbessard@27: clientsize = self.Preview.GetClientSize() lbessard@27: x = (clientsize.width - width) / 2 lbessard@27: y = (clientsize.height - height) / 2 lbessard@27: self.Connection.SetPosition(x, y) lbessard@27: self.Connection.Draw(dc) lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Edit Ladder Element Properties Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: lbessard@27: [wxID_LDELEMENTDIALOG, wxID_LDELEMENTDIALOGMAINPANEL, lbessard@27: wxID_LDELEMENTDIALOGNAME, wxID_LDELEMENTDIALOGRADIOBUTTON1, lbessard@27: wxID_LDELEMENTDIALOGRADIOBUTTON2, wxID_LDELEMENTDIALOGRADIOBUTTON3, lbessard@27: wxID_LDELEMENTDIALOGRADIOBUTTON4, wxID_LDELEMENTDIALOGPREVIEW, lbessard@27: wxID_LDELEMENTDIALOGSTATICTEXT1, wxID_LDELEMENTDIALOGSTATICTEXT2, lbessard@27: wxID_LDELEMENTDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@27: lbessard@27: class LDElementDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt, title, labels): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_LDELEMENTDIALOG, lbessard@27: name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title=title) lbessard@27: self.SetClientSize(wx.Size(350, 260)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_LDELEMENTDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT1, lbessard@27: label='Modifier:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT2, lbessard@27: label='Name:', name='staticText2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 150), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText3 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT3, lbessard@27: label='Preview:', name='staticText3', parent=self.MainPanel, lbessard@27: pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.radioButton1 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON1, lbessard@27: label=labels[0], name='radioButton1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON1, self.OnTypeChanged) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@27: self.radioButton2 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON2, lbessard@27: label=labels[1], name='radioButton2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON2, self.OnTypeChanged) lbessard@27: lbessard@27: self.radioButton3 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON3, lbessard@27: label=labels[2], name='radioButton3', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 96), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON3, self.OnTypeChanged) lbessard@27: lbessard@27: self.radioButton4 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON4, lbessard@27: label=labels[3], name='radioButton4', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 120), size=wx.Size(128, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON4, self.OnTypeChanged) lbessard@27: lbessard@27: self.Name = wx.Choice(id=wxID_LDELEMENTDIALOGNAME, lbessard@27: name='Name', parent=self.MainPanel, pos=wx.Point(24, 174), lbessard@27: size=wx.Size(145, 24), style=0) lbessard@27: EVT_CHOICE(self, wxID_LDELEMENTDIALOGNAME, self.OnNameChanged) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_LDELEMENTDIALOGPREVIEW, lbessard@27: name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), lbessard@27: size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent, type): lbessard@27: self.Type = type lbessard@27: if type == "contact": lbessard@27: self._init_ctrls(parent, "Edit Contact Values", ['Normal','Negate','Rising Edge','Falling Edge']) lbessard@27: self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "") lbessard@27: elif type == "coil": lbessard@27: self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset']) lbessard@27: self.Element = LD_Coil(self.Preview, COIL_NORMAL, "") lbessard@27: self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2) lbessard@27: lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: lbessard@28: def SetElementSize(self, size): lbessard@27: min_width, min_height = self.Element.GetMinSize() lbessard@28: width, height = max(min_width, size[0]), max(min_height, size[1]) lbessard@27: self.Element.SetSize(width, height) lbessard@27: self.Element.SetPosition((150 - width) / 2, (150 - height) / 2) lbessard@27: lbessard@27: def SetVariables(self, vars): lbessard@27: self.Name.Clear() lbessard@27: for name in vars: lbessard@27: self.Name.Append(name) lbessard@27: self.Name.Enable(self.Name.GetCount() > 0) lbessard@27: lbessard@27: def SetValues(self, values): lbessard@27: for name, value in values.items(): lbessard@27: if name == "name": lbessard@27: self.Element.SetName(value) lbessard@27: self.Name.SetStringSelection(value) lbessard@27: elif name == "type": lbessard@27: self.Element.SetType(value) lbessard@27: if self.Type == "contact": lbessard@27: if value == CONTACT_NORMAL: lbessard@27: self.radioButton1.SetValue(True) lbessard@27: elif value == CONTACT_REVERSE: lbessard@27: self.radioButton2.SetValue(True) lbessard@27: elif value == CONTACT_RISING: lbessard@27: self.radioButton3.SetValue(True) lbessard@27: elif value == CONTACT_FALLING: lbessard@27: self.radioButton4.SetValue(True) lbessard@27: elif self.Type == "coil": lbessard@27: if value == COIL_NORMAL: lbessard@27: self.radioButton1.SetValue(True) lbessard@27: elif value == COIL_REVERSE: lbessard@27: self.radioButton2.SetValue(True) lbessard@27: elif value == COIL_SET: lbessard@27: self.radioButton3.SetValue(True) lbessard@27: elif value == COIL_RESET: lbessard@27: self.radioButton4.SetValue(True) lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: values["name"] = self.Element.GetName() lbessard@27: values["type"] = self.Element.GetType() lbessard@27: values["width"], values["height"] = self.Element.GetSize() lbessard@27: return values lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: if self.Type == "contact": lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Element.SetType(CONTACT_NORMAL) lbessard@27: elif self.radioButton2.GetValue(): lbessard@27: self.Element.SetType(CONTACT_REVERSE) lbessard@27: elif self.radioButton3.GetValue(): lbessard@27: self.Element.SetType(CONTACT_RISING) lbessard@27: elif self.radioButton4.GetValue(): lbessard@27: self.Element.SetType(CONTACT_FALLING) lbessard@27: elif self.Type == "coil": lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Element.SetType(COIL_NORMAL) lbessard@27: elif self.radioButton2.GetValue(): lbessard@27: self.Element.SetType(COIL_REVERSE) lbessard@27: elif self.radioButton3.GetValue(): lbessard@27: self.Element.SetType(COIL_SET) lbessard@27: elif self.radioButton4.GetValue(): lbessard@27: self.Element.SetType(COIL_RESET) lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnNameChanged(self, event): lbessard@27: self.Element.SetName(self.Name.GetStringSelection()) lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: self.Element.Draw(dc) lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Edit Ladder Power Rail Properties Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: lbessard@27: [wxID_LDPOWERRAILDIALOG, wxID_LDPOWERRAILDIALOGMAINPANEL, lbessard@27: wxID_LDPOWERRAILDIALOGTYPE, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, lbessard@27: wxID_LDPOWERRAILDIALOGRADIOBUTTON2, wxID_LDPOWERRAILDIALOGPREVIEW, lbessard@27: wxID_LDPOWERRAILDIALOGSTATICTEXT1, wxID_LDPOWERRAILDIALOGSTATICTEXT2, lbessard@27: wxID_LDPOWERRAILDIALOGSTATICTEXT3, wxID_LDPOWERRAILDIALOGPINNUMBER, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@27: lbessard@27: class LDPowerRailDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_LDPOWERRAILDIALOG, lbessard@27: name='PowerRailDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Power Rail Properties') lbessard@27: self.SetClientSize(wx.Size(350, 260)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_LDPOWERRAILDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT1, lbessard@27: label='Type:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT2, lbessard@27: label='Pin number:', name='staticText2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 100), size=wx.Size(70, 17), style=0) lbessard@27: lbessard@27: self.staticText3 = wx.StaticText(id=wxID_LDPOWERRAILDIALOGSTATICTEXT3, lbessard@27: label='Preview:', name='staticText3', parent=self.MainPanel, lbessard@27: pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.radioButton1 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON1, lbessard@27: label='Left PowerRail', name='radioButton1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON1, self.OnTypeChanged) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@27: self.radioButton2 = wx.RadioButton(id=wxID_LDPOWERRAILDIALOGRADIOBUTTON2, lbessard@27: label='Right PowerRail', name='radioButton2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_LDPOWERRAILDIALOGRADIOBUTTON2, self.OnTypeChanged) lbessard@27: lbessard@27: self.PinNumber = wx.SpinCtrl(id=wxID_LDPOWERRAILDIALOGPINNUMBER, lbessard@27: name='PinNumber', parent=self.MainPanel, pos=wx.Point(24, 124), lbessard@27: size=wx.Size(145, 24), style=wxSP_ARROW_KEYS, min=1, max=20) lbessard@27: EVT_SPINCTRL(self, wxID_LDPOWERRAILDIALOGPINNUMBER, self.OnPinNumberChanged) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_LDPOWERRAILDIALOGPREVIEW, lbessard@27: name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48), lbessard@27: size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent, type = LEFTRAIL, number = 1): lbessard@27: self._init_ctrls(parent) lbessard@27: self.Type = type lbessard@27: if type == LEFTRAIL: lbessard@27: self.radioButton1.SetValue(True) lbessard@27: elif type == RIGHTRAIL: lbessard@27: self.radioButton2.SetValue(True) lbessard@27: self.PinNumber.SetValue(number) lbessard@27: lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: lbessard@27: self.PowerRailMinSize = (0, 0) lbessard@27: self.PowerRail = None lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: lbessard@27: def SetMinSize(self, size): lbessard@27: self.PowerRailMinSize = size lbessard@28: self.RefreshPreview() lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: values["type"] = self.Type lbessard@27: values["number"] = self.PinNumber.GetValue() lbessard@27: values["width"], values["height"] = self.PowerRail.GetSize() lbessard@27: return values lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Type = LEFTRAIL lbessard@27: elif self.radioButton2.GetValue(): lbessard@27: self.Type = RIGHTRAIL lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnPinNumberChanged(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = [True for i in xrange(self.PinNumber.GetValue())]) lbessard@27: min_width, min_height = self.PowerRail.GetMinSize() lbessard@27: width, height = max(min_width, self.PowerRailMinSize[0]), max(min_height, self.PowerRailMinSize[1]) lbessard@27: self.PowerRail.SetSize(width, height) lbessard@27: self.PowerRail.RefreshConnectors() lbessard@27: self.PowerRail.SetPosition((150 - width) / 2, (150 - height) / 2) lbessard@27: self.PowerRail.Draw(dc) lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Edit Transition Content Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: [wxID_TRANSITIONCONTENTDIALOG, wxID_TRANSITIONCONTENTDIALOGMAINPANEL, lbessard@27: wxID_TRANSITIONCONTENTDIALOGREFERENCE, wxID_TRANSITIONCONTENTDIALOGINLINE, lbessard@27: wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(6)] lbessard@27: lbessard@27: class TransitionContentDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_TRANSITIONCONTENTDIALOG, lbessard@27: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Edit transition') lbessard@27: self.SetClientSize(wx.Size(300, 200)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_TRANSITIONCONTENTDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.radioButton1 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, lbessard@27: label='Reference', name='radioButton1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, self.OnTypeChanged) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@27: self.Reference = wx.Choice(id=wxID_TRANSITIONCONTENTDIALOGREFERENCE, lbessard@27: name='Reference', parent=self.MainPanel, pos=wx.Point(48, 48), lbessard@27: size=wx.Size(200, 24), style=0) lbessard@27: lbessard@27: self.radioButton2 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, lbessard@27: label='Inline', name='radioButton2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 72), size=wx.Size(114, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, self.OnTypeChanged) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@27: self.Inline = wx.TextCtrl(id=wxID_TRANSITIONCONTENTDIALOGINLINE, lbessard@27: name='Inline', parent=self.MainPanel, pos=wx.Point(48, 96), lbessard@27: size=wx.Size(200, 24), style=0) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: lbessard@27: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) lbessard@27: lbessard@27: def OnOK(self, event): lbessard@27: error = [] lbessard@27: if self.radioButton1.GetValue() and self.Reference.GetStringSelection() == "": lbessard@27: error.append("Reference") lbessard@27: if self.radioButton2.GetValue() and self.Inline.GetValue() == "": lbessard@27: error.append("Inline") lbessard@27: if len(error) > 0: lbessard@27: text = "" lbessard@27: for i, item in enumerate(error): lbessard@27: if i == 0: lbessard@27: text += item lbessard@27: elif i == len(error) - 1: lbessard@27: text += " and %s"%item lbessard@27: else: lbessard@27: text += ", %s"%item lbessard@27: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: else: lbessard@27: self.EndModal(wxID_OK) lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Reference.Enable(True) lbessard@27: self.Inline.Enable(False) lbessard@27: else: lbessard@27: self.Reference.Enable(False) lbessard@27: self.Inline.Enable(True) lbessard@27: event.Skip() lbessard@27: lbessard@27: def SetTransitions(self, transitions): lbessard@27: for transition in transitions: lbessard@27: self.Reference.Append(transition) lbessard@27: lbessard@27: def SetValues(self, values): lbessard@27: if values["type"] == "reference": lbessard@27: self.radioButton1.SetValue(True) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: self.Reference.Enable(True) lbessard@27: self.Inline.Enable(False) lbessard@27: self.Reference.SetStringSelection(values["value"]) lbessard@27: elif values["type"] == "inline": lbessard@27: self.radioButton1.SetValue(False) lbessard@27: self.radioButton2.SetValue(True) lbessard@27: self.Reference.Enable(False) lbessard@27: self.Inline.Enable(True) lbessard@27: self.Inline.SetValue(values["value"]) lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: if self.radioButton1.GetValue(): lbessard@27: values["type"] = "reference" lbessard@27: values["value"] = self.Reference.GetStringSelection() lbessard@27: else: lbessard@27: values["type"] = "inline" lbessard@27: values["value"] = self.Inline.GetValue() lbessard@27: return values lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Divergence Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: [wxID_DIVERGENCECREATEDIALOG, wxID_DIVERGENCECREATEDIALOGMAINPANEL, lbessard@27: wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, lbessard@27: wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, lbessard@27: wxID_DIVERGENCECREATEDIALOGSEQUENCES, wxID_DIVERGENCECREATEDIALOGPREVIEW, lbessard@27: wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, lbessard@27: wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@27: lbessard@27: class DivergenceCreateDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_DIVERGENCECREATEDIALOG, lbessard@27: name='DivergencePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Create a new divergence or convergence') lbessard@27: self.SetClientSize(wx.Size(500, 260)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(600, 220), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, lbessard@27: label='Type:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(200, 17), style=0) lbessard@27: lbessard@27: self.radioButton1 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, lbessard@27: label='Selection Divergence', name='radioButton1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 48), size=wx.Size(200, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, self.OnTypeChanged) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@27: self.radioButton2 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, lbessard@27: label='Selection Convergence', name='radioButton2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 72), size=wx.Size(200, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, self.OnTypeChanged) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@27: self.radioButton3 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, lbessard@27: label='Simultaneous Divergence', name='radioButton3', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 96), size=wx.Size(200, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, self.OnTypeChanged) lbessard@27: self.radioButton3.SetValue(False) lbessard@27: lbessard@27: self.radioButton4 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, lbessard@27: label='Simultaneous Convergence', name='radioButton4', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 120), size=wx.Size(200, 24), style=0) lbessard@27: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, self.OnTypeChanged) lbessard@27: self.radioButton4.SetValue(False) lbessard@27: lbessard@27: self.staticText2 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, lbessard@27: label='Number of sequences:', name='staticText2', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 150), size=wx.Size(200, 17), style=0) lbessard@27: lbessard@27: self.Sequences = wx.SpinCtrl(id=wxID_DIVERGENCECREATEDIALOGSEQUENCES, lbessard@27: name='Sequences', parent=self.MainPanel, pos=wx.Point(24, 174), lbessard@27: size=wx.Size(200, 24), style=0, min=2, max=20) lbessard@27: EVT_SPINCTRL(self, wxID_DIVERGENCECREATEDIALOGSEQUENCES, self.OnSequencesChanged) lbessard@27: lbessard@27: self.staticText3 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, lbessard@27: label='Preview:', name='staticText3', parent=self.MainPanel, lbessard@27: pos=wx.Point(250, 24), size=wx.Size(100, 17), style=0) lbessard@27: lbessard@27: self.Preview = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGPREVIEW, lbessard@27: name='Preview', parent=self.MainPanel, pos=wx.Point(250, 48), lbessard@27: size=wx.Size(225, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@27: self.Preview.SetBackgroundColour(wxColour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: lbessard@27: self.Divergence = None lbessard@27: self.MinSize = (0, 0) lbessard@27: lbessard@27: EVT_PAINT(self, self.OnPaint) lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = {} lbessard@27: if self.radioButton1.GetValue(): lbessard@27: values["type"] = SELECTION_DIVERGENCE lbessard@27: elif self.radioButton2.GetValue(): lbessard@27: values["type"] = SELECTION_CONVERGENCE lbessard@27: elif self.radioButton3.GetValue(): lbessard@27: values["type"] = SIMULTANEOUS_DIVERGENCE lbessard@27: else: lbessard@27: values["type"] = SIMULTANEOUS_CONVERGENCE lbessard@27: values["number"] = self.Sequences.GetValue() lbessard@27: return values lbessard@27: lbessard@27: def SetMinSize(self, size): lbessard@27: self.MinSize = size lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnSequencesChanged(self, event): lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@27: dc = wxClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: if self.radioButton1.GetValue(): lbessard@27: self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue()) lbessard@27: elif self.radioButton2.GetValue(): lbessard@27: self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue()) lbessard@27: elif self.radioButton3.GetValue(): lbessard@27: self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue()) lbessard@27: else: lbessard@27: self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue()) lbessard@27: width, height = self.Divergence.GetSize() lbessard@27: min_width, min_height = max(width, self.MinSize[0]), max(height, self.MinSize[1]) lbessard@27: self.Divergence.SetSize(min_width, min_height) lbessard@27: clientsize = self.Preview.GetClientSize() lbessard@27: x = (clientsize.width - min_width) / 2 lbessard@27: y = (clientsize.height - min_height) / 2 lbessard@27: self.Divergence.SetPosition(x, y) lbessard@27: self.Divergence.Draw(dc) lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@27: self.RefreshPreview() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Action Block Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: class ActionTable(wxPyGridTableBase): lbessard@27: lbessard@27: """ lbessard@27: A custom wxGrid Table using user supplied data lbessard@27: """ lbessard@27: def __init__(self, parent, data, colnames): lbessard@27: # The base class must be initialized *first* lbessard@27: wxPyGridTableBase.__init__(self) lbessard@27: self.data = data lbessard@27: self.colnames = colnames lbessard@27: self.Parent = parent lbessard@27: # XXX lbessard@27: # we need to store the row length and collength to lbessard@27: # see if the table has changed size lbessard@27: self._rows = self.GetNumberRows() lbessard@27: self._cols = self.GetNumberCols() lbessard@27: lbessard@27: def GetNumberCols(self): lbessard@27: return len(self.colnames) lbessard@27: lbessard@27: def GetNumberRows(self): lbessard@27: return len(self.data) lbessard@27: lbessard@27: def GetColLabelValue(self, col): lbessard@27: if col < len(self.colnames): lbessard@27: return self.colnames[col] lbessard@27: lbessard@27: def GetRowLabelValues(self, row): lbessard@27: return row lbessard@27: lbessard@27: def GetValue(self, row, col): lbessard@27: if row < self.GetNumberRows(): lbessard@27: name = str(self.data[row].get(self.GetColLabelValue(col), "")) lbessard@27: return name lbessard@27: lbessard@27: def GetValueByName(self, row, colname): lbessard@27: return self.data[row].get(colname) lbessard@27: lbessard@27: def SetValue(self, row, col, value): lbessard@27: if col < len(self.colnames): lbessard@27: self.data[row][self.GetColLabelValue(col)] = value lbessard@27: lbessard@27: def ResetView(self, grid): lbessard@27: """ lbessard@27: (wxGrid) -> Reset the grid view. Call this to lbessard@27: update the grid if rows and columns have been added or deleted lbessard@27: """ lbessard@27: grid.BeginBatch() lbessard@27: for current, new, delmsg, addmsg in [ lbessard@27: (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@27: (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), lbessard@27: ]: lbessard@27: if new < current: lbessard@27: msg = wxGridTableMessage(self,delmsg,new,current-new) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: elif new > current: lbessard@27: msg = wxGridTableMessage(self,addmsg,new-current) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: self.UpdateValues(grid) lbessard@27: grid.EndBatch() lbessard@27: lbessard@27: self._rows = self.GetNumberRows() lbessard@27: self._cols = self.GetNumberCols() lbessard@27: # update the column rendering scheme lbessard@27: self._updateColAttrs(grid) lbessard@27: lbessard@27: # update the scrollbars and the displayed part of the grid lbessard@27: grid.AdjustScrollbars() lbessard@27: grid.ForceRefresh() lbessard@27: lbessard@27: def UpdateValues(self, grid): lbessard@27: """Update all displayed values""" lbessard@27: # This sends an event to the grid table to update all of the values lbessard@27: msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: lbessard@27: def _updateColAttrs(self, grid): lbessard@27: """ lbessard@27: wxGrid -> update the column attributes to add the lbessard@27: appropriate renderer given the column name. lbessard@27: lbessard@27: Otherwise default to the default renderer. lbessard@27: """ lbessard@27: lbessard@27: for col in range(self.GetNumberCols()): lbessard@27: attr = wxGridCellAttr() lbessard@27: attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) lbessard@27: grid.SetColAttr(col, attr) lbessard@27: grid.SetColSize(col, self.Parent.ColSizes[col]) lbessard@27: lbessard@27: typelist = None lbessard@27: accesslist = None lbessard@27: for row in range(self.GetNumberRows()): lbessard@27: for col in range(self.GetNumberCols()): lbessard@27: editor = None lbessard@27: renderer = None lbessard@27: readonly = False lbessard@27: colname = self.GetColLabelValue(col) lbessard@27: if colname == "Qualifier": lbessard@27: editor = wxGridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.QualifierList) lbessard@27: if colname == "Duration": lbessard@27: editor = wxGridCellTextEditor() lbessard@27: renderer = wxGridCellStringRenderer() lbessard@27: if self.Parent.DurationList[self.data[row]["Qualifier"]]: lbessard@27: readonly = False lbessard@27: else: lbessard@27: readonly = True lbessard@27: self.data[row]["Duration"] = "" lbessard@27: elif colname == "Type": lbessard@27: editor = wxGridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.TypeList) lbessard@27: elif colname == "Value": lbessard@27: type = self.data[row]["Type"] lbessard@27: if type == "Action": lbessard@27: editor = wxGridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.ActionList) lbessard@27: elif type == "Variable": lbessard@27: editor = wxGridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.VariableList) lbessard@27: elif type == "Inline": lbessard@27: editor = wxGridCellTextEditor() lbessard@27: renderer = wxGridCellStringRenderer() lbessard@27: elif colname == "Indicator": lbessard@27: editor = wxGridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.VariableList) lbessard@27: lbessard@27: grid.SetCellEditor(row, col, editor) lbessard@27: grid.SetCellRenderer(row, col, renderer) lbessard@27: grid.SetReadOnly(row, col, readonly) lbessard@27: lbessard@27: grid.SetCellBackgroundColour(row, col, wxWHITE) lbessard@27: lbessard@27: def SetData(self, data): lbessard@27: self.data = data lbessard@27: lbessard@27: def GetData(self): lbessard@27: return self.data lbessard@27: lbessard@27: def GetCurrentIndex(self): lbessard@27: return self.CurrentIndex lbessard@27: lbessard@27: def SetCurrentIndex(self, index): lbessard@27: self.CurrentIndex = index lbessard@27: lbessard@27: def AppendRow(self, row_content): lbessard@27: self.data.append(row_content) lbessard@27: lbessard@27: def RemoveRow(self, row_index): lbessard@27: self.data.pop(row_index) lbessard@27: lbessard@27: def MoveRow(self, row_index, move, grid): lbessard@27: new_index = max(0, min(row_index + move, len(self.data) - 1)) lbessard@27: if new_index != row_index: lbessard@27: self.data.insert(new_index, self.data.pop(row_index)) lbessard@27: grid.SetGridCursor(new_index, grid.GetGridCursorCol()) lbessard@27: lbessard@27: def Empty(self): lbessard@27: self.data = [] lbessard@27: self.editors = [] lbessard@27: lbessard@27: [wxID_ACTIONBLOCKDIALOG, wxID_ACTIONBLOCKDIALOGMAINPANEL, lbessard@27: wxID_ACTIONBLOCKDIALOGVARIABLESGRID, wxID_ACTIONBLOCKDIALOGSTATICTEXT1, lbessard@27: wxID_ACTIONBLOCKDIALOGADDBUTTON,wxID_ACTIONBLOCKDIALOGDELETEBUTTON, lbessard@27: wxID_ACTIONBLOCKDIALOGUPBUTTON, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(8)] lbessard@27: lbessard@27: class ActionBlockDialog(wx.Dialog): lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@27: # generated method, don't edit lbessard@27: lbessard@27: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@27: # generated method, don't edit lbessard@27: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@27: # generated method, don't edit lbessard@27: wx.Dialog.__init__(self, id=wxID_ACTIONBLOCKDIALOG, lbessard@27: name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@27: size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Edit action block properties') lbessard@27: self.SetClientSize(wx.Size(500, 300)) lbessard@27: lbessard@27: self.MainPanel = wx.Panel(id=wxID_ACTIONBLOCKDIALOGMAINPANEL, lbessard@27: name='MainPanel', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(500, 300), style=wx.TAB_TRAVERSAL) lbessard@27: self.MainPanel.SetAutoLayout(True) lbessard@27: lbessard@27: self.staticText1 = wx.StaticText(id=wxID_ACTIONBLOCKDIALOGSTATICTEXT1, lbessard@27: label='Actions:', name='staticText1', parent=self.MainPanel, lbessard@27: pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) lbessard@27: lbessard@27: self.ActionsGrid = wx.grid.Grid(id=wxID_ACTIONBLOCKDIALOGVARIABLESGRID, lbessard@27: name='ActionsGrid', parent=self.MainPanel, pos=wx.Point(24, 44), lbessard@27: size=wx.Size(450, 150), style=wxVSCROLL) lbessard@27: self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, lbessard@27: 'Sans')) lbessard@27: self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, lbessard@27: False, 'Sans')) lbessard@27: self.ActionsGrid.DisableDragGridSize() lbessard@27: self.ActionsGrid.EnableScrolling(False, True) lbessard@27: EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange) lbessard@27: lbessard@27: self.AddButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGADDBUTTON, label='Add', lbessard@27: name='AddButton', parent=self.MainPanel, pos=wx.Point(245, 204), lbessard@27: size=wx.Size(72, 32), style=0) lbessard@27: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGADDBUTTON, self.OnAddButton) lbessard@27: lbessard@27: self.DeleteButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete', lbessard@27: name='DeleteButton', parent=self.MainPanel, pos=wx.Point(325, 204), lbessard@27: size=wx.Size(72, 32), style=0) lbessard@27: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDELETEBUTTON, self.OnDeleteButton) lbessard@27: lbessard@27: self.UpButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGUPBUTTON, label='^', lbessard@27: name='UpButton', parent=self.MainPanel, pos=wx.Point(405, 204), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@27: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGUPBUTTON, self.OnUpButton) lbessard@27: lbessard@27: self.DownButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', lbessard@27: name='DownButton', parent=self.MainPanel, pos=wx.Point(445, 204), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@27: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, self.OnDownButton) lbessard@27: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) lbessard@27: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE) lbessard@27: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) lbessard@27: lbessard@27: self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} lbessard@27: self.Table = ActionTable(self, [], ["Qualifier","Duration","Type","Value","Indicator"]) lbessard@27: self.TypeList = "Action,Variable,Inline" lbessard@27: self.ColSizes = [60, 90, 80, 110, 80] lbessard@27: self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT] lbessard@27: lbessard@27: self.ActionsGrid.SetTable(self.Table) lbessard@27: self.ActionsGrid.SetRowLabelSize(0) lbessard@27: lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: lbessard@27: def OnAddButton(self, event): lbessard@27: self.Table.AppendRow(self.DefaultValue.copy()) lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDeleteButton(self, event): lbessard@27: row = self.ActionsGrid.GetGridCursorRow() lbessard@27: self.Table.RemoveRow(row) lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnUpButton(self, event): lbessard@27: row = self.ActionsGrid.GetGridCursorRow() lbessard@27: self.Table.MoveRow(row, -1, self.ActionsGrid) lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnDownButton(self, event): lbessard@27: row = self.ActionsGrid.GetGridCursorRow() lbessard@27: self.Table.MoveRow(row, 1, self.ActionsGrid) lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnActionsGridCellChange(self, event): lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: event.Skip() lbessard@27: lbessard@27: def SetQualifierList(self, list): lbessard@27: self.QualifierList = "" lbessard@27: sep = "" lbessard@27: for qualifier in list.keys(): lbessard@27: self.QualifierList += "%s%s"%(sep, qualifier) lbessard@27: sep = "," lbessard@27: self.DurationList = list lbessard@27: lbessard@27: def SetVariableList(self, list): lbessard@27: self.VariableList = "" lbessard@27: sep = "" lbessard@27: for variable in list: lbessard@27: self.VariableList += "%s%s"%(sep, variable["Name"]) lbessard@27: sep = "," lbessard@27: lbessard@27: def SetActionList(self, list): lbessard@27: self.ActionList = "" lbessard@27: sep = "" lbessard@27: for action in list: lbessard@27: self.ActionList += "%s%s"%(sep, action) lbessard@27: sep = "," lbessard@27: lbessard@27: def SetValues(self, actions): lbessard@27: for action in actions: lbessard@27: row = {"Qualifier" : action["qualifier"], "Value" : action["value"]} lbessard@27: if action["type"] == "reference": lbessard@27: if action["value"] in self.ActionList: lbessard@27: row["Type"] = "Action" lbessard@27: elif action["value"] in self.VariableList: lbessard@27: row["Type"] = "Variable" lbessard@27: else: lbessard@27: row["Type"] = "Inline" lbessard@27: else: lbessard@27: row["Type"] = "Inline" lbessard@27: if "duration" in action: lbessard@27: row["Duration"] = action["duration"] lbessard@27: else: lbessard@27: row["Duration"] = "" lbessard@27: if "indicator" in action: lbessard@27: row["Indicator"] = action["indicator"] lbessard@27: else: lbessard@27: row["Indicator"] = "" lbessard@27: self.Table.AppendRow(row) lbessard@27: self.Table.ResetView(self.ActionsGrid) lbessard@27: lbessard@27: def GetValues(self): lbessard@27: values = [] lbessard@27: for data in self.Table.GetData(): lbessard@27: action = {"qualifier" : data["Qualifier"], "value" : data["Value"]} lbessard@27: if data["Type"] in ["Action", "Variable"]: lbessard@27: action["type"] = "reference" lbessard@27: else: lbessard@27: action["type"] = "inline" lbessard@27: if data["Duration"] != "": lbessard@27: action["duration"] = data["Duration"] lbessard@27: if data["Indicator"] != "": lbessard@27: action["indicator"] = data["Indicator"] lbessard@27: values.append(action) lbessard@27: return values lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Edit Step Name Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: class StepNameDialog(wxTextEntryDialog): lbessard@27: lbessard@27: def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", lbessard@27: style = wxOK|wxCANCEL|wxCENTRE, pos = wxDefaultPosition): lbessard@27: wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) lbessard@27: lbessard@27: self.PouNames = [] lbessard@27: self.Variables = [] lbessard@27: self.StepNames = [] lbessard@27: lbessard@27: EVT_BUTTON(self, self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId(), self.OnOK) lbessard@27: lbessard@27: def OnOK(self, event): lbessard@27: step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() lbessard@27: if step_name == "": lbessard@27: message = wxMessageDialog(self, "You must type a name!", "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif not TestIdentifier(step_name): lbessard@27: message = wxMessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in IEC_KEYWORDS: lbessard@27: message = wxMessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.PouNames: lbessard@27: message = wxMessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.Variables: lbessard@27: message = wxMessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.StepNames: lbessard@27: message = wxMessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wxOK|wxICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: else: lbessard@27: self.EndModal(wxID_OK) lbessard@27: lbessard@27: def SetPouNames(self, pou_names): lbessard@27: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@27: lbessard@27: def SetVariables(self, variables): lbessard@27: self.Variables = [var["Name"].upper() for var in variables] lbessard@27: lbessard@27: def SetStepNames(self, step_names): lbessard@27: self.StepNames = [step_name.upper() for step_name in step_names] lbessard@27: lbessard@42: def GetValue(self): lbessard@42: return self.GetSizer().GetItem(1).GetWindow().GetValue()