dialogs/FBDVariableDialog.py
changeset 1246 101625efb1c1
parent 1244 336d515096b1
child 1250 7e6de17c687a
equal deleted inserted replaced
1245:d34ba528346b 1246:101625efb1c1
   135         # Set options that can be selected in class combo box
   135         # Set options that can be selected in class combo box
   136         for choice in VARIABLE_CLASSES_DICT.itervalues():
   136         for choice in VARIABLE_CLASSES_DICT.itervalues():
   137             self.Class.Append(choice)
   137             self.Class.Append(choice)
   138         self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[INPUT])
   138         self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[INPUT])
   139         
   139         
   140         # Get list of variables defined in POU
   140         # Extract list of variables defined in POU
   141         self.VarList = {
   141         self.RefreshVariableList()
   142             var["Name"]: (var["Class"], var["Type"])
       
   143             for var in self.Controller.GetEditedElementInterfaceVars(
       
   144                                                         self.TagName)
       
   145             if var["Edit"]}
       
   146         
       
   147         # Add POU name to variable list if POU is a function 
       
   148         returntype = self.Controller.GetEditedElementInterfaceReturnType(
       
   149                                                             self.TagName)
       
   150         if returntype is not None:
       
   151             self.VarList[
       
   152                 self.Controller.GetEditedElementName(self.TagName)] = \
       
   153                  ("Output", returntype)
       
   154         
       
   155         # Add POU name if POU is a transition
       
   156         words = tagname.split("::")
       
   157         if words[0] == "T":
       
   158             self.VarList[words[2]] = ("Output", "BOOL")
       
   159         
   142         
   160         # Refresh values in name list box
   143         # Refresh values in name list box
   161         self.RefreshNameList()
   144         self.RefreshNameList()
   162         
   145         
   163         # Class combo box is default control having keyboard focus
   146         # Class combo box is default control having keyboard focus
   172                             self.Class.GetStringSelection()]
   155                             self.Class.GetStringSelection()]
   173         
   156         
   174         # Refresh names in name list box by selecting variables in POU variables
   157         # Refresh names in name list box by selecting variables in POU variables
   175         # list that can be applied to variable class
   158         # list that can be applied to variable class
   176         self.VariableName.Clear()
   159         self.VariableName.Clear()
   177         for name, (var_type, value_type) in self.VarList.iteritems():
   160         for name, (var_type, value_type) in self.VariableList.iteritems():
   178             if var_type != "Input" or var_class == INPUT:
   161             if var_type != "Input" or var_class == INPUT:
   179                 self.VariableName.Append(name)
   162                 self.VariableName.Append(name)
   180         
   163         
   181         # Get variable expression and select corresponding value in name list
   164         # Get variable expression and select corresponding value in name list
   182         # box if it exists
   165         # box if it exists
   232         expression = self.Expression.GetValue()
   215         expression = self.Expression.GetValue()
   233         values = {
   216         values = {
   234             "class": VARIABLE_CLASSES_DICT_REVERSE[
   217             "class": VARIABLE_CLASSES_DICT_REVERSE[
   235                         self.Class.GetStringSelection()],
   218                         self.Class.GetStringSelection()],
   236             "expression": expression,
   219             "expression": expression,
   237             "var_type": self.VarList.get(expression, (None, None))[1],
   220             "var_type": self.VariableList.get(expression, (None, None))[1],
   238             "executionOrder": self.ExecutionOrder.GetValue()}
   221             "executionOrder": self.ExecutionOrder.GetValue()}
   239         values["width"], values["height"] = self.Element.GetSize()
   222         values["width"], values["height"] = self.Element.GetSize()
   240         return values
   223         return values
   241 
   224 
   242     def OnOK(self, event):
   225     def OnOK(self, event):
   315         # Set graphic element displayed, creating a FBD variable element
   298         # Set graphic element displayed, creating a FBD variable element
   316         self.Element = FBD_Variable(self.Preview, 
   299         self.Element = FBD_Variable(self.Preview, 
   317                     VARIABLE_CLASSES_DICT_REVERSE[
   300                     VARIABLE_CLASSES_DICT_REVERSE[
   318                         self.Class.GetStringSelection()], 
   301                         self.Class.GetStringSelection()], 
   319                     name, 
   302                     name, 
   320                     self.VarList.get(name, ("", ""))[1], 
   303                     self.VariableList.get(name, ("", ""))[1], 
   321                     executionOrder = self.ExecutionOrder.GetValue())
   304                     executionOrder = self.ExecutionOrder.GetValue())
   322         
   305         
   323         # Call BlockPreviewDialog function
   306         # Call BlockPreviewDialog function
   324         BlockPreviewDialog.RefreshPreview(self)
   307         BlockPreviewDialog.RefreshPreview(self)
   325         
   308