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@58: #Copyright (C) 2007: 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@58: #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: import wx lbessard@64: import wx.grid lbessard@27: lbessard@45: from graphics import * lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Block Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: [ID_BLOCKPROPERTIESDIALOG, ID_BLOCKPROPERTIESDIALOGNAME, lbessard@64: ID_BLOCKPROPERTIESDIALOGTYPETREE, ID_BLOCKPROPERTIESDIALOGTYPEDESC, lbessard@64: ID_BLOCKPROPERTIESDIALOGINPUTS, ID_BLOCKPROPERTIESDIALOGPREVIEW, lbessard@118: ID_BLOCKPROPERTIESDIALOGEXECUTIONORDER, ID_BLOCKPROPERTIESDIALOGSTATICTEXT1, lbessard@118: ID_BLOCKPROPERTIESDIALOGSTATICTEXT2, ID_BLOCKPROPERTIESDIALOGSTATICTEXT3, lbessard@118: ID_BLOCKPROPERTIESDIALOGSTATICTEXT4, ID_BLOCKPROPERTIESDIALOGSTATICTEXT5, lbessard@118: ] = [wx.NewId() for _init_ctrls in range(12)] lbessard@27: lbessard@27: [CATEGORY, BLOCK] = range(2) lbessard@27: lbessard@27: class BlockPropertiesDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@58: lbessard@58: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(0) lbessard@58: lbessard@58: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftBoxSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@58: lbessard@58: def _init_coll_LeftBoxSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.TypeTree, 3, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@64: parent.AddWindow(self.TypeDesc, 1, border=0, flag=wx.GROW) lbessard@58: lbessard@58: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.RightUpGridSizer, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@58: lbessard@58: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(2) lbessard@58: lbessard@58: def _init_coll_RightUpGridSizer_Items(self, parent): lbessard@118: parent.AddWindow(self.staticText2, 0, border=4, flag=wx.GROW|wx.TOP) lbessard@95: parent.AddWindow(self.BlockName, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.staticText3, 0, border=4, flag=wx.GROW|wx.TOP) lbessard@64: parent.AddWindow(self.Inputs, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.staticText4, 0, border=4, flag=wx.GROW|wx.TOP) lbessard@118: parent.AddWindow(self.ExecutionOrder, 0, border=0, flag=wx.GROW) lbessard@118: lbessard@27: def _init_sizers(self): lbessard@58: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@64: self.LeftBoxSizer = wx.StaticBoxSizer(self.staticbox1, wx.VERTICAL) lbessard@58: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) lbessard@118: self.RightUpGridSizer = wx.GridSizer(cols=2, hgap=5, rows=3, vgap=5) lbessard@58: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@58: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@58: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@58: self._init_coll_LeftBoxSizer_Items(self.LeftBoxSizer) lbessard@58: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@58: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@58: self._init_coll_RightUpGridSizer_Items(self.RightUpGridSizer) lbessard@58: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@27: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_BLOCKPROPERTIESDIALOG, lbessard@27: name='BlockPropertiesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@118: size=wx.Size(600, 380), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, lbessard@27: title='Block Properties') lbessard@118: self.SetClientSize(wx.Size(600, 380)) lbessard@27: lbessard@64: self.staticbox1 = wx.StaticBox(id=ID_BLOCKPROPERTIESDIALOGSTATICTEXT1, lbessard@58: label='Type:', name='staticBox1', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_BLOCKPROPERTIESDIALOGSTATICTEXT2, lbessard@58: label='Name:', name='staticText2', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText3 = wx.StaticText(id=ID_BLOCKPROPERTIESDIALOGSTATICTEXT2, lbessard@58: label='Inputs:', name='staticText4', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText4 = wx.StaticText(id=ID_BLOCKPROPERTIESDIALOGSTATICTEXT4, lbessard@118: label='Execution Order:', name='staticText4', parent=self, lbessard@118: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@118: lbessard@118: self.staticText5 = wx.StaticText(id=ID_BLOCKPROPERTIESDIALOGSTATICTEXT5, lbessard@118: label='Preview:', name='staticText5', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@95: if wx.Platform == '__WXMSW__': lbessard@95: treestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER lbessard@95: else: lbessard@95: treestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER lbessard@64: self.TypeTree = wx.TreeCtrl(id=ID_BLOCKPROPERTIESDIALOGTYPETREE, lbessard@58: name='TypeTree', parent=self, pos=wx.Point(0, 0), lbessard@105: size=wx.Size(0, 0), style=treestyle) lbessard@64: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTypeTreeItemSelected, lbessard@64: id=ID_BLOCKPROPERTIESDIALOGTYPETREE) lbessard@64: lbessard@64: self.TypeDesc = wx.TextCtrl(id=ID_BLOCKPROPERTIESDIALOGTYPEDESC, lbessard@58: name='TypeDesc', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 0), style=wx.TE_READONLY|wx.TE_MULTILINE) lbessard@27: lbessard@95: self.BlockName = wx.TextCtrl(id=ID_BLOCKPROPERTIESDIALOGNAME, value='', lbessard@95: name='BlockName', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_BLOCKPROPERTIESDIALOGNAME) lbessard@64: lbessard@64: self.Inputs = wx.SpinCtrl(id=ID_BLOCKPROPERTIESDIALOGINPUTS, lbessard@58: name='Inputs', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=2, max=20) lbessard@64: self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, id=ID_BLOCKPROPERTIESDIALOGINPUTS) lbessard@64: lbessard@118: self.ExecutionOrder = wx.SpinCtrl(id=ID_BLOCKPROPERTIESDIALOGEXECUTIONORDER, lbessard@118: name='ExecutionOrder', parent=self, pos=wx.Point(0, 0), lbessard@118: size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0) lbessard@118: self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, id=ID_BLOCKPROPERTIESDIALOGEXECUTIONORDER) lbessard@118: lbessard@64: self.Preview = wx.Panel(id=ID_BLOCKPROPERTIESDIALOGPREVIEW, lbessard@58: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "GetBlockType", self.Controler.GetBlockType) lbessard@226: setattr(self.Preview, "IsOfType", self.Controler.IsOfType) lbessard@27: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@58: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler): lbessard@226: self.Controler = controler lbessard@27: self._init_ctrls(parent) lbessard@95: self.BlockName.SetValue("") lbessard@95: self.BlockName.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Block = None lbessard@27: self.MinBlockSize = None lbessard@113: self.First = True lbessard@70: lbessard@70: self.PouNames = [] lbessard@70: self.PouElementNames = [] lbessard@27: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: 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@113: if wx.VERSION < (2, 6, 0): lbessard@113: item, root_cookie = self.TypeTree.GetFirstChild(root, 0) lbessard@113: else: lbessard@113: 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@95: block_name = self.BlockName.GetValue() lbessard@95: name_enabled = self.BlockName.IsEnabled() lbessard@27: if not selected.IsOk() or self.TypeTree.GetItemParent(selected) == self.TypeTree.GetRootItem() or selected == self.TypeTree.GetRootItem(): lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. Valid block type must be selected!", "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@70: elif name_enabled and block_name == "": lbessard@64: message = wx.MessageDialog(self, "Form isn't complete. Name must be filled!", "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@70: elif name_enabled and not TestIdentifier(block_name): lbessard@70: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%block_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif name_enabled and block_name.upper() in IEC_KEYWORDS: lbessard@70: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%block_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif name_enabled and block_name.upper() in self.PouNames: lbessard@70: message = wx.MessageDialog(self, "\"%s\" pou already exists!"%block_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@70: elif name_enabled and block_name.upper() in self.PouElementNames: lbessard@70: message = wx.MessageDialog(self, "\"%s\" element for this pou already exists!"%block_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@70: message.ShowModal() lbessard@70: message.Destroy() lbessard@27: else: lbessard@64: self.EndModal(wx.ID_OK) lbessard@27: lbessard@27: def SetBlockList(self, blocktypes): lbessard@95: if wx.Platform == '__WXMSW__': lbessard@95: root = self.TypeTree.AddRoot("Block Types") lbessard@95: else: lbessard@95: 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@95: if wx.Platform == '__WXMSW__': lbessard@95: self.TypeTree.Expand(root) lbessard@27: lbessard@27: def SetMinBlockSize(self, size): lbessard@27: self.MinBlockSize = size lbessard@27: lbessard@70: def SetPouNames(self, pou_names): lbessard@70: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@70: lbessard@70: def SetPouElementNames(self, element_names): lbessard@70: self.PouElementNames = [element_name.upper() for element_name in element_names] lbessard@70: 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@95: self.BlockName.SetValue(value) lbessard@27: elif name == "extension": lbessard@27: self.Inputs.SetValue(value) lbessard@118: elif name == "executionOrder": lbessard@118: self.ExecutionOrder.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@95: if self.BlockName.GetValue() != "": lbessard@95: values["name"] = self.BlockName.GetValue() lbessard@27: values["width"], values["height"] = self.Block.GetSize() lbessard@27: values["extension"] = self.Inputs.GetValue() lbessard@118: values["executionOrder"] = self.ExecutionOrder.GetValue() lbessard@27: return values lbessard@27: lbessard@27: def OnTypeTreeItemSelected(self, event): lbessard@95: self.BlockName.SetValue("") lbessard@27: selected = event.GetItem() lbessard@28: pydata = self.TypeTree.GetPyData(selected) lbessard@28: if pydata["type"] != CATEGORY: lbessard@226: blocktype = self.Controler.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@95: self.BlockName.Enable(blocktype["type"] != "function") lbessard@27: self.TypeDesc.SetValue(blocktype["comment"]) lbessard@64: wx.CallAfter(self.RefreshPreview) lbessard@27: else: lbessard@95: self.BlockName.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Inputs.SetValue(2) lbessard@27: self.TypeDesc.SetValue("") lbessard@64: wx.CallAfter(self.ErasePreview) lbessard@27: else: lbessard@95: self.BlockName.Enable(False) lbessard@27: self.Inputs.Enable(False) lbessard@27: self.Inputs.SetValue(2) lbessard@27: self.TypeDesc.SetValue("") lbessard@64: wx.CallAfter(self.ErasePreview) lbessard@27: event.Skip() lbessard@27: lbessard@27: def OnNameChanged(self, event): lbessard@95: if self.BlockName.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@118: def OnExecutionOrderChanged(self, event): lbessard@118: self.RefreshPreview() lbessard@118: event.Skip() lbessard@118: lbessard@27: def ErasePreview(self): lbessard@64: dc = wx.ClientDC(self.Preview) lbessard@27: dc.Clear() lbessard@27: self.Block = None lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@27: dc.Clear() lbessard@27: item = self.TypeTree.GetSelection() lbessard@80: if item.IsOk(): lbessard@80: pydata = self.TypeTree.GetPyData(item) lbessard@80: if pydata["type"] == CATEGORY: lbessard@80: self.Block = None lbessard@27: else: lbessard@80: blocktype = self.TypeTree.GetItemText(item) lbessard@80: if blocktype: lbessard@118: self.Block = FBD_Block(self.Preview, blocktype, self.BlockName.GetValue(), extension = self.Inputs.GetValue(), inputs = pydata["inputs"], executionOrder = self.ExecutionOrder.GetValue()) lbessard@80: width, height = self.MinBlockSize lbessard@80: min_width, min_height = self.Block.GetMinSize() lbessard@80: width, height = max(min_width, width), max(min_height, height) lbessard@80: self.Block.SetSize(width, height) lbessard@80: clientsize = self.Preview.GetClientSize() lbessard@80: x = (clientsize.width - width) / 2 lbessard@80: y = (clientsize.height - height) / 2 lbessard@80: self.Block.SetPosition(x, y) lbessard@80: self.Block.Draw(dc) lbessard@80: else: lbessard@80: self.Block = None lbessard@27: lbessard@27: def OnPaint(self, event): lbessard@113: if self.Block is not None: lbessard@27: self.RefreshPreview() lbessard@95: event.Skip() lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Variable Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: [ID_VARIABLEPROPERTIESDIALOG, ID_VARIABLEPROPERTIESDIALOGSPACER, lbessard@64: ID_VARIABLEPROPERTIESDIALOGNAME, ID_VARIABLEPROPERTIESDIALOGCLASS, lbessard@64: ID_VARIABLEPROPERTIESDIALOGPREVIEW, ID_VARIABLEPROPERTIESDIALOGEXPRESSION, lbessard@118: ID_VARIABLEPROPERTIESDIALOGEXECUTIONORDER, ID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, lbessard@118: ID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, ID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, lbessard@118: ID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, ID_VARIABLEPROPERTIESDIALOGSTATICTEXT5 lbessard@118: ] = [wx.NewId() for _init_ctrls in range(12)] lbessard@27: lbessard@27: class VariablePropertiesDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@58: lbessard@58: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(0) lbessard@58: lbessard@58: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.TopSizer, 0, border=0, flag=wx.GROW) lbessard@128: parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@58: lbessard@58: def _init_coll_MainSizer_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(2) lbessard@58: lbessard@58: def _init_coll_TopSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@58: lbessard@58: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Class, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Expression, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.ExecutionOrder, 0, border=0, flag=wx.GROW) lbessard@118: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@58: lbessard@58: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(2) lbessard@58: lbessard@58: def _init_coll_RightGridSizer_Items(self, parent): lbessard@128: parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW) lbessard@95: parent.AddWindow(self.VariableName, 0, border=0, flag=wx.GROW) lbessard@58: lbessard@58: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@58: parent.AddGrowableCol(0) lbessard@58: parent.AddGrowableRow(1) lbessard@58: lbessard@27: def _init_sizers(self): lbessard@58: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@58: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) lbessard@64: self.TopSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@118: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=7, vgap=5) lbessard@58: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@58: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@58: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@58: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@58: self._init_coll_TopSizer_Items(self.TopSizer) lbessard@58: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@58: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@58: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@58: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@58: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@64: wx.Dialog.__init__(self, id=ID_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@64: self.staticText1 = wx.StaticText(id=ID_VARIABLEPROPERTIESDIALOGSTATICTEXT1, lbessard@58: label='Class:', name='staticText1', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_VARIABLEPROPERTIESDIALOGSTATICTEXT2, lbessard@58: label='Expression:', name='staticText2', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@28: lbessard@64: self.staticText3 = wx.StaticText(id=ID_VARIABLEPROPERTIESDIALOGSTATICTEXT3, lbessard@118: label='Execution Order:', name='staticText3', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText4 = wx.StaticText(id=ID_VARIABLEPROPERTIESDIALOGSTATICTEXT4, lbessard@118: label='Name:', name='staticText4', parent=self, lbessard@118: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@118: lbessard@118: self.staticText5 = wx.StaticText(id=ID_VARIABLEPROPERTIESDIALOGSTATICTEXT5, lbessard@118: label='Preview:', name='staticText5', parent=self, lbessard@58: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.Class = wx.Choice(id=ID_VARIABLEPROPERTIESDIALOGCLASS, lbessard@58: name='Class', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_CHOICE, self.OnClassChanged, id=ID_VARIABLEPROPERTIESDIALOGCLASS) lbessard@64: lbessard@95: self.VariableName = wx.ListBox(id=ID_VARIABLEPROPERTIESDIALOGNAME, lbessard@58: name='Name', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 90), style=wx.LB_SINGLE) lbessard@64: self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, id=ID_VARIABLEPROPERTIESDIALOGNAME) lbessard@64: lbessard@64: self.Expression = wx.TextCtrl(id=ID_VARIABLEPROPERTIESDIALOGEXPRESSION, lbessard@58: name='Expression', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, id=ID_VARIABLEPROPERTIESDIALOGEXPRESSION) lbessard@64: lbessard@118: self.ExecutionOrder = wx.SpinCtrl(id=ID_VARIABLEPROPERTIESDIALOGEXECUTIONORDER, lbessard@118: name='ExecutionOrder', parent=self, pos=wx.Point(0, 0), lbessard@118: size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0) lbessard@118: self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, id=ID_VARIABLEPROPERTIESDIALOGEXECUTIONORDER) lbessard@118: lbessard@64: self.Spacer = wx.Panel(id=ID_VARIABLEPROPERTIESDIALOGSPACER, lbessard@58: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@58: lbessard@64: self.Preview = wx.Panel(id=ID_VARIABLEPROPERTIESDIALOGPREVIEW, lbessard@58: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@58: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@27: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@113: lbessard@27: self._init_sizers() lbessard@27: lbessard@251: def __init__(self, parent, controler, transition = ""): lbessard@226: self._init_ctrls(parent, controler) lbessard@251: self.Transition = transition 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@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: lbessard@27: def RefreshNameList(self): lbessard@95: selected = self.VariableName.GetStringSelection() lbessard@95: self.VariableName.Clear() lbessard@95: self.VariableName.Append("") lbessard@27: for name, var_type, value_type in self.VarList: lbessard@28: if var_type in ["Local","Temp","Global","External"]: lbessard@95: self.VariableName.Append(name) lbessard@27: elif var_type == "Input" and self.Class.GetStringSelection() == "Input": lbessard@95: self.VariableName.Append(name) lbessard@27: elif var_type == "Output" and self.Class.GetStringSelection() == "Output": lbessard@255: if self.Transition == "" or name == self.Transition: lbessard@251: self.VariableName.Append(name) lbessard@27: elif var_type == "InOut" and self.Class.GetStringSelection() == "InOut": lbessard@255: if self.Transition == "" or name == self.Transition: lbessard@251: self.VariableName.Append(name) lbessard@95: if self.VariableName.FindString(selected) != wx.NOT_FOUND: lbessard@95: self.VariableName.SetStringSelection(selected) lbessard@28: else: lbessard@95: self.VariableName.SetStringSelection("") lbessard@95: self.VariableName.Enable(self.VariableName.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@56: value_type = values.get("type", None) lbessard@56: value_name = values.get("name", None) lbessard@56: if value_type: lbessard@56: if value_type == INPUT: lbessard@56: self.Class.SetStringSelection("Input") lbessard@56: if value_type == OUTPUT: lbessard@56: self.Class.SetStringSelection("Output") lbessard@56: if value_type == INOUT: lbessard@56: self.Class.SetStringSelection("InOut") lbessard@56: self.RefreshNameList() lbessard@56: if value_name: lbessard@95: if self.VariableName.FindString(value_name) != wx.NOT_FOUND: lbessard@95: self.VariableName.SetStringSelection(value_name) lbessard@56: self.Expression.Enable(False) lbessard@56: else: lbessard@56: self.Expression.SetValue(value_name) lbessard@95: self.VariableName.Enable(False) lbessard@118: if "executionOrder" in values: lbessard@118: self.ExecutionOrder.SetValue(values["executionOrder"]) 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@95: values["name"] = self.VariableName.GetStringSelection() etisserant@101: values["value_type"] = None 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@118: values["executionOrder"] = self.ExecutionOrder.GetValue() 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@95: if self.VariableName.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@95: self.VariableName.Enable(False) lbessard@28: else: lbessard@95: self.VariableName.Enable(True) lbessard@28: self.RefreshPreview() lbessard@28: event.Skip() lbessard@28: lbessard@118: def OnExecutionOrderChanged(self, event): lbessard@118: self.RefreshPreview() lbessard@118: event.Skip() lbessard@118: lbessard@27: def RefreshPreview(self): lbessard@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) 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@95: name = self.VariableName.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@118: self.Variable = FBD_Variable(self.Preview, INPUT, name, type, executionOrder = self.ExecutionOrder.GetValue()) lbessard@27: elif classtype == "Output": lbessard@118: self.Variable = FBD_Variable(self.Preview, OUTPUT, name, type, executionOrder = self.ExecutionOrder.GetValue()) lbessard@27: elif classtype == "InOut": lbessard@118: self.Variable = FBD_Variable(self.Preview, INOUT, name, type, executionOrder = self.ExecutionOrder.GetValue()) 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@95: event.Skip() lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Connection Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: [ID_CONNECTIONPROPERTIESDIALOG, ID_CONNECTIONPROPERTIESDIALOGSPACER, lbessard@64: ID_CONNECTIONPROPERTIESDIALOGNAME, ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, lbessard@64: ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, ID_CONNECTIONPROPERTIESDIALOGPREVIEW, lbessard@64: ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, lbessard@64: ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(9)] lbessard@27: lbessard@27: class ConnectionPropertiesDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@62: lbessard@62: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(0) lbessard@62: lbessard@62: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@62: lbessard@62: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@95: parent.AddWindow(self.ConnectionName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@62: lbessard@62: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(5) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@62: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@62: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=5) lbessard@62: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@62: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@62: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@62: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@62: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@62: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@62: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@64: wx.Dialog.__init__(self, id=ID_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@64: self.staticText1 = wx.StaticText(id=ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT1, lbessard@62: label='Type:', name='staticText1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT2, lbessard@62: label='Name:', name='staticText2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText3 = wx.StaticText(id=ID_CONNECTIONPROPERTIESDIALOGSTATICTEXT3, lbessard@62: label='Preview:', name='staticText3', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.radioButton1 = wx.RadioButton(id=ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1, lbessard@62: label='Connector', name='radioButton1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON1) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@64: self.radioButton2 = wx.RadioButton(id=ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2, lbessard@62: label='Continuation', name='radioButton2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_CONNECTIONPROPERTIESDIALOGRADIOBUTTON2) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@95: self.ConnectionName = wx.TextCtrl(id=ID_CONNECTIONPROPERTIESDIALOGNAME, lbessard@62: name='Name', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_CONNECTIONPROPERTIESDIALOGNAME) lbessard@64: lbessard@64: self.Preview = wx.Panel(id=ID_CONNECTIONPROPERTIESDIALOGPREVIEW, lbessard@62: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@27: lbessard@64: self.Spacer = wx.Panel(id=ID_CONNECTIONPROPERTIESDIALOGSPACER, lbessard@62: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@62: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@62: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler): lbessard@226: self._init_ctrls(parent, controler) lbessard@27: self.Connection = None lbessard@27: self.MinConnectionSize = None lbessard@165: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: 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@95: self.ConnectionName.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@95: values["name"] = self.ConnectionName.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@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@27: dc.Clear() lbessard@27: if self.radioButton1.GetValue(): lbessard@95: self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.ConnectionName.GetValue()) lbessard@27: else: lbessard@95: self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.ConnectionName.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@95: event.Skip() lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Edit Ladder Element Properties Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@27: lbessard@64: [ID_LDELEMENTDIALOG, ID_LDELEMENTDIALOGSPACER, lbessard@64: ID_LDELEMENTDIALOGNAME, ID_LDELEMENTDIALOGRADIOBUTTON1, lbessard@64: ID_LDELEMENTDIALOGRADIOBUTTON2, ID_LDELEMENTDIALOGRADIOBUTTON3, lbessard@64: ID_LDELEMENTDIALOGRADIOBUTTON4, ID_LDELEMENTDIALOGPREVIEW, lbessard@64: ID_LDELEMENTDIALOGSTATICTEXT1, ID_LDELEMENTDIALOGSTATICTEXT2, lbessard@64: ID_LDELEMENTDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@27: lbessard@27: class LDElementDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@62: lbessard@62: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(0) lbessard@62: lbessard@62: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@62: lbessard@62: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton4, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@95: parent.AddWindow(self.ElementName, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@62: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(7) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@62: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@62: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5) lbessard@62: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@62: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@62: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@62: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@62: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@62: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@62: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@226: def _init_ctrls(self, prnt, ctrler, title, labels): lbessard@64: wx.Dialog.__init__(self, id=ID_LDELEMENTDIALOG, lbessard@71: name='LDElementDialog', 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@64: self.staticText1 = wx.StaticText(id=ID_LDELEMENTDIALOGSTATICTEXT1, lbessard@62: label='Modifier:', name='staticText1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_LDELEMENTDIALOGSTATICTEXT2, lbessard@62: label='Name:', name='staticText2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText3 = wx.StaticText(id=ID_LDELEMENTDIALOGSTATICTEXT3, lbessard@62: label='Preview:', name='staticText3', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.radioButton1 = wx.RadioButton(id=ID_LDELEMENTDIALOGRADIOBUTTON1, lbessard@62: label=labels[0], name='radioButton1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDELEMENTDIALOGRADIOBUTTON1) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@64: self.radioButton2 = wx.RadioButton(id=ID_LDELEMENTDIALOGRADIOBUTTON2, lbessard@62: label=labels[1], name='radioButton2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDELEMENTDIALOGRADIOBUTTON2) lbessard@64: lbessard@64: self.radioButton3 = wx.RadioButton(id=ID_LDELEMENTDIALOGRADIOBUTTON3, lbessard@62: label=labels[2], name='radioButton3', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDELEMENTDIALOGRADIOBUTTON3) lbessard@64: lbessard@64: self.radioButton4 = wx.RadioButton(id=ID_LDELEMENTDIALOGRADIOBUTTON4, lbessard@62: label=labels[3], name='radioButton4', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDELEMENTDIALOGRADIOBUTTON4) lbessard@64: lbessard@95: self.ElementName = wx.Choice(id=ID_LDELEMENTDIALOGNAME, lbessard@62: name='Name', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_CHOICE, self.OnNameChanged, id=ID_LDELEMENTDIALOGNAME) lbessard@64: lbessard@64: self.Preview = wx.Panel(id=ID_LDELEMENTDIALOGPREVIEW, lbessard@62: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@27: lbessard@64: self.Spacer = wx.Panel(id=ID_LDELEMENTDIALOGSPACER, lbessard@62: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@62: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@64: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler, type): lbessard@27: self.Type = type lbessard@27: if type == "contact": lbessard@226: self._init_ctrls(parent, controler, "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@226: self._init_ctrls(parent, controler, "Edit Coil Values", ['Normal','Negate','Set','Reset']) lbessard@27: self.Element = LD_Coil(self.Preview, COIL_NORMAL, "") lbessard@165: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: 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@64: lbessard@27: def SetVariables(self, vars): lbessard@95: self.ElementName.Clear() lbessard@27: for name in vars: lbessard@95: self.ElementName.Append(name) lbessard@95: self.ElementName.Enable(self.ElementName.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@95: self.ElementName.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@95: self.Element.SetName(self.ElementName.GetStringSelection()) lbessard@27: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@27: def RefreshPreview(self): lbessard@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@27: dc.Clear() lbessard@62: clientsize = self.Preview.GetClientSize() lbessard@62: width, height = self.Element.GetSize() lbessard@62: self.Element.SetPosition((clientsize.width - width) / 2, (clientsize.height - height) / 2) 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@64: [ID_LDPOWERRAILDIALOG, ID_LDPOWERRAILDIALOGSPACER, lbessard@64: ID_LDPOWERRAILDIALOGTYPE, ID_LDPOWERRAILDIALOGRADIOBUTTON1, lbessard@64: ID_LDPOWERRAILDIALOGRADIOBUTTON2, ID_LDPOWERRAILDIALOGPREVIEW, lbessard@64: ID_LDPOWERRAILDIALOGSTATICTEXT1, ID_LDPOWERRAILDIALOGSTATICTEXT2, lbessard@64: ID_LDPOWERRAILDIALOGSTATICTEXT3, ID_LDPOWERRAILDIALOGPINNUMBER, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@27: lbessard@27: class LDPowerRailDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@62: lbessard@62: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(0) lbessard@62: lbessard@62: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@62: lbessard@62: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.PinNumber, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@62: lbessard@62: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(5) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@62: lbessard@62: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@62: parent.AddGrowableCol(0) lbessard@62: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@62: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@62: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=5) lbessard@62: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@62: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@62: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@62: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@62: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@62: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@62: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@64: wx.Dialog.__init__(self, id=ID_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@64: self.staticText1 = wx.StaticText(id=ID_LDPOWERRAILDIALOGSTATICTEXT1, lbessard@62: label='Type:', name='staticText1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_LDPOWERRAILDIALOGSTATICTEXT2, lbessard@62: label='Pin number:', name='staticText2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.staticText3 = wx.StaticText(id=ID_LDPOWERRAILDIALOGSTATICTEXT3, lbessard@62: label='Preview:', name='staticText3', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@27: lbessard@64: self.radioButton1 = wx.RadioButton(id=ID_LDPOWERRAILDIALOGRADIOBUTTON1, lbessard@62: label='Left PowerRail', name='radioButton1', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDPOWERRAILDIALOGRADIOBUTTON1) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@64: self.radioButton2 = wx.RadioButton(id=ID_LDPOWERRAILDIALOGRADIOBUTTON2, lbessard@62: label='Right PowerRail', name='radioButton2', parent=self, lbessard@62: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_LDPOWERRAILDIALOGRADIOBUTTON2) lbessard@64: lbessard@64: self.PinNumber = wx.SpinCtrl(id=ID_LDPOWERRAILDIALOGPINNUMBER, lbessard@62: name='PinNumber', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=1, max=20) lbessard@64: self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, id=ID_LDPOWERRAILDIALOGPINNUMBER) lbessard@64: lbessard@64: self.Preview = wx.Panel(id=ID_LDPOWERRAILDIALOGPREVIEW, lbessard@62: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@27: lbessard@64: self.Spacer = wx.Panel(id=ID_LDELEMENTDIALOGSPACER, lbessard@62: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@62: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@62: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@64: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler, type = LEFTRAIL, number = 1): lbessard@226: self._init_ctrls(parent, controler) 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.PowerRailMinSize = (0, 0) lbessard@27: self.PowerRail = None lbessard@27: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: 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@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@27: dc.Clear() lbessard@27: self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = [True for i in xrange(self.PinNumber.GetValue())]) lbessard@96: min_width, min_height = 2, LD_LINE_SIZE * self.PinNumber.GetValue() lbessard@27: width, height = max(min_width, self.PowerRailMinSize[0]), max(min_height, self.PowerRailMinSize[1]) lbessard@27: self.PowerRail.SetSize(width, height) lbessard@62: clientsize = self.Preview.GetClientSize() lbessard@62: self.PowerRail.SetPosition((clientsize.width - width) / 2, (clientsize.height - 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@71: # Edit Step Content Dialog lbessard@71: #------------------------------------------------------------------------------- lbessard@71: lbessard@71: [ID_STEPCONTENTDIALOG, ID_STEPCONTENTDIALOGSPACER, lbessard@71: ID_STEPCONTENTDIALOGNAME, ID_STEPCONTENTDIALOGPREVIEW, lbessard@71: ID_STEPCONTENTDIALOGCHECKBOX1, ID_STEPCONTENTDIALOGCHECKBOX2, lbessard@71: ID_STEPCONTENTDIALOGCHECKBOX3, ID_STEPCONTENTDIALOGSTATICTEXT1, lbessard@71: ID_STEPCONTENTDIALOGSTATICTEXT2, ID_STEPCONTENTDIALOGSTATICTEXT3, lbessard@71: ] = [wx.NewId() for _init_ctrls in range(10)] lbessard@71: lbessard@71: class StepContentDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@71: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@71: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@71: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@71: lbessard@71: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@71: parent.AddGrowableCol(0) lbessard@71: parent.AddGrowableRow(0) lbessard@71: lbessard@71: def _init_coll_MainSizer_Items(self, parent): lbessard@71: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@71: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@71: lbessard@71: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@71: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@95: parent.AddWindow(self.StepName, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.checkBox1, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.checkBox2, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.checkBox3, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@71: lbessard@71: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@71: parent.AddGrowableCol(0) lbessard@71: parent.AddGrowableRow(6) lbessard@71: lbessard@71: def _init_coll_RightGridSizer_Items(self, parent): lbessard@71: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@71: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@71: lbessard@71: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@71: parent.AddGrowableCol(0) lbessard@71: parent.AddGrowableRow(1) lbessard@71: lbessard@71: def _init_sizers(self): lbessard@71: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@71: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@71: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=7, vgap=5) lbessard@71: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@71: lbessard@71: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@71: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@71: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@71: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@71: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@71: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@71: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@71: lbessard@71: self.SetSizer(self.flexGridSizer1) lbessard@71: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@71: wx.Dialog.__init__(self, id=ID_STEPCONTENTDIALOG, lbessard@71: name='StepContentDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@71: size=wx.Size(400, 250), style=wx.DEFAULT_DIALOG_STYLE, lbessard@71: title='Edit Step') lbessard@71: self.SetClientSize(wx.Size(400, 250)) lbessard@71: lbessard@71: self.staticText1 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT1, lbessard@71: label='Name:', name='staticText1', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@71: lbessard@71: self.staticText2 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT2, lbessard@71: label='Connectors:', name='staticText2', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@71: lbessard@71: self.staticText3 = wx.StaticText(id=ID_STEPCONTENTDIALOGSTATICTEXT3, lbessard@71: label='Preview:', name='staticText4', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@71: lbessard@95: self.StepName = wx.TextCtrl(id=ID_STEPCONTENTDIALOGNAME, lbessard@71: name='Name', parent=self, pos=wx.Point(0, 0), lbessard@71: size=wx.Size(0, 24), style=0) lbessard@71: self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_STEPCONTENTDIALOGNAME) lbessard@71: lbessard@71: self.checkBox1 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX1, lbessard@71: label="Input", name='checkBox1', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@71: self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX1) lbessard@71: lbessard@71: self.checkBox2 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX2, lbessard@71: label="Output", name='checkBox2', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@71: self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX2) lbessard@71: lbessard@71: self.checkBox3 = wx.CheckBox(id=ID_STEPCONTENTDIALOGCHECKBOX3, lbessard@71: label="Action", name='checkBox3', parent=self, lbessard@71: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@71: self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, id=ID_STEPCONTENTDIALOGCHECKBOX3) lbessard@71: lbessard@71: self.Spacer = wx.Panel(id=ID_STEPCONTENTDIALOGSPACER, lbessard@71: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@71: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@71: lbessard@71: self.Preview = wx.Panel(id=ID_STEPCONTENTDIALOGPREVIEW, lbessard@71: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@71: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@71: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@71: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@71: setattr(self.Preview, "RefreshStepModel", lambda x:None) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@71: lbessard@71: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@113: lbessard@71: self._init_sizers() lbessard@71: lbessard@226: def __init__(self, parent, controler, initial = False): lbessard@226: self._init_ctrls(parent, controler) lbessard@71: self.Step = None lbessard@71: self.Initial = initial lbessard@71: self.MinStepSize = None lbessard@71: lbessard@71: self.PouNames = [] lbessard@71: self.Variables = [] lbessard@71: self.StepNames = [] lbessard@71: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: lbessard@71: def OnOK(self, event): lbessard@95: step_name = self.StepName.GetValue() lbessard@71: if step_name == "": lbessard@71: message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: elif not TestIdentifier(step_name): lbessard@71: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: elif step_name.upper() in IEC_KEYWORDS: lbessard@71: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: elif step_name.upper() in self.PouNames: lbessard@71: message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: elif step_name.upper() in self.Variables: lbessard@71: message = wx.MessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: elif step_name.upper() in self.StepNames: lbessard@71: message = wx.MessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@71: message.ShowModal() lbessard@71: message.Destroy() lbessard@71: else: lbessard@71: self.EndModal(wx.ID_OK) lbessard@71: lbessard@71: def SetMinStepSize(self, size): lbessard@71: self.MinStepSize = size lbessard@71: lbessard@71: def SetPouNames(self, pou_names): lbessard@71: self.PouNames = [pou_name.upper() for pou_name in pou_names] lbessard@71: lbessard@71: def SetVariables(self, variables): lbessard@71: self.Variables = [var["Name"].upper() for var in variables] lbessard@71: lbessard@71: def SetStepNames(self, step_names): lbessard@71: self.StepNames = [step_name.upper() for step_name in step_names] lbessard@71: lbessard@71: def SetValues(self, values): lbessard@71: value_name = values.get("name", None) lbessard@71: if value_name: lbessard@95: self.StepName.SetValue(value_name) lbessard@71: else: lbessard@95: self.StepName.SetValue("") lbessard@71: self.checkBox1.SetValue(values.get("input", False)) lbessard@71: self.checkBox2.SetValue(values.get("output", False)) lbessard@71: self.checkBox3.SetValue(values.get("action", False)) lbessard@71: self.RefreshPreview() lbessard@71: lbessard@71: def GetValues(self): lbessard@71: values = {} lbessard@95: values["name"] = self.StepName.GetValue() lbessard@71: values["input"] = self.checkBox1.IsChecked() lbessard@71: values["output"] = self.checkBox2.IsChecked() lbessard@71: values["action"] = self.checkBox3.IsChecked() lbessard@71: values["width"], values["height"] = self.Step.GetSize() lbessard@71: return values lbessard@71: lbessard@71: def OnConnectorsChanged(self, event): lbessard@71: self.RefreshPreview() lbessard@71: event.Skip() lbessard@71: lbessard@71: def OnNameChanged(self, event): lbessard@71: self.RefreshPreview() lbessard@71: event.Skip() lbessard@71: lbessard@71: def RefreshPreview(self): lbessard@71: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@71: dc.Clear() lbessard@95: self.Step = SFC_Step(self.Preview, self.StepName.GetValue(), self.Initial) lbessard@71: if self.checkBox1.IsChecked(): lbessard@71: self.Step.AddInput() lbessard@71: else: lbessard@71: self.Step.RemoveInput() lbessard@71: if self.checkBox2.IsChecked(): lbessard@71: self.Step.AddOutput() lbessard@71: else: lbessard@71: self.Step.RemoveOutput() lbessard@71: if self.checkBox3.IsChecked(): lbessard@71: self.Step.AddAction() lbessard@71: else: lbessard@71: self.Step.RemoveAction() lbessard@71: width, height = self.MinStepSize lbessard@71: min_width, min_height = self.Step.GetMinSize() lbessard@71: width, height = max(min_width, width), max(min_height, height) lbessard@71: self.Step.SetSize(width, height) lbessard@71: clientsize = self.Preview.GetClientSize() lbessard@71: x = (clientsize.width - width) / 2 lbessard@71: y = (clientsize.height - height) / 2 lbessard@71: self.Step.SetPosition(x, y) lbessard@71: self.Step.Draw(dc) lbessard@71: lbessard@71: def OnPaint(self, event): lbessard@71: self.RefreshPreview() lbessard@95: event.Skip() lbessard@71: lbessard@71: #------------------------------------------------------------------------------- lbessard@27: # Edit Transition Content Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: [ID_TRANSITIONCONTENTDIALOG, ID_TRANSITIONCONTENTDIALOGSPACER, lbessard@64: ID_TRANSITIONCONTENTDIALOGREFERENCE, ID_TRANSITIONCONTENTDIALOGINLINE, lbessard@80: ID_TRANSITIONCONTENTDIALOGPRIORITY, ID_TRANSITIONCONTENTDIALOGPREVIEW, lbessard@80: ID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, ID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, lbessard@80: ID_TRANSITIONCONTENTDIALOGRADIOBUTTON3, ID_TRANSITIONCONTENTDIALOGSTATICTEXT1, lbessard@80: ID_TRANSITIONCONTENTDIALOGSTATICTEXT2, ID_TRANSITIONCONTENTDIALOGSTATICTEXT3, lbessard@80: ] = [wx.NewId() for _init_ctrls in range(12)] lbessard@27: lbessard@27: class TransitionContentDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@64: lbessard@64: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Reference, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Inline, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW) lbessard@80: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@80: parent.AddWindow(self.Priority, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(6) lbessard@64: lbessard@64: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@80: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=9, vgap=5) lbessard@64: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@64: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@64: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@64: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@27: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@64: wx.Dialog.__init__(self, id=ID_TRANSITIONCONTENTDIALOG, lbessard@27: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@80: size=wx.Size(350, 300), style=wx.DEFAULT_DIALOG_STYLE, lbessard@27: title='Edit transition') lbessard@80: self.SetClientSize(wx.Size(350, 300)) lbessard@64: lbessard@64: self.staticText1 = wx.StaticText(id=ID_TRANSITIONCONTENTDIALOGSTATICTEXT1, lbessard@64: label='Type:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@64: self.staticText2 = wx.StaticText(id=ID_TRANSITIONCONTENTDIALOGSTATICTEXT2, lbessard@64: label='Preview:', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@80: self.staticText3 = wx.StaticText(id=ID_TRANSITIONCONTENTDIALOGSTATICTEXT3, lbessard@80: label='Priority:', name='staticText3', parent=self, lbessard@80: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@80: lbessard@64: self.radioButton1 = wx.RadioButton(id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, lbessard@64: label='Reference', name='radioButton1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON1) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@64: self.Reference = wx.Choice(id=ID_TRANSITIONCONTENTDIALOGREFERENCE, lbessard@64: name='Reference', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_CHOICE, self.OnReferenceChanged, id=ID_TRANSITIONCONTENTDIALOGREFERENCE) lbessard@64: lbessard@64: self.radioButton2 = wx.RadioButton(id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, lbessard@64: label='Inline', name='radioButton2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON2) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@64: self.Inline = wx.TextCtrl(id=ID_TRANSITIONCONTENTDIALOGINLINE, lbessard@64: name='Inline', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_TEXT, self.OnInlineChanged, id=ID_TRANSITIONCONTENTDIALOGINLINE) lbessard@108: self.Inline.Enable(False) lbessard@108: lbessard@64: self.radioButton3 = wx.RadioButton(id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON3, lbessard@64: label='Connection', name='radioButton3', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON3) lbessard@64: self.radioButton3.SetValue(False) lbessard@64: if not self.Connection: lbessard@64: self.radioButton3.Hide() lbessard@64: lbessard@80: self.Priority = wx.SpinCtrl(id=ID_TRANSITIONCONTENTDIALOGPRIORITY, lbessard@80: name='Priority', parent=self, pos=wx.Point(0, 0), lbessard@80: size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0) lbessard@80: self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, id=ID_TRANSITIONCONTENTDIALOGPRIORITY) lbessard@80: lbessard@64: self.Preview = wx.Panel(id=ID_TRANSITIONCONTENTDIALOGPREVIEW, lbessard@64: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@64: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@64: setattr(self.Preview, "RefreshTransitionModel", lambda x:None) lbessard@145: setattr(self.Preview, "GetScaling", lambda:None) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@64: lbessard@64: self.Spacer = wx.Panel(id=ID_TRANSITIONCONTENTDIALOGSPACER, lbessard@64: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@64: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler, connection): lbessard@64: self.Connection = connection lbessard@226: self._init_ctrls(parent, controler) lbessard@64: self.Transition = None lbessard@64: self.MinTransitionSize = None lbessard@64: lbessard@64: self.Element = SFC_Transition(self.Preview) lbessard@165: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: lbessard@64: def SetElementSize(self, size): lbessard@64: min_width, min_height = self.Element.GetMinSize() lbessard@64: width, height = max(min_width, size[0]), max(min_height, size[1]) lbessard@64: self.Element.SetSize(width, height) 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@64: message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: else: lbessard@64: self.EndModal(wx.ID_OK) lbessard@27: lbessard@27: def OnTypeChanged(self, event): lbessard@27: if self.radioButton1.GetValue(): lbessard@64: self.Element.SetType("reference", self.Reference.GetStringSelection()) lbessard@27: self.Reference.Enable(True) lbessard@27: self.Inline.Enable(False) lbessard@64: elif self.radioButton2.GetValue(): lbessard@64: self.Element.SetType("inline", self.Inline.GetValue()) lbessard@27: self.Reference.Enable(False) lbessard@27: self.Inline.Enable(True) lbessard@64: else: lbessard@64: self.Element.SetType("connection") lbessard@64: self.Reference.Enable(False) lbessard@64: self.Inline.Enable(False) lbessard@64: self.RefreshPreview() lbessard@64: event.Skip() lbessard@64: lbessard@64: def OnReferenceChanged(self, event): lbessard@64: self.Element.SetType("reference", self.Reference.GetStringSelection()) lbessard@64: self.RefreshPreview() lbessard@64: event.Skip() lbessard@64: lbessard@64: def OnInlineChanged(self, event): lbessard@64: self.Element.SetType("inline", self.Inline.GetValue()) lbessard@64: self.RefreshPreview() lbessard@27: event.Skip() lbessard@27: lbessard@80: def OnPriorityChanged(self, event): lbessard@80: self.Element.SetPriority(int(self.Priority.GetValue())) lbessard@80: self.RefreshPreview() lbessard@80: event.Skip() lbessard@80: lbessard@27: def SetTransitions(self, transitions): lbessard@64: self.Reference.Append("") 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@64: self.radioButton3.SetValue(False) lbessard@27: self.Reference.Enable(True) lbessard@27: self.Inline.Enable(False) lbessard@27: self.Reference.SetStringSelection(values["value"]) lbessard@64: self.Element.SetType("reference", values["value"]) lbessard@27: elif values["type"] == "inline": lbessard@27: self.radioButton1.SetValue(False) lbessard@27: self.radioButton2.SetValue(True) lbessard@64: self.radioButton3.SetValue(False) lbessard@27: self.Reference.Enable(False) lbessard@27: self.Inline.Enable(True) lbessard@27: self.Inline.SetValue(values["value"]) lbessard@64: self.Element.SetType("inline", values["value"]) lbessard@64: elif values["type"] == "connection" and self.Connection: lbessard@64: self.radioButton1.SetValue(False) lbessard@64: self.radioButton2.SetValue(False) lbessard@64: self.radioButton3.SetValue(True) lbessard@64: self.Reference.Enable(False) lbessard@64: self.Inline.Enable(False) lbessard@64: self.Element.SetType("connection") lbessard@108: self.Priority.SetValue(values["priority"]) lbessard@80: self.Element.SetPriority(values["priority"]) lbessard@64: self.RefreshPreview() lbessard@64: lbessard@27: def GetValues(self): lbessard@80: values = {"priority" : int(self.Priority.GetValue())} lbessard@27: if self.radioButton1.GetValue(): lbessard@27: values["type"] = "reference" lbessard@27: values["value"] = self.Reference.GetStringSelection() lbessard@64: elif self.radioButton2.GetValue(): lbessard@27: values["type"] = "inline" lbessard@27: values["value"] = self.Inline.GetValue() lbessard@64: else: lbessard@64: values["type"] = "connection" lbessard@64: values["value"] = None lbessard@27: return values lbessard@27: lbessard@64: def RefreshPreview(self): lbessard@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) lbessard@64: dc.Clear() lbessard@64: clientsize = self.Preview.GetClientSize() lbessard@64: posx, posy = self.Element.GetPosition() lbessard@64: rect = self.Element.GetBoundingBox() lbessard@64: diffx, diffy = posx - rect.x, posy - rect.y lbessard@64: self.Element.SetPosition((clientsize.width - rect.width) / 2 + diffx, (clientsize.height - rect.height) / 2 + diffy) lbessard@64: self.Element.Draw(dc) lbessard@64: lbessard@64: def OnPaint(self, event): lbessard@64: self.RefreshPreview() lbessard@95: event.Skip() lbessard@64: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Create New Divergence Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: [ID_DIVERGENCECREATEDIALOG, ID_DIVERGENCECREATEDIALOGSPACER, lbessard@64: ID_DIVERGENCECREATEDIALOGRADIOBUTTON1, ID_DIVERGENCECREATEDIALOGRADIOBUTTON2, lbessard@64: ID_DIVERGENCECREATEDIALOGRADIOBUTTON3, ID_DIVERGENCECREATEDIALOGRADIOBUTTON4, lbessard@64: ID_DIVERGENCECREATEDIALOGSEQUENCES, ID_DIVERGENCECREATEDIALOGPREVIEW, lbessard@64: ID_DIVERGENCECREATEDIALOGSTATICTEXT1, ID_DIVERGENCECREATEDIALOGSTATICTEXT2, lbessard@64: ID_DIVERGENCECREATEDIALOGSTATICTEXT3, lbessard@27: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@27: lbessard@27: class DivergenceCreateDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_MainSizer_Items(self, parent): lbessard@64: parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT) lbessard@64: parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT) lbessard@64: lbessard@64: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.radioButton4, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Sequences, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(7) lbessard@64: lbessard@64: def _init_coll_RightGridSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(1) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@64: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@64: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5) lbessard@64: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@27: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@64: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@64: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@64: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@64: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@27: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@64: lbessard@226: def _init_ctrls(self, prnt, ctrler): lbessard@64: wx.Dialog.__init__(self, id=ID_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@64: self.SetClientSize(wx.Size(500, 300)) lbessard@64: lbessard@64: self.staticText1 = wx.StaticText(id=ID_DIVERGENCECREATEDIALOGSTATICTEXT1, lbessard@64: label='Type:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@64: self.radioButton1 = wx.RadioButton(id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON1, lbessard@64: label='Selection Divergence', name='radioButton1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON1) lbessard@27: self.radioButton1.SetValue(True) lbessard@27: lbessard@64: self.radioButton2 = wx.RadioButton(id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON2, lbessard@64: label='Selection Convergence', name='radioButton2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON2) lbessard@27: self.radioButton2.SetValue(False) lbessard@27: lbessard@64: self.radioButton3 = wx.RadioButton(id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON3, lbessard@64: label='Simultaneous Divergence', name='radioButton3', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON3) lbessard@27: self.radioButton3.SetValue(False) lbessard@27: lbessard@64: self.radioButton4 = wx.RadioButton(id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON4, lbessard@64: label='Simultaneous Convergence', name='radioButton4', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@64: self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_DIVERGENCECREATEDIALOGRADIOBUTTON4) lbessard@27: self.radioButton4.SetValue(False) lbessard@27: lbessard@64: self.staticText2 = wx.StaticText(id=ID_DIVERGENCECREATEDIALOGSTATICTEXT2, lbessard@64: label='Number of sequences:', name='staticText2', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@64: self.Sequences = wx.SpinCtrl(id=ID_DIVERGENCECREATEDIALOGSEQUENCES, lbessard@64: name='Sequences', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 24), style=0, min=2, max=20) lbessard@64: self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, id=ID_DIVERGENCECREATEDIALOGSEQUENCES) lbessard@64: lbessard@64: self.staticText3 = wx.StaticText(id=ID_DIVERGENCECREATEDIALOGSTATICTEXT3, lbessard@64: label='Preview:', name='staticText3', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@64: self.Preview = wx.Panel(id=ID_DIVERGENCECREATEDIALOGPREVIEW, lbessard@64: name='Preview', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) lbessard@64: self.Preview.SetBackgroundColour(wx.Colour(255,255,255)) lbessard@42: setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE) lbessard@226: setattr(self.Preview, "IsOfType", ctrler.IsOfType) lbessard@27: lbessard@64: self.Spacer = wx.Panel(id=ID_TRANSITIONCONTENTDIALOGSPACER, lbessard@64: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@64: lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Preview.Bind(wx.EVT_PAINT, self.OnPaint) lbessard@113: else: lbessard@113: wx.EVT_PAINT(self.Preview, self.OnPaint) lbessard@64: lbessard@27: self._init_sizers() lbessard@27: lbessard@226: def __init__(self, parent, controler): lbessard@226: self._init_ctrls(parent, controler) lbessard@27: lbessard@27: self.Divergence = None lbessard@27: self.MinSize = (0, 0) lbessard@165: lbessard@165: def SetPreviewFont(self, font): lbessard@165: self.Preview.SetFont(font) lbessard@165: 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@64: dc = wx.ClientDC(self.Preview) lbessard@165: dc.SetFont(self.Preview.GetFont()) 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@95: event.Skip() lbessard@27: lbessard@27: lbessard@27: #------------------------------------------------------------------------------- lbessard@27: # Action Block Dialog lbessard@27: #------------------------------------------------------------------------------- lbessard@27: lbessard@64: class ActionTable(wx.grid.PyGridTableBase): lbessard@27: lbessard@27: """ lbessard@64: A custom wx.Grid 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@64: wx.grid.PyGridTableBase.__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@64: (wx.Grid) -> 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@64: (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@64: (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), lbessard@27: ]: lbessard@27: if new < current: lbessard@64: msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: elif new > current: lbessard@64: msg = wx.grid.GridTableMessage(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@64: msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) lbessard@27: grid.ProcessTableMessage(msg) lbessard@27: lbessard@27: def _updateColAttrs(self, grid): lbessard@27: """ lbessard@64: wx.Grid -> 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@64: attr = wx.grid.GridCellAttr() lbessard@64: attr.SetAlignment(self.Parent.ColAlignements[col], wx.ALIGN_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@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.QualifierList) lbessard@27: if colname == "Duration": lbessard@64: editor = wx.grid.GridCellTextEditor() lbessard@64: renderer = wx.grid.GridCellStringRenderer() 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@64: editor = wx.grid.GridCellChoiceEditor() 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@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.ActionList) lbessard@27: elif type == "Variable": lbessard@64: editor = wx.grid.GridCellChoiceEditor() lbessard@27: editor.SetParameters(self.Parent.VariableList) lbessard@27: elif type == "Inline": lbessard@64: editor = wx.grid.GridCellTextEditor() lbessard@64: renderer = wx.grid.GridCellStringRenderer() lbessard@27: elif colname == "Indicator": lbessard@64: editor = wx.grid.GridCellChoiceEditor() 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@64: grid.SetCellBackgroundColour(row, col, wx.WHITE) 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@64: [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, lbessard@64: ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON, lbessard@64: ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, lbessard@64: ID_ACTIONBLOCKDIALOGDOWNBUTTON, lbessard@64: ] = [wx.NewId() for _init_ctrls in range(7)] lbessard@27: lbessard@27: class ActionBlockDialog(wx.Dialog): lbessard@113: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@27: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@64: parent.AddSizer(self.TopSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.GridButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT) lbessard@64: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@64: lbessard@64: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(0) lbessard@64: lbessard@64: def _init_coll_TopSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@64: parent.AddWindow(self.ActionsGrid, 0, border=0, flag=wx.GROW) lbessard@64: lbessard@64: def _init_coll_TopSizer_Growables(self, parent): lbessard@64: parent.AddGrowableCol(0) lbessard@64: parent.AddGrowableRow(1) lbessard@64: lbessard@64: def _init_coll_GridButtonSizer_Items(self, parent): lbessard@64: parent.AddWindow(self.AddButton, 0, border=10, flag=wx.GROW|wx.LEFT) lbessard@64: parent.AddWindow(self.DeleteButton, 0, border=10, flag=wx.GROW|wx.LEFT) lbessard@64: parent.AddWindow(self.UpButton, 0, border=10, flag=wx.GROW|wx.LEFT) lbessard@64: parent.AddWindow(self.DownButton, 0, border=10, flag=wx.GROW|wx.LEFT) lbessard@27: lbessard@27: def _init_sizers(self): lbessard@64: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) lbessard@64: self.TopSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@64: self.GridButtonSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@64: lbessard@27: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@64: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@64: self._init_coll_TopSizer_Items(self.TopSizer) lbessard@64: self._init_coll_TopSizer_Growables(self.TopSizer) lbessard@64: self._init_coll_GridButtonSizer_Items(self.GridButtonSizer) lbessard@64: lbessard@27: self.SetSizer(self.flexGridSizer1) lbessard@64: lbessard@27: def _init_ctrls(self, prnt): lbessard@64: wx.Dialog.__init__(self, id=ID_ACTIONBLOCKDIALOG, lbessard@27: name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@64: size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, lbessard@27: title='Edit action block properties') lbessard@27: self.SetClientSize(wx.Size(500, 300)) lbessard@27: lbessard@64: self.staticText1 = wx.StaticText(id=ID_ACTIONBLOCKDIALOGSTATICTEXT1, lbessard@64: label='Actions:', name='staticText1', parent=self, lbessard@64: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@64: lbessard@64: self.ActionsGrid = wx.grid.Grid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID, lbessard@64: name='ActionsGrid', parent=self, pos=wx.Point(0, 0), lbessard@64: size=wx.Size(0, 0), style=wx.VSCROLL) 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@64: self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange) lbessard@64: lbessard@64: self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label='Add', lbessard@64: name='AddButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(72, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_ACTIONBLOCKDIALOGADDBUTTON) lbessard@64: lbessard@64: self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete', lbessard@64: name='DeleteButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(72, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_ACTIONBLOCKDIALOGDELETEBUTTON) lbessard@64: lbessard@64: self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^', lbessard@64: name='UpButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_ACTIONBLOCKDIALOGUPBUTTON) lbessard@64: lbessard@64: self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', lbessard@64: name='DownButton', parent=self, pos=wx.Point(0, 0), lbessard@27: size=wx.Size(32, 32), style=0) lbessard@64: self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_ACTIONBLOCKDIALOGDOWNBUTTON) lbessard@64: lbessard@64: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@113: if wx.VERSION >= (2, 5, 0): lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@113: else: lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) lbessard@113: lbessard@27: self._init_sizers() lbessard@27: lbessard@27: def __init__(self, parent): lbessard@27: self._init_ctrls(parent) 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@64: self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_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@108: def OnOK(self, event): lbessard@108: self.ActionsGrid.SetGridCursor(0, 0) lbessard@108: self.EndModal(wx.ID_OK) lbessard@108: 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@154: self.QualifierList = "," + ",".join(list) lbessard@27: self.DurationList = list lbessard@27: lbessard@27: def SetVariableList(self, list): lbessard@154: self.VariableList = "," + ",".join([variable["Name"] for variable in list]) lbessard@154: lbessard@27: def SetActionList(self, list): lbessard@154: self.ActionList = "," + ",".join(list) 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@64: class StepNameDialog(wx.TextEntryDialog): lbessard@27: lbessard@113: if wx.VERSION < (2, 6, 0): lbessard@113: def Bind(self, event, function, id = None): lbessard@113: if id is not None: lbessard@113: event(self, id, function) lbessard@113: else: lbessard@113: event(self, function) lbessard@113: lbessard@113: lbessard@27: def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", lbessard@64: style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): 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@123: if wx.VERSION >= (2, 8, 0): lbessard@123: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) lbessard@123: elif wx.VERSION >= (2, 6, 0): lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) lbessard@113: else: lbessard@113: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) lbessard@113: lbessard@27: def OnOK(self, event): lbessard@27: step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() lbessard@27: if step_name == "": lbessard@64: message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif not TestIdentifier(step_name): lbessard@64: message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in IEC_KEYWORDS: lbessard@64: message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.PouNames: lbessard@64: message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.Variables: lbessard@64: message = wx.MessageDialog(self, "A variable with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: elif step_name.upper() in self.StepNames: lbessard@64: message = wx.MessageDialog(self, "\"%s\" step already exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) lbessard@27: message.ShowModal() lbessard@27: message.Destroy() lbessard@27: else: lbessard@64: self.EndModal(wx.ID_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()