--- a/dialogs/BlockPreviewDialog.py Tue Jun 11 19:33:03 2013 +0200
+++ b/dialogs/BlockPreviewDialog.py Tue Jun 11 23:08:06 2013 +0200
@@ -81,6 +81,9 @@
# Variable containing the graphic element name when dialog is opened
self.DefaultElementName = None
+ # List of variables defined in POU {var_name: (var_class, var_type),...} @@ -102,6 +105,30 @@
self.Preview.SetFont(font)
+ def RefreshVariableList(self): + Extract list of variables defined in POU + # Get list of variables defined in POU + var["Name"]: (var["Class"], var["Type"]) + for var in self.Controller.GetEditedElementInterfaceVars( + # Add POU name to variable list if POU is a function + returntype = self.Controller.GetEditedElementInterfaceReturnType( + if returntype is not None: + self.Controller.GetEditedElementName(self.TagName)] = \ + # Add POU name if POU is a transition + words = self.TagName.split("::") + self.VariableList[words[2]] = ("Output", "BOOL") def TestElementName(self, element_name):
Test displayed graphic element name
--- a/dialogs/ConnectionDialog.py Tue Jun 11 19:33:03 2013 +0200
+++ b/dialogs/ConnectionDialog.py Tue Jun 11 23:08:06 2013 +0200
@@ -67,7 +67,7 @@
left_gridsizer.AddWindow(type_label, flag=wx.GROW)
# Create radio buttons for selecting connection type
- self.ConnectionRadioButtons = {}
+ self.TypeRadioButtons = {} for type, label in [(CONNECTOR, _('Connector')),
(CONTINUATION, _('Continuation'))]:
@@ -76,7 +76,7 @@
radio_button.SetValue(first)
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
left_gridsizer.AddWindow(radio_button, flag=wx.GROW)
- self.ConnectionRadioButtons[type] = radio_button
+ self.TypeRadioButtons[type] = radio_button # Create label for connection name
@@ -120,7 +120,7 @@
self.SetSizer(main_sizer)
# Connector radio button is default control having keyboard focus
- self.ConnectionRadioButtons[CONNECTOR].SetFocus()
+ self.TypeRadioButtons[CONNECTOR].SetFocus() def SetValues(self, values):
@@ -132,7 +132,7 @@
# Parameter is connection type
- self.ConnectionRadioButtons[value].SetValue(True)
+ self.TypeRadioButtons[value].SetValue(True) # Parameter is connection name
@@ -148,7 +148,7 @@
- if self.ConnectionRadioButtons[CONNECTOR].GetValue()
+ if self.TypeRadioButtons[CONNECTOR].GetValue() "name": self.ConnectionName.GetValue()}
values["width"], values["height"] = self.Element.GetSize()
@@ -221,7 +221,7 @@
# Set graphic element displayed, creating a FBD connection element
self.Element = FBD_Connector(self.Preview,
- if self.ConnectionRadioButtons[CONNECTOR].GetValue()
+ if self.TypeRadioButtons[CONNECTOR].GetValue() self.ConnectionName.GetValue())
--- a/dialogs/FBDVariableDialog.py Tue Jun 11 19:33:03 2013 +0200
+++ b/dialogs/FBDVariableDialog.py Tue Jun 11 23:08:06 2013 +0200
@@ -137,25 +137,8 @@
self.Class.Append(choice)
self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[INPUT])
- # Get list of variables defined in POU
- var["Name"]: (var["Class"], var["Type"])
- for var in self.Controller.GetEditedElementInterfaceVars(
- # Add POU name to variable list if POU is a function
- returntype = self.Controller.GetEditedElementInterfaceReturnType(
- if returntype is not None:
- self.Controller.GetEditedElementName(self.TagName)] = \
- # Add POU name if POU is a transition
- words = tagname.split("::")
- self.VarList[words[2]] = ("Output", "BOOL")
+ # Extract list of variables defined in POU + self.RefreshVariableList() # Refresh values in name list box
@@ -174,7 +157,7 @@
# Refresh names in name list box by selecting variables in POU variables
# list that can be applied to variable class
self.VariableName.Clear()
- for name, (var_type, value_type) in self.VarList.iteritems():
+ for name, (var_type, value_type) in self.VariableList.iteritems(): if var_type != "Input" or var_class == INPUT:
self.VariableName.Append(name)
@@ -234,7 +217,7 @@
"class": VARIABLE_CLASSES_DICT_REVERSE[
self.Class.GetStringSelection()],
"expression": expression,
- "var_type": self.VarList.get(expression, (None, None))[1],
+ "var_type": self.VariableList.get(expression, (None, None))[1], "executionOrder": self.ExecutionOrder.GetValue()}
values["width"], values["height"] = self.Element.GetSize()
@@ -317,7 +300,7 @@
VARIABLE_CLASSES_DICT_REVERSE[
self.Class.GetStringSelection()],
- self.VarList.get(name, ("", ""))[1],
+ self.VariableList.get(name, ("", ""))[1], executionOrder = self.ExecutionOrder.GetValue())
# Call BlockPreviewDialog function
--- a/dialogs/LDElementDialog.py Tue Jun 11 19:33:03 2013 +0200
+++ b/dialogs/LDElementDialog.py Tue Jun 11 23:08:06 2013 +0200
@@ -24,198 +24,194 @@
+from graphics.GraphicCommons import CONTACT_NORMAL, CONTACT_REVERSE, \ + CONTACT_RISING, CONTACT_FALLING, COIL_NORMAL, COIL_REVERSE, COIL_SET, \ + COIL_RESET, COIL_RISING, COIL_FALLING +from graphics.LD_Objects import LD_Contact, LD_Coil +from BlockPreviewDialog import BlockPreviewDialog #-------------------------------------------------------------------------------
-# Edit Ladder Element Properties Dialog
+# Set Ladder Element Parmeters Dialog #-------------------------------------------------------------------------------
-class LDElementDialog(wx.Dialog):
+Class that implements a dialog for defining parameters of a LD contact or coil +class LDElementDialog(BlockPreviewDialog): - def __init__(self, parent, controller, type):
- wx.Dialog.__init__(self, parent, size=wx.Size(350, 260),
- title=_("Edit Contact Values"))
- wx.Dialog.__init__(self, parent, size=wx.Size(350, 310),
- title=_("Edit Coil Values"))
+ def __init__(self, parent, controller, tagname, type): + @param parent: Parent wx.Window of dialog for modal + @param controller: Reference to project controller + @param tagname: Tagname of project POU edited + @param type: Type of LD element ('contact or 'coil') + BlockPreviewDialog.__init__(self, parent, controller, tagname, + size=wx.Size(350, 260 if type == "contact" else 310), + title=(_("Edit Contact Values") + else _("Edit Coil Values"))) + # Create dialog main sizer main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
main_sizer.AddGrowableCol(0)
main_sizer.AddGrowableRow(0)
+ # Create a sizer for dividing LD element parameters in two columns column_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer.AddSizer(column_sizer, border=20,
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=7, vgap=0)
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=9, vgap=0)
+ # Create a sizer for left column + left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, + rows=(7 if type == "contact" else 9), vgap=0) left_gridsizer.AddGrowableCol(0)
column_sizer.AddSizer(left_gridsizer, 1, border=5,
+ # Create label for LD element modifier modifier_label = wx.StaticText(self, label=_('Modifier:'))
- left_gridsizer.AddWindow(modifier_label, border=5, flag=wx.GROW|wx.BOTTOM)
+ left_gridsizer.AddWindow(modifier_label, border=5, + flag=wx.GROW|wx.BOTTOM) - self.Normal = wx.RadioButton(self, label=_("Normal"), style=wx.RB_GROUP)
- self.Normal.SetValue(True)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.Normal)
- left_gridsizer.AddWindow(self.Normal, flag=wx.GROW)
- self.Negated = wx.RadioButton(self, label=_("Negated"))
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.Negated)
- left_gridsizer.AddWindow(self.Negated, flag=wx.GROW)
+ # Create radio buttons for selecting LD element modifier + self.ModifierRadioButtons = {} + element_modifiers = ([CONTACT_NORMAL, CONTACT_REVERSE, + CONTACT_RISING, CONTACT_FALLING] + else [COIL_NORMAL, COIL_REVERSE, COIL_SET, + COIL_RESET, COIL_RISING, COIL_FALLING]) + modifiers_label = [_("Normal"), _("Negated")] + \ + ([_("Set"), _("Reset")] if type == "coil" else []) + \ + [_("Rising Edge"), _("Falling Edge")]
- self.Set = wx.RadioButton(self, label=_("Set"))
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.Set)
- left_gridsizer.AddWindow(self.Set, flag=wx.GROW)
- self.Reset = wx.RadioButton(self, label=_("Reset"))
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.Reset)
- left_gridsizer.AddWindow(self.Reset, flag=wx.GROW)
- self.RisingEdge = wx.RadioButton(self, label=_("Rising Edge"))
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.RisingEdge)
- left_gridsizer.AddWindow(self.RisingEdge, flag=wx.GROW)
+ for modifier, label in zip(element_modifiers, modifiers_label): + radio_button = wx.RadioButton(self, label=label, + style=(wx.RB_GROUP if first else wx.RB_SINGLE)) + radio_button.SetValue(first) + self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) + left_gridsizer.AddWindow(radio_button, flag=wx.GROW) + self.ModifierRadioButtons[modifier] = radio_button - self.FallingEdge = wx.RadioButton(self, label=_("Falling Edge"))
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.FallingEdge)
- left_gridsizer.AddWindow(self.FallingEdge, flag=wx.GROW)
+ # Create label for LD element variable + element_variable_label = wx.StaticText(self, label=_('Variable:')) + left_gridsizer.AddWindow(element_variable_label, border=5, - element_name_label = wx.StaticText(self, label=_('Name:'))
- left_gridsizer.AddWindow(element_name_label, border=5, flag=wx.GROW|wx.TOP)
+ # Create a combo box for defining LD element variable + self.ElementVariable = wx.ComboBox(self, style=wx.CB_READONLY) + self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, + left_gridsizer.AddWindow(self.ElementVariable, border=5, - self.ElementName = wx.ComboBox(self, style=wx.CB_READONLY)
- self.Bind(wx.EVT_COMBOBOX, self.OnNameChanged, self.ElementName)
- left_gridsizer.AddWindow(self.ElementName, border=5, flag=wx.GROW|wx.TOP)
+ # Create a sizer for right column right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
right_gridsizer.AddGrowableCol(0)
right_gridsizer.AddGrowableRow(1)
column_sizer.AddSizer(right_gridsizer, 1, border=5,
- preview_label = wx.StaticText(self, label=_('Preview:'))
- right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
- self.Preview = wx.Panel(self,
- style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
- self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
- setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
- setattr(self.Preview, "GetScaling", lambda:None)
- setattr(self.Preview, "IsOfType", controller.IsOfType)
- self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
+ # Add preview panel and associated label to sizers + right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW) right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
- button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
- main_sizer.AddSizer(button_sizer, border=20,
+ # Add buttons sizer to sizers + main_sizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
self.SetSizer(main_sizer)
- self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "")
- self.Element = LD_Coil(self.Preview, COIL_NORMAL, "")
+ # Save LD element class + self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) + # Extract list of variables defined in POU + self.RefreshVariableList()
+ # Set values in ElementVariable + for name, (var_type, value_type) in self.VariableList.iteritems(): + # Only select BOOL variable and avoid input for coil + if (type == "contact" or var_type != "Input") and \ + self.ElementVariable.Append(name) + self.ElementVariable.Enable(self.ElementVariable.GetCount() > 0)
+ # Normal radio button is default control having keyboard focus + self.ModifierRadioButtons[element_modifiers[0]].SetFocus() - def SetPreviewFont(self, font):
- self.Preview.SetFont(font)
- def SetElementSize(self, size):
- min_width, min_height = self.Element.GetMinSize()
- width, height = max(min_width, size[0]), max(min_height, size[1])
- self.Element.SetSize(width, height)
- def SetVariables(self, vars):
- self.ElementName.Clear()
- self.ElementName.Append(name)
- self.ElementName.Enable(self.ElementName.GetCount() > 0)
+ def GetElementModifier(self): + Return modifier selected for LD element + @return: Modifier selected (None if not found) + # Go through radio buttons and return modifier associated to the one + for modifier, control in self.ModifierRadioButtons.iteritems(): def SetValues(self, values):
+ Set default LD element parameters + @param values: Block parameters values + # For each parameters defined, set corresponding control value for name, value in values.items():
- self.Element.SetName(value)
- self.ElementName.SetStringSelection(value)
- self.Element.SetType(value)
- if self.Type == "contact":
- if value == CONTACT_NORMAL:
- self.Normal.SetValue(True)
- elif value == CONTACT_REVERSE:
- self.Negated.SetValue(True)
- elif value == CONTACT_RISING:
- self.RisingEdge.SetValue(True)
- elif value == CONTACT_FALLING:
- self.FallingEdge.SetValue(True)
- elif self.Type == "coil":
- if value == COIL_NORMAL:
- self.Normal.SetValue(True)
- elif value == COIL_REVERSE:
- self.Negated.SetValue(True)
- elif value == COIL_SET:
- self.Set.SetValue(True)
- elif value == COIL_RESET:
- self.Reset.SetValue(True)
- elif value == COIL_RISING:
- self.RisingEdge.SetValue(True)
- elif value == COIL_FALLING:
- self.FallingEdge.SetValue(True)
+ # Parameter is LD element variable + self.ElementVariable.SetStringSelection(value) + # Set value of other controls + elif name == "modifier": + self.ModifierRadioButtons[value].SetValue(True) + # Refresh preview panel
- values["name"] = self.Element.GetName()
- values["type"] = self.Element.GetType()
+ Return LD element parameters defined in dialog + @return: {parameter_name: parameter_value,...} + "variable": self.ElementVariable.GetValue(), + "modifier": self.GetElementModifier()} values["width"], values["height"] = self.Element.GetSize()
- def OnTypeChanged(self, event):
- if self.Type == "contact":
- if self.Normal.GetValue():
- self.Element.SetType(CONTACT_NORMAL)
- elif self.Negated.GetValue():
- self.Element.SetType(CONTACT_REVERSE)
- elif self.RisingEdge.GetValue():
- self.Element.SetType(CONTACT_RISING)
- elif self.FallingEdge.GetValue():
- self.Element.SetType(CONTACT_FALLING)
- elif self.Type == "coil":
- if self.Normal.GetValue():
- self.Element.SetType(COIL_NORMAL)
- elif self.Negated.GetValue():
- self.Element.SetType(COIL_REVERSE)
- elif self.Set.GetValue():
- self.Element.SetType(COIL_SET)
- elif self.Reset.GetValue():
- self.Element.SetType(COIL_RESET)
- elif self.RisingEdge.GetValue():
- self.Element.SetType(COIL_RISING)
- elif self.FallingEdge.GetValue():
- self.Element.SetType(COIL_FALLING)
+ def OnModifierChanged(self, event): + Called when LD element modifier changed + @param event: wx.RadioButtonEvent - def OnNameChanged(self, event):
- self.Element.SetName(self.ElementName.GetStringSelection())
+ def OnVariableChanged(self, event): + Called when LD element associated variable changed + @param event: wx.ComboBoxEvent def RefreshPreview(self):
- dc = wx.ClientDC(self.Preview)
- dc.SetFont(self.Preview.GetFont())
- clientsize = self.Preview.GetClientSize()
- width, height = self.Element.GetSize()
- self.Element.SetPosition((clientsize.width - width) / 2, (clientsize.height - height) / 2)
- def OnPaint(self, event):
+ Refresh preview panel of graphic element + Override BlockPreviewDialog function + # Set graphic element displayed, creating a LD element + self.Element = self.ElementClass( + self.GetElementModifier(), + self.ElementVariable.GetStringSelection()) + # Call BlockPreviewDialog function + BlockPreviewDialog.RefreshPreview(self) --- a/editors/Viewer.py Tue Jun 11 19:33:03 2013 +0200
+++ b/editors/Viewer.py Tue Jun 11 23:08:06 2013 +0200
@@ -2282,21 +2282,13 @@
def AddNewContact(self, bbox):
- dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
+ dialog = LDElementDialog(self.ParentWindow, self.Controler, self.TagName, "contact") dialog.SetPreviewFont(self.GetFont())
- vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
- if var["Type"] == "BOOL":
- varlist.append(var["Name"])
- dialog.SetVariables(varlist)
- dialog.SetValues({"name":"","type":CONTACT_NORMAL})
- dialog.SetElementSize((bbox.width, bbox.height))
+ dialog.SetMinElementSize((bbox.width, bbox.height)) if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
- contact = LD_Contact(self, values["type"], values["name"], id)
+ contact = LD_Contact(self, values["modifier"], values["variable"], id) contact.SetPosition(bbox.x, bbox.y)
contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
@@ -2309,24 +2301,13 @@
def AddNewCoil(self, bbox):
- dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
+ dialog = LDElementDialog(self.ParentWindow, self.Controler, self.TagName, "coil") dialog.SetPreviewFont(self.GetFont())
- vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
- if var["Class"] != "Input" and var["Type"] == "BOOL":
- varlist.append(var["Name"])
- returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
- if returntype == "BOOL":
- varlist.append(self.Controler.GetEditedElementName(self.TagName))
- dialog.SetVariables(varlist)
- dialog.SetValues({"name":"","type":COIL_NORMAL})
- dialog.SetElementSize((bbox.width, bbox.height))
+ dialog.SetMinElementSize((bbox.width, bbox.height)) if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
- coil = LD_Coil(self, values["type"], values["name"], id)
+ coil = LD_Coil(self, values["modifier"], values["variable"], id) coil.SetPosition(bbox.x, bbox.y)
coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
@@ -2577,23 +2558,16 @@
def EditContactContent(self, contact):
- dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
+ dialog = LDElementDialog(self.ParentWindow, self.Controler, self.TagName, "contact") dialog.SetPreviewFont(self.GetFont())
- vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
- if var["Type"] == "BOOL":
- varlist.append(var["Name"])
- dialog.SetVariables(varlist)
- values = {"name" : contact.GetName(), "type" : contact.GetType()}
- dialog.SetValues(values)
- dialog.SetElementSize(contact.GetSize())
+ dialog.SetMinElementSize(contact.GetSize()) + dialog.SetValues({"variable" : contact.GetName(), + "modifier" : contact.GetType()}) if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
rect = contact.GetRedrawRect(1, 1)
- contact.SetName(values["name"])
- contact.SetType(values["type"])
+ contact.SetName(values["variable"]) + contact.SetType(values["modifier"]) contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
rect = rect.Union(contact.GetRedrawRect())
self.RefreshContactModel(contact)
@@ -2604,26 +2578,16 @@
def EditCoilContent(self, coil):
- dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
+ dialog = LDElementDialog(self.ParentWindow, self.Controler, self.TagName, "coil") dialog.SetPreviewFont(self.GetFont())
- vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
- if var["Class"] != "Input" and var["Type"] == "BOOL":
- varlist.append(var["Name"])
- returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
- if returntype == "BOOL":
- varlist.append(self.Controler.GetEditedElementName(self.TagName))
- dialog.SetVariables(varlist)
- values = {"name" : coil.GetName(), "type" : coil.GetType()}
- dialog.SetValues(values)
- dialog.SetElementSize(coil.GetSize())
+ dialog.SetMinElementSize(coil.GetSize()) + dialog.SetValues({"variable" : coil.GetName(), + "modifier" : coil.GetType()}) if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
rect = coil.GetRedrawRect(1, 1)
- coil.SetName(values["name"])
- coil.SetType(values["type"])
+ coil.SetName(values["variable"]) + coil.SetType(values["modifier"]) coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
rect = rect.Union(coil.GetRedrawRect())
self.RefreshCoilModel(coil)