dialogs/FBDVariableDialog.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1847 6198190bc121
--- a/dialogs/FBDVariableDialog.py	Mon Aug 21 20:17:19 2017 +0000
+++ b/dialogs/FBDVariableDialog.py	Mon Aug 21 23:22:58 2017 +0300
@@ -29,28 +29,31 @@
 from graphics.FBD_Objects import FBD_Variable
 from BlockPreviewDialog import BlockPreviewDialog
 
-#-------------------------------------------------------------------------------
+# -------------------------------------------------------------------------------
 #                                    Helpers
-#-------------------------------------------------------------------------------
+# -------------------------------------------------------------------------------
 
 # Dictionaries containing correspondence between variable block class and string
 # to be shown in Class combo box in both sense
-VARIABLE_CLASSES_DICT = {INPUT : _("Input"),
-                         INOUT : _("InOut"),
-                         OUTPUT : _("Output")}
+VARIABLE_CLASSES_DICT = {
+    INPUT:  _("Input"),
+    INOUT:  _("InOut"),
+    OUTPUT: _("Output")
+}
+
 VARIABLE_CLASSES_DICT_REVERSE = dict(
     [(value, key) for key, value in VARIABLE_CLASSES_DICT.iteritems()])
 
-#-------------------------------------------------------------------------------
+# -------------------------------------------------------------------------------
 #                        Set Variable Parameters Dialog
-#-------------------------------------------------------------------------------
-
-"""
-Class that implements a dialog for defining parameters of a FBD variable graphic
-element
-"""
+# -------------------------------------------------------------------------------
+
 
 class FBDVariableDialog(BlockPreviewDialog):
+    """
+    Class that implements a dialog for defining parameters of a FBD variable graphic
+    element
+    """
 
     def __init__(self, parent, controller, tagname, exclude_input=False):
         """
@@ -61,70 +64,71 @@
         @param exclude_input: Exclude input from variable class selection
         """
         BlockPreviewDialog.__init__(self, parent, controller, tagname,
-              title=_('Variable Properties'))
-        
+                                    title=_('Variable Properties'))
+
         # Init common sizers
         self._init_sizers(4, 2, 4, None, 3, 2)
-        
+
         # Create label for variable class
         class_label = wx.StaticText(self, label=_('Class:'))
         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)
         self.LeftGridSizer.AddWindow(self.Class, flag=wx.GROW)
-        
+
         # Create label for variable execution order
-        execution_order_label = wx.StaticText(self, 
-              label=_('Execution Order:'))
+        execution_order_label = wx.StaticText(self,
+                                              label=_('Execution Order:'))
         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.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged,
                   self.ExecutionOrder)
         self.LeftGridSizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
-        
+
         # Create label for variable expression
         name_label = wx.StaticText(self, label=_('Expression:'))
-        self.RightGridSizer.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)
         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(-1,120),
-              style=wx.LB_SINGLE|wx.LB_SORT)
+        self.VariableName = wx.ListBox(self, size=wx.Size(-1, 120),
+                                       style=wx.LB_SINGLE | wx.LB_SORT)
         self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName)
-        self.RightGridSizer.AddWindow(self.VariableName, border=4, flag=wx.GROW|wx.TOP)
-        
+        self.RightGridSizer.AddWindow(self.VariableName, border=4, flag=wx.GROW | wx.TOP)
+
         # Add preview panel and associated label to sizers
         self.MainSizer.AddWindow(self.PreviewLabel, border=20,
-              flag=wx.GROW|wx.LEFT|wx.RIGHT)
+                                 flag=wx.GROW | wx.LEFT | wx.RIGHT)
         self.MainSizer.AddWindow(self.Preview, border=20,
-              flag=wx.GROW|wx.LEFT|wx.RIGHT)
-        
+                                 flag=wx.GROW | wx.LEFT | wx.RIGHT)
+
         # Add buttons sizer to sizers
