equal
deleted
inserted
replaced
32 |
32 |
33 # ------------------------------------------------------------------------------- |
33 # ------------------------------------------------------------------------------- |
34 # Helpers |
34 # Helpers |
35 # ------------------------------------------------------------------------------- |
35 # ------------------------------------------------------------------------------- |
36 |
36 |
37 # Dictionaries containing correspondence between variable block class and string |
|
38 # to be shown in Class combo box in both sense |
|
39 VARIABLE_CLASSES_DICT = { |
|
40 INPUT: _("Input"), |
|
41 INOUT: _("InOut"), |
|
42 OUTPUT: _("Output") |
|
43 } |
|
44 |
|
45 VARIABLE_CLASSES_DICT_REVERSE = dict( |
|
46 [(value, key) for key, value in VARIABLE_CLASSES_DICT.iteritems()]) |
|
47 |
37 |
48 # ------------------------------------------------------------------------------- |
38 # ------------------------------------------------------------------------------- |
49 # Set Variable Parameters Dialog |
39 # Set Variable Parameters Dialog |
50 # ------------------------------------------------------------------------------- |
40 # ------------------------------------------------------------------------------- |
51 |
41 |
64 @param tagname: Tagname of project POU edited |
54 @param tagname: Tagname of project POU edited |
65 @param exclude_input: Exclude input from variable class selection |
55 @param exclude_input: Exclude input from variable class selection |
66 """ |
56 """ |
67 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
57 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
68 title=_('Variable Properties')) |
58 title=_('Variable Properties')) |
|
59 |
|
60 # Dictionaries containing correspondence between variable block class and string |
|
61 # to be shown in Class combo box in both sense |
|
62 self.VARIABLE_CLASSES_DICT = { |
|
63 INPUT: _("Input"), |
|
64 INOUT: _("InOut"), |
|
65 OUTPUT: _("Output") |
|
66 } |
|
67 |
|
68 self.VARIABLE_CLASSES_DICT_REVERSE = dict( |
|
69 [(value, key) for key, value in self.VARIABLE_CLASSES_DICT.iteritems()]) |
69 |
70 |
70 # Init common sizers |
71 # Init common sizers |
71 self._init_sizers(4, 2, 4, None, 3, 2) |
72 self._init_sizers(4, 2, 4, None, 3, 2) |
72 |
73 |
73 # Create label for variable class |
74 # Create label for variable class |
117 self.MainSizer.AddSizer( |
118 self.MainSizer.AddSizer( |
118 self.ButtonSizer, border=20, |
119 self.ButtonSizer, border=20, |
119 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
120 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
120 |
121 |
121 # Set options that can be selected in class combo box |
122 # Set options that can be selected in class combo box |
122 for var_class, choice in VARIABLE_CLASSES_DICT.iteritems(): |
123 for var_class, choice in self.VARIABLE_CLASSES_DICT.iteritems(): |
123 if not exclude_input or var_class != INPUT: |
124 if not exclude_input or var_class != INPUT: |
124 self.Class.Append(choice) |
125 self.Class.Append(choice) |
125 self.Class.SetSelection(0) |
126 self.Class.SetSelection(0) |
126 |
127 |
127 # Extract list of variables defined in POU |
128 # Extract list of variables defined in POU |
139 def RefreshNameList(self): |
140 def RefreshNameList(self): |
140 """ |
141 """ |
141 Called to refresh names in name list box |
142 Called to refresh names in name list box |
142 """ |
143 """ |
143 # Get variable class to select POU variable applicable |
144 # Get variable class to select POU variable applicable |
144 var_class = VARIABLE_CLASSES_DICT_REVERSE[ |
145 var_class = self.VARIABLE_CLASSES_DICT_REVERSE[ |
145 self.Class.GetStringSelection()] |
146 self.Class.GetStringSelection()] |
146 |
147 |
147 # Refresh names in name list box by selecting variables in POU variables |
148 # Refresh names in name list box by selecting variables in POU variables |
148 # list that can be applied to variable class |
149 # list that can be applied to variable class |
149 self.VariableName.Clear() |
150 self.VariableName.Clear() |
170 |
171 |
171 # Get class parameter value |
172 # Get class parameter value |
172 var_class = values.get("class", None) |
173 var_class = values.get("class", None) |
173 if var_class is not None: |
174 if var_class is not None: |
174 # Set class selected in class combo box |
175 # Set class selected in class combo box |
175 self.Class.SetStringSelection(VARIABLE_CLASSES_DICT[var_class]) |
176 self.Class.SetStringSelection(self.VARIABLE_CLASSES_DICT[var_class]) |
176 # Refresh names in name list box according to var class |
177 # Refresh names in name list box according to var class |
177 self.RefreshNameList() |
178 self.RefreshNameList() |
178 |
179 |
179 # For each parameters defined, set corresponding control value |
180 # For each parameters defined, set corresponding control value |
180 for name, value in values.items(): |
181 for name, value in values.items(): |
202 Return block parameters defined in dialog |
203 Return block parameters defined in dialog |
203 @return: {parameter_name: parameter_value,...} |
204 @return: {parameter_name: parameter_value,...} |
204 """ |
205 """ |
205 expression = self.Expression.GetValue() |
206 expression = self.Expression.GetValue() |
206 values = { |
207 values = { |
207 "class": VARIABLE_CLASSES_DICT_REVERSE[ |
208 "class": self.VARIABLE_CLASSES_DICT_REVERSE[ |
208 self.Class.GetStringSelection()], |
209 self.Class.GetStringSelection()], |
209 "expression": expression, |
210 "expression": expression, |
210 "var_type": self.VariableList.get(expression, (None, None))[1], |
211 "var_type": self.VariableList.get(expression, (None, None))[1], |
211 "executionOrder": self.ExecutionOrder.GetValue()} |
212 "executionOrder": self.ExecutionOrder.GetValue()} |
212 values["width"], values["height"] = self.Element.GetSize() |
213 values["width"], values["height"] = self.Element.GetSize() |
286 name = self.Expression.GetValue() |
287 name = self.Expression.GetValue() |
287 |
288 |
288 # Set graphic element displayed, creating a FBD variable element |
289 # Set graphic element displayed, creating a FBD variable element |
289 self.Element = FBD_Variable( |
290 self.Element = FBD_Variable( |
290 self.Preview, |
291 self.Preview, |
291 VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()], |
292 self.VARIABLE_CLASSES_DICT_REVERSE[self.Class.GetStringSelection()], |
292 name, |
293 name, |
293 self.VariableList.get(name, ("", ""))[1], |
294 self.VariableList.get(name, ("", ""))[1], |
294 executionOrder=self.ExecutionOrder.GetValue()) |
295 executionOrder=self.ExecutionOrder.GetValue()) |
295 |
296 |
296 # Call BlockPreviewDialog function |
297 # Call BlockPreviewDialog function |