--- a/dialogs/BlockPreviewDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/BlockPreviewDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -37,7 +37,7 @@
"""
class BlockPreviewDialog(wx.Dialog):
-
+
def __init__(self, parent, controller, tagname, size, title):
"""
Constructor
@@ -91,6 +91,53 @@
# Remove reference to project controller
self.Controller = None
+ def _init_sizers(self, main_rows, main_growable_row,
+ left_rows, left_growable_row,
+ right_rows, right_growable_row):
+ """
+ Initialize common sizers
+ @param main_rows: Number of rows in main sizer
+ @param main_growable_row: Row that is growable in main sizer, None if no
+ row is growable
+ @param left_rows: Number of rows in left grid sizer
+ @param left_growable_row: Row that is growable in left grid sizer, None
+ if no row is growable
+ @param right_rows: Number of rows in right grid sizer
+ @param right_growable_row: Row that is growable in right grid sizer,
+ None if no row is growable
+ """
+ # Create dialog main sizer
+ self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0,
+ rows=main_rows, vgap=10)
+ self.MainSizer.AddGrowableCol(0)
+ if main_growable_row is not None:
+ self.MainSizer.AddGrowableRow(main_growable_row)
+
+ # Create a sizer for dividing parameters in two columns
+ column_sizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.MainSizer.AddSizer(column_sizer, border=20,
+ flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
+
+ # Create a sizer for left column
+ self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0,
+ rows=left_rows, vgap=5)
+ self.LeftGridSizer.AddGrowableCol(0)
+ if left_growable_row is not None:
+ self.LeftGridSizer.AddGrowableRow(left_growable_row)
+ column_sizer.AddSizer(self.LeftGridSizer, 1, border=5,
+ flag=wx.GROW|wx.RIGHT)
+
+ # Create a sizer for right column
+ self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0,
+ rows=right_rows, vgap=0)
+ self.RightGridSizer.AddGrowableCol(0)
+ if right_growable_row is not None:
+ self.RightGridSizer.AddGrowableRow(right_growable_row)
+ column_sizer.AddSizer(self.RightGridSizer, 1, border=5,
+ flag=wx.GROW|wx.LEFT)
+
+ self.SetSizer(self.MainSizer)
+
def SetMinElementSize(self, size):
"""
Define minimal graphic element size
--- a/dialogs/ConnectionDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/ConnectionDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -51,25 +51,12 @@
BlockPreviewDialog.__init__(self, parent, controller, tagname,
size=wx.Size(350, 220), title=_('Connection Properties'))
- # 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 FBD connection 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)
-
- # Create a sizer for left column
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
- left_gridsizer.AddGrowableCol(0)
- column_sizer.AddSizer(left_gridsizer, 1, border=5,
- flag=wx.GROW|wx.RIGHT)
+ # Init common sizers
+ self._init_sizers(2, 0, 5, None, 2, 1)
# Create label for connection type
type_label = wx.StaticText(self, label=_('Type:'))
- left_gridsizer.AddWindow(type_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
# Create radio buttons for selecting connection type
self.TypeRadioButtons = {}
@@ -80,32 +67,25 @@
style=(wx.RB_GROUP if first else 0))
radio_button.SetValue(first)
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
- left_gridsizer.AddWindow(radio_button, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
self.TypeRadioButtons[type] = radio_button
first = False
# Create label for connection name
name_label = wx.StaticText(self, label=_('Name:'))
- left_gridsizer.AddWindow(name_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW)
# Create text control for defining connection name
self.ConnectionName = wx.TextCtrl(self)
self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName)
- left_gridsizer.AddWindow(self.ConnectionName, flag=wx.GROW)
-
- # 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,
- flag=wx.GROW|wx.LEFT)
+ self.LeftGridSizer.AddWindow(self.ConnectionName, flag=wx.GROW)
# Add preview panel and associated label to sizers
- right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
- right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
# Add buttons sizer to sizers
- main_sizer.AddSizer(self.ButtonSizer, border=20,
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
# Add button for applying connection name modification to all connection
@@ -123,8 +103,6 @@
controller.GenerateNewName(
tagname, None, "Connection%d", 0))
- self.SetSizer(main_sizer)
-
# Connector radio button is default control having keyboard focus
self.TypeRadioButtons[CONNECTOR].SetFocus()
--- a/dialogs/FBDBlockDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/FBDBlockDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -58,21 +58,13 @@
BlockPreviewDialog.__init__(self, parent, controller, tagname,
size=wx.Size(600, 450), title=_('Block Properties'))
- # Create dialog main sizer
- main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
- main_sizer.AddGrowableCol(0)
- main_sizer.AddGrowableRow(0)
-
- # Create a sizer for dividing FBD block 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)
+ # Init common sizers
+ self._init_sizers(2, 0, 1, 0, 3, 2)
# Create static box around library panel
type_staticbox = wx.StaticBox(self, label=_('Type:'))
left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
- column_sizer.AddSizer(left_staticboxsizer, 1, border=5,
- flag=wx.GROW|wx.RIGHT)
+ self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW)
# Create Library panel and add it to static box
self.LibraryPanel = LibraryPanel(self)
@@ -82,17 +74,10 @@
left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5,
flag=wx.GROW|wx.TOP)
- # Create sizer for other block parameters and preview panle
- right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
- right_gridsizer.AddGrowableCol(0)
- right_gridsizer.AddGrowableRow(2)
- column_sizer.AddSizer(right_gridsizer, 1, border=5,
- flag=wx.GROW|wx.LEFT)
-
# Create sizer for other block parameters
top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
top_right_gridsizer.AddGrowableCol(1)
- right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
+ self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
# Create label for block name
name_label = wx.StaticText(self, label=_('Name:'))
@@ -140,15 +125,13 @@
top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
# Add preview panel and associated label to sizers
- right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
- right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
# Add buttons sizer to sizers
- main_sizer.AddSizer(self.ButtonSizer, border=20,
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
- self.SetSizer(main_sizer)
-
# Dictionary containing correspondence between parameter exchanged and
# control to fill with parameter value
self.ParamsControl = {
@@ -169,38 +152,6 @@
self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname))
self.LibraryPanel.SetFocus()
- def OnOK(self, event):
- """
- Called when dialog OK button is pressed
- Test if parameters defined are valid
- @param event: wx.Event from OK button
- """
- message = None
-
- # Get block type selected
- selected = self.LibraryPanel.GetSelectedBlock()
-
- # Get block type name and if block is a function block
- block_name = self.BlockName.GetValue()
- name_enabled = self.BlockName.IsEnabled()
-
- # Test that a type has been selected for block
- if selected is None:
- message = _("Form isn't complete. Valid block type must be selected!")
-
- # Test, if block is a function block, that a name have been defined
- elif name_enabled and block_name == "":
- message = _("Form isn't complete. Name must be filled!")
-
- # Show error message if an error is detected
- if message is not None:
- self.ShowErrorMessage(message)
-
- # Test block name validity if necessary
- elif not name_enabled or self.TestElementName(block_name):
- # Call BlockPreviewDialog function
- BlockPreviewDialog.OnOK(self, event)
-
def SetValues(self, values):
"""
Set default block parameters
@@ -256,7 +207,39 @@
name: control.GetValue()
for name, control in self.ParamsControl.iteritems()})
return values
-
+
+ def OnOK(self, event):
+ """
+ Called when dialog OK button is pressed
+ Test if parameters defined are valid
+ @param event: wx.Event from OK button
+ """
+ message = None
+
+ # Get block type selected
+ selected = self.LibraryPanel.GetSelectedBlock()
+
+ # Get block type name and if block is a function block
+ block_name = self.BlockName.GetValue()
+ name_enabled = self.BlockName.IsEnabled()
+
+ # Test that a type has been selected for block
+ if selected is None:
+ message = _("Form isn't complete. Valid block type must be selected!")
+
+ # Test, if block is a function block, that a name have been defined
+ elif name_enabled and block_name == "":
+ message = _("Form isn't complete. Name must be filled!")
+
+ # Show error message if an error is detected
+ if message is not None:
+ self.ShowErrorMessage(message)
+
+ # Test block name validity if necessary
+ elif not name_enabled or self.TestElementName(block_name):
+ # Call BlockPreviewDialog function
+ BlockPreviewDialog.OnOK(self, event)
+
def OnLibraryTreeItemSelected(self, event):
"""
Called when block type selected in library panel
--- a/dialogs/FBDVariableDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/FBDVariableDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -61,77 +61,56 @@
BlockPreviewDialog.__init__(self, parent, controller, tagname,
size=wx.Size(400, 380), title=_('Variable Properties'))
- # Create dialog main sizer
- main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
- main_sizer.AddGrowableCol(0)
- main_sizer.AddGrowableRow(2)
-
- # Create a sizer for dividing FBD variable 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)
-
- # Create a sizer for left column
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=5)
- left_gridsizer.AddGrowableCol(0)
- column_sizer.AddSizer(left_gridsizer, 1, border=5,
- flag=wx.GROW|wx.RIGHT)
+ # Init common sizers
+ self._init_sizers(4, 2, 4, None, 3, 2)
# Create label for variable class
class_label = wx.StaticText(self, label=_('Class:'))
- left_gridsizer.AddWindow(class_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(class_label, flag=wx.GROW)
# Create a combo box for defining variable class
self.Class = wx.ComboBox(self, style=wx.CB_READONLY)
self.Bind(wx.EVT_COMBOBOX, self.OnClassChanged, self.Class)
- left_gridsizer.AddWindow(self.Class, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(self.Class, flag=wx.GROW)
# Create label for variable execution order
execution_order_label = wx.StaticText(self,
label=_('Execution Order:'))
- left_gridsizer.AddWindow(execution_order_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(execution_order_label, flag=wx.GROW)
# Create spin control for defining variable execution order
self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged,
self.ExecutionOrder)
- left_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
-
- # Create a sizer for right column
- right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
- right_gridsizer.AddGrowableCol(0)
- right_gridsizer.AddGrowableRow(2)
- column_sizer.AddSizer(right_gridsizer, 1, border=5,
- flag=wx.GROW|wx.LEFT)
+ self.LeftGridSizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
# Create label for variable expression
name_label = wx.StaticText(self, label=_('Expression:'))
- right_gridsizer.AddWindow(name_label, border=5, flag=wx.GROW|wx.BOTTOM)
+ self.RightGridSizer.AddWindow(name_label, border=5,
+ flag=wx.GROW|wx.BOTTOM)
# Create text control for defining variable expression
self.Expression = wx.TextCtrl(self)
self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, self.Expression)
- right_gridsizer.AddWindow(self.Expression, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Expression, flag=wx.GROW)
# Create a list box to selected variable expression in the list of
# variables defined in POU
self.VariableName = wx.ListBox(self, size=wx.Size(0, 120),
style=wx.LB_SINGLE|wx.LB_SORT)
self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName)
- right_gridsizer.AddWindow(self.VariableName, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.VariableName, flag=wx.GROW)
# Add preview panel and associated label to sizers
- main_sizer.AddWindow(self.PreviewLabel, border=20,
+ self.MainSizer.AddWindow(self.PreviewLabel, border=20,
flag=wx.GROW|wx.LEFT|wx.RIGHT)
- main_sizer.AddWindow(self.Preview, border=20,
+ self.MainSizer.AddWindow(self.Preview, border=20,
flag=wx.GROW|wx.LEFT|wx.RIGHT)
# Add buttons sizer to sizers
- main_sizer.AddSizer(self.ButtonSizer, border=20,
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
- self.SetSizer(main_sizer)
-
# Set options that can be selected in class combo box
for choice in VARIABLE_CLASSES_DICT.itervalues():
self.Class.Append(choice)
--- a/dialogs/LDElementDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/LDElementDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -55,26 +55,13 @@
if type == "contact"
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)
-
- # 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,
- flag=wx.GROW|wx.RIGHT)
+ # Init common sizers
+ self._init_sizers(2, 0,
+ (7 if type == "contact" else 9), None, 2, 1)
# Create label for LD element modifier
modifier_label = wx.StaticText(self, label=_('Modifier:'))
- left_gridsizer.AddWindow(modifier_label, border=5,
+ self.LeftGridSizer.AddWindow(modifier_label, border=5,
flag=wx.GROW|wx.BOTTOM)
# Create radio buttons for selecting LD element modifier
@@ -94,41 +81,30 @@
style=(wx.RB_GROUP if first else 0))
radio_button.SetValue(first)
self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button)
- left_gridsizer.AddWindow(radio_button,
- border=(5 if not first and wx.Platform == '__WXMSW__' else 0),
- flag=wx.GROW|wx.TOP)
+ self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
self.ModifierRadioButtons[modifier] = radio_button
first = False
# Create label for LD element variable
element_variable_label = wx.StaticText(self, label=_('Variable:'))
- left_gridsizer.AddWindow(element_variable_label, border=5,
+ self.LeftGridSizer.AddWindow(element_variable_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,
self.ElementVariable)
- left_gridsizer.AddWindow(self.ElementVariable, border=5,
+ self.LeftGridSizer.AddWindow(self.ElementVariable, 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,
- flag=wx.GROW|wx.LEFT)
-
# Add preview panel and associated label to sizers
- right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
- right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
# Add buttons sizer to sizers
- main_sizer.AddSizer(self.ButtonSizer, border=20,
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
- self.SetSizer(main_sizer)
-
# Save LD element class
self.ElementClass = (LD_Contact if type == "contact" else LD_Coil)
--- a/dialogs/LDPowerRailDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/LDPowerRailDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -48,25 +48,12 @@
BlockPreviewDialog.__init__(self, parent, controller, tagname,
size=wx.Size(350, 260), title=_('Power Rail Properties'))
- # 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 power rail 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)
-
- # Create a sizer for left column
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
- left_gridsizer.AddGrowableCol(0)
- column_sizer.AddSizer(left_gridsizer, 1, border=5,
- flag=wx.GROW|wx.RIGHT)
+ # Init common sizers
+ self._init_sizers(2, 0, 5, None, 2, 1)
# Create label for connection type
type_label = wx.StaticText(self, label=_('Type:'))
- left_gridsizer.AddWindow(type_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW)
# Create radio buttons for selecting power rail type
self.TypeRadioButtons = {}
@@ -77,37 +64,28 @@
style=(wx.RB_GROUP if first else 0))
radio_button.SetValue(first)
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button)
- left_gridsizer.AddWindow(radio_button, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW)
self.TypeRadioButtons[type] = radio_button
first = False
# Create label for power rail pin number
pin_number_label = wx.StaticText(self, label=_('Pin number:'))
- left_gridsizer.AddWindow(pin_number_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW)
# Create spin control for defining power rail pin number
self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
style=wx.SP_ARROW_KEYS)
self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
- left_gridsizer.AddWindow(self.PinNumber, flag=wx.GROW)
-
- # 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,
- flag=wx.GROW|wx.LEFT)
+ self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW)
# Add preview panel and associated label to sizers
- right_gridsizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
- right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
# Add buttons sizer to sizers
- main_sizer.AddSizer(self.ButtonSizer, border=20,
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
- self.SetSizer(main_sizer)
-
# Left Power Rail radio button is default control having keyboard focus
self.TypeRadioButtons[LEFTRAIL].SetFocus()
--- a/dialogs/SFCStepDialog.py Wed Jun 12 09:36:59 2013 +0200
+++ b/dialogs/SFCStepDialog.py Wed Jun 12 11:01:27 2013 +0200
@@ -23,183 +23,160 @@
import wx
-from graphics import *
+from graphics.SFC_Objects import SFC_Step
+from BlockPreviewDialog import BlockPreviewDialog
#-------------------------------------------------------------------------------
-# Edit Step Content Dialog
+# Set SFC Step Parameters Dialog
#-------------------------------------------------------------------------------
-class SFCStepDialog(wx.Dialog):
+"""
+Class that implements a dialog for defining parameters of a SFC step graphic
+element
+"""
+
+class SFCStepDialog(BlockPreviewDialog):
- def __init__(self, parent, controller, initial = False):
- wx.Dialog.__init__(self, parent, title=_('Edit Step'),
- size=wx.Size(400, 250))
+ def __init__(self, parent, controller, tagname, initial=False):
+ """
+ Constructor
+ @param parent: Parent wx.Window of dialog for modal
+ @param controller: Reference to project controller
+ @param tagname: Tagname of project POU edited
+ @param initial: True if step is initial (default: False)
+ """
+ BlockPreviewDialog.__init__(self,parent, controller, tagname,
+ size=wx.Size(400, 250), title=_('Edit Step'))
- main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
- main_sizer.AddGrowableCol(0)
- main_sizer.AddGrowableRow(0)
+ # Init common sizers
+ self._init_sizers(2, 0, 6, None, 2, 1)
- column_sizer = wx.BoxSizer(wx.HORIZONTAL)
- main_sizer.AddSizer(column_sizer, border=20,
- flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
+ # Create label for SFC step name
+ name_label = wx.StaticText(self, label=_('Name:'))
+ self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW)
- left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=5)
- left_gridsizer.AddGrowableCol(0)
- column_sizer.AddSizer(left_gridsizer, 1, border=5,
- flag=wx.GROW|wx.RIGHT)
-
- name_label = wx.StaticText(self, label=_('Name:'))
- left_gridsizer.AddWindow(name_label, flag=wx.GROW)
-
+ # Create text control for defining SFC step name
self.StepName = wx.TextCtrl(self)
self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.StepName)
- left_gridsizer.AddWindow(self.StepName, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(self.StepName, flag=wx.GROW)
+ # Create label for SFC step connectors
connectors_label = wx.StaticText(self, label=_('Connectors:'))
- left_gridsizer.AddWindow(connectors_label, flag=wx.GROW)
+ self.LeftGridSizer.AddWindow(connectors_label, flag=wx.GROW)
- self.Input = wx.CheckBox(self, label=_("Input"))
- self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, self.Input)
- left_gridsizer.AddWindow(self.Input, flag=wx.GROW)
+ # Create check boxes for defining connectors available on SFC step
+ self.ConnectorsCheckBox = {}
+ for name, label in [("input", _("Input")),
+ ("output", _("Output")),
+ ("action", _("Action"))]:
+ check_box = wx.CheckBox(self, label=label)
+ self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, check_box)
+ self.LeftGridSizer.AddWindow(check_box, flag=wx.GROW)
+ self.ConnectorsCheckBox[name] = check_box
- self.Output = wx.CheckBox(self, label=_("Output"))
- self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, self.Output)
- left_gridsizer.AddWindow(self.Output, flag=wx.GROW)
+ # Add preview panel and associated label to sizers
+ self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW)
+ self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW)
- self.Action = wx.CheckBox(self, label=_("Action"))
- self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, self.Action)
- left_gridsizer.AddWindow(self.Action, flag=wx.GROW)
-
- 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,
- flag=wx.GROW|wx.LEFT)
-
- 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, "RefreshStepModel", lambda x:None)
- setattr(self.Preview, "GetScaling", lambda:None)
- setattr(self.Preview, "IsOfType", controller.IsOfType)
- self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
- right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
-
- button_sizer = self.CreateButtonSizer(
- wx.OK|wx.CANCEL|wx.CENTRE)
- self.Bind(wx.EVT_BUTTON, self.OnOK,
- button_sizer.GetAffirmativeButton())
- main_sizer.AddSizer(button_sizer, border=20,
+ # Add buttons sizer to sizers
+ self.MainSizer.AddSizer(self.ButtonSizer, border=20,
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
- self.SetSizer(main_sizer)
+ # Save flag that indicates that step is initial
+ self.Initial = initial
- self.Step = None
- self.Initial = initial
- self.MinStepSize = None
-
- self.PouNames = []
- self.Variables = []
- self.StepNames = []
-
+ # Step name text control is default control having keyboard focus
self.StepName.SetFocus()
- def SetPreviewFont(self, font):
- self.Preview.SetFont(font)
-
- def OnOK(self, event):
- message = None
- step_name = self.StepName.GetValue()
- if step_name == "":
- message = _("You must type a name!")
- elif not TestIdentifier(step_name):
- message = _("\"%s\" is not a valid identifier!") % step_name
- elif step_name.upper() in IEC_KEYWORDS:
- message = _("\"%s\" is a keyword. It can't be used!") % step_name
- elif step_name.upper() in self.PouNames:
- message = _("A POU named \"%s\" already exists!") % step_name
- elif step_name.upper() in self.Variables:
- message = _("A variable with \"%s\" as name already exists in this pou!") % step_name
- elif step_name.upper() in self.StepNames:
- message = _("\"%s\" step already exists!") % step_name
- if message is not None:
- dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
- dialog.ShowModal()
- dialog.Destroy()
- else:
- self.EndModal(wx.ID_OK)
-
- def SetMinStepSize(self, size):
- self.MinStepSize = size
-
- def SetPouNames(self, pou_names):
- self.PouNames = [pou_name.upper() for pou_name in pou_names]
-
- def SetVariables(self, variables):
- self.Variables = [var["Name"].upper() for var in variables]
-
- def SetStepNames(self, step_names):
- self.StepNames = [step_name.upper() for step_name in step_names]
-
def SetValues(self, values):
- value_name = values.get("name", None)
- if value_name:
- self.StepName.SetValue(value_name)
- else:
- self.StepName.SetValue("")
- self.Input.SetValue(values.get("input", False))
- self.Output.SetValue(values.get("output", False))
- self.Action.SetValue(values.get("action", False))
+ """
+ Set default block parameters
+ @param values: Block parameters values
+ """
+ # For each parameters defined, set corresponding control value
+ for name, value in values.items():
+
+ # Parameter is step name
+ if name == "name":
+ self.StepName.ChangeValue(value)
+
+ # Set value of other controls
+ else:
+ control = self.ConnectorsCheckBox.get(name, None)
+ if control is not None:
+ control.SetValue(value)
+
+ # Refresh preview panel
self.RefreshPreview()
def GetValues(self):
- values = {}
- values["name"] = self.StepName.GetValue()
- values["input"] = self.Input.IsChecked()
- values["output"] = self.Output.IsChecked()
- values["action"] = self.Action.IsChecked()
- values["width"], values["height"] = self.Step.GetSize()
+ """
+ Return step parameters defined in dialog
+ @return: {parameter_name: parameter_value,...}
+ """
+ values = {"name": self.StepName.GetValue()}
+ values.update({
+ name: control.IsChecked()
+ for name, control in self.ConnectorsCheckBox.iteritems()})
+ values["width"], values["height"] = self.Element.GetSize()
return values
+ def OnOK(self, event):
+ """
+ Called when dialog OK button is pressed
+ Test if step name defined is valid
+ @param event: wx.Event from OK button
+ """
+ message = None
+
+ # Get step name typed by user
+ step_name = self.StepName.GetValue()
+
+ # Test that a name have been defined
+ if step_name == "":
+ message = _("Form isn't complete. Name must be filled!")
+
+ # If an error have been identify, show error message dialog
+ if message is not None:
+ self.ShowErrorMessage(message)
+
+ # Test step name validity
+ elif self.TestElementName(step_name):
+ # Call BlockPreviewDialog function
+ BlockPreviewDialog.OnOK(self, event)
+
def OnConnectorsChanged(self, event):
+ """
+ Called when a step connector value changed
+ @param event: wx.CheckBoxEvent
+ """
self.RefreshPreview()
event.Skip()
def OnNameChanged(self, event):
+ """
+ Called when step name value changed
+ @param event: wx.TextEvent
+ """
self.RefreshPreview()
event.Skip()
def RefreshPreview(self):
- dc = wx.ClientDC(self.Preview)
- dc.SetFont(self.Preview.GetFont())
- dc.Clear()
- self.Step = SFC_Step(self.Preview, self.StepName.GetValue(), self.Initial)
- if self.Input.IsChecked():
- self.Step.AddInput()
- else:
- self.Step.RemoveInput()
- if self.Output.IsChecked():
- self.Step.AddOutput()
- else:
- self.Step.RemoveOutput()
- if self.Action.IsChecked():
- self.Step.AddAction()
- else:
- self.Step.RemoveAction()
- width, height = self.MinStepSize
- min_width, min_height = self.Step.GetMinSize()
- width, height = max(min_width, width), max(min_height, height)
- self.Step.SetSize(width, height)
- clientsize = self.Preview.GetClientSize()
- x = (clientsize.width - width) / 2
- y = (clientsize.height - height) / 2
- self.Step.SetPosition(x, y)
- self.Step.Draw(dc)
-
- def OnPaint(self, event):
- self.RefreshPreview()
- event.Skip()
+ """
+ Refresh preview panel of graphic element
+ Override BlockPreviewDialog function
+ """
+ # Set graphic element displayed, creating a SFC step element
+ self.Element = SFC_Step(self.Preview,
+ self.StepName.GetValue(),
+ self.Initial)
+
+ # Update connectors of SFC step element according to check boxes value
+ for name, control in self.ConnectorsCheckBox.iteritems():
+ if control.IsChecked():
+ getattr(self.Element, "Add" + name.capitalize())()
+ else:
+ getattr(self.Element, "Remove" + name.capitalize())()
+
+ # Call BlockPreviewDialog function
+ BlockPreviewDialog.RefreshPreview(self)
--- a/editors/Viewer.py Wed Jun 12 09:36:59 2013 +0200
+++ b/editors/Viewer.py Wed Jun 12 11:01:27 2013 +0200
@@ -2340,12 +2340,9 @@
dialog.Destroy()
def AddNewStep(self, bbox, initial = False):
- dialog = SFCStepDialog(self.ParentWindow, self.Controler, initial)
+ dialog = SFCStepDialog(self.ParentWindow, self.Controler, self.TagName, initial)
dialog.SetPreviewFont(self.GetFont())
- dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
- dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
- dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step)])
- dialog.SetMinStepSize((bbox.width, bbox.height))
+ dialog.SetMinElementSize((bbox.width, bbox.height))
if dialog.ShowModal() == wx.ID_OK:
id = self.GetNewId()
values = dialog.GetValues()
@@ -2625,18 +2622,15 @@
dialog.Destroy()
def EditStepContent(self, step):
- dialog = SFCStepDialog(self.ParentWindow, self.Controler, step.GetInitial())
+ dialog = SFCStepDialog(self.ParentWindow, self.Controler, self.TagName, step.GetInitial())
dialog.SetPreviewFont(self.GetFont())
- dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
- dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
- dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
- dialog.SetMinStepSize(step.GetSize())
- values = {"name" : step.GetName()}
+ dialog.SetMinElementSize(step.GetSize())
connectors = step.GetConnectors()
- values["input"] = len(connectors["inputs"]) > 0
- values["output"] = len(connectors["outputs"]) > 0
- values["action"] = step.GetActionConnector() != None
- dialog.SetValues(values)
+ dialog.SetValues({
+ "name" : step.GetName(),
+ "input": len(connectors["inputs"]) > 0,
+ "output": len(connectors["outputs"]) > 0,
+ "action": step.GetActionConnector() != None})
if dialog.ShowModal() == wx.ID_OK:
values = dialog.GetValues()
rect = step.GetRedrawRect(1, 1)