-        self.MainSizer.AddSizer(self.ButtonSizer, border=20, 
-              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
-        
+        self.MainSizer.AddSizer(
+            self.ButtonSizer, border=20,
+            flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
+
         # Set options that can be selected in class combo box
         for var_class, choice in VARIABLE_CLASSES_DICT.iteritems():
             if not exclude_input or var_class != INPUT:
                 self.Class.Append(choice)
         self.Class.SetSelection(0)
-        
+
         # Extract list of variables defined in POU
         self.RefreshVariableList()
-        
+
         # Refresh values in name list box
         self.RefreshNameList()
-        
+
         self.Preview.SetInitialSize(wx.Size(-1, 60))
         self.Fit()
 
@@ -138,32 +142,31 @@
         # Get variable class to select POU variable applicable
         var_class = VARIABLE_CLASSES_DICT_REVERSE[
                             self.Class.GetStringSelection()]
-        
+
         # 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.VariableList.iteritems():
             if var_type != "Input" or var_class == INPUT:
                 self.VariableName.Append(name)
-        
+
         # Get variable expression and select corresponding value in name list
         # box if it exists
         selected = self.Expression.GetValue()
-        if (selected != "" and 
-            self.VariableName.FindString(selected) != wx.NOT_FOUND):
+        if selected != "" and self.VariableName.FindString(selected) != wx.NOT_FOUND:
             self.VariableName.SetStringSelection(selected)
         else:
             self.VariableName.SetSelection(wx.NOT_FOUND)
-        
+
         # Disable name list box if no name present inside
         self.VariableName.Enable(self.VariableName.GetCount() > 0)
-            
+
     def SetValues(self, values):
         """
         Set default variable parameters
         @param values: Variable parameters values
         """
-        
+
         # Get class parameter value
         var_class = values.get("class", None)
         if var_class is not None:
@@ -171,10 +174,10 @@
             self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[var_class])
             # Refresh names in name list box according to var class
             self.RefreshNameList()
-        
+
         # For each parameters defined, set corresponding control value
         for name, value in values.items():
-            
+
             # Parameter is variable expression
             if name == "expression":
                 # Set expression text control value
@@ -184,15 +187,15 @@
                     self.VariableName.SetStringSelection(value)
                 else:
                     self.VariableName.SetSelection(wx.NOT_FOUND)
-            
+
             # Parameter is variable execution order
             elif name == "executionOrder":
                 self.ExecutionOrder.SetValue(value)
-        
+
         # Refresh preview panel
         self.RefreshPreview()
         self.Fit()
-        
+
     def GetValues(self):
         """
         Return block parameters defined in dialog
@@ -215,16 +218,16 @@
         @param event: wx.Event from OK button
         """
         message = None
-        
+
         # Test that an expression have been selected or typed by user
         value = self.Expression.GetValue()
         if value == "":
             message = _("At least a variable or an expression must be selected!")
-        
+
         # Show error message if an error is detected
         if message is not None:
             self.ShowErrorMessage(message)
-        
+
         else:
             # Call BlockPreviewDialog function
             BlockPreviewDialog.OnOK(self, event)
@@ -236,7 +239,7 @@
         """
         # Refresh name list box values
         self.RefreshNameList()
-        
+
         self.RefreshPreview()
         event.Skip()
 
@@ -249,10 +252,10 @@
         # list box if value selected is valid
         if self.VariableName.GetSelection() != wx.NOT_FOUND:
             self.Expression.ChangeValue(self.VariableName.GetStringSelection())
-        
-        self.RefreshPreview()
-        event.Skip()
-    
+
+        self.RefreshPreview()
+        event.Skip()
+
     def OnExpressionChanged(self, event):
         """
         Called when expression text control is changed by user
@@ -261,10 +264,10 @@
         # Select the corresponding value in name list box if it exists
         self.VariableName.SetSelection(
             self.VariableName.FindString(self.Expression.GetValue()))
-        
-        self.RefreshPreview()
-        event.Skip()
-    
+
+        self.RefreshPreview()
+        event.Skip()
+
     def OnExecutionOrderChanged(self, event):
         """
         Called when block execution control value changed
@@ -272,7 +275,7 @@
         """
         self.RefreshPreview()
         event.Skip()
-    
+
     def RefreshPreview(self):
         """
         Refresh preview panel of graphic element
@@ -280,16 +283,14 @@
         """
         # Get expression value to put in FBD variable element
         name = self.Expression.GetValue()
-        
+
         # Set graphic element displayed, creating a FBD variable element
-        self.Element = FBD_Variable(self.Preview, 
-                    VARIABLE_CLASSES_DICT_REVERSE[
-                        self.Class.GetStringSelection()], 
-                    name, 
-                    self.VariableList.get(name, ("", ""))[1], 
-                    executionOrder = self.ExecutionOrder.GetValue())
-        
+        self.Element = FBD_Variable(
+            self.Preview,
+            VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()],
+            name,
+            self.VariableList.get(name, ("", ""))[1],
+            executionOrder=self.ExecutionOrder.GetValue())
+
         # Call BlockPreviewDialog function
         BlockPreviewDialog.RefreshPreview(self)
-        
-