39 Class that implements a dialog for defining parameters of a LD contact or coil |
39 Class that implements a dialog for defining parameters of a LD contact or coil |
40 graphic element |
40 graphic element |
41 """ |
41 """ |
42 |
42 |
43 class LDElementDialog(BlockPreviewDialog): |
43 class LDElementDialog(BlockPreviewDialog): |
44 |
44 |
45 def __init__(self, parent, controller, tagname, type): |
45 def __init__(self, parent, controller, tagname, type): |
46 """ |
46 """ |
47 Constructor |
47 Constructor |
48 @param parent: Parent wx.Window of dialog for modal |
48 @param parent: Parent wx.Window of dialog for modal |
49 @param controller: Reference to project controller |
49 @param controller: Reference to project controller |
50 @param tagname: Tagname of project POU edited |
50 @param tagname: Tagname of project POU edited |
51 @param type: Type of LD element ('contact or 'coil') |
51 @param type: Type of LD element ('contact or 'coil') |
52 """ |
52 """ |
53 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
53 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
54 title=(_("Edit Contact Values") |
54 title=(_("Edit Contact Values") |
55 if type == "contact" |
55 if type == "contact" |
56 else _("Edit Coil Values"))) |
56 else _("Edit Coil Values"))) |
57 |
57 |
58 # Init common sizers |
58 # Init common sizers |
59 self._init_sizers(2, 0, |
59 self._init_sizers(2, 0, |
60 (7 if type == "contact" else 9), None, 2, 1) |
60 (7 if type == "contact" else 9), None, 2, 1) |
61 |
61 |
62 # Create label for LD element modifier |
62 # Create label for LD element modifier |
63 modifier_label = wx.StaticText(self, label=_('Modifier:')) |
63 modifier_label = wx.StaticText(self, label=_('Modifier:')) |
64 self.LeftGridSizer.AddWindow(modifier_label, border=5, |
64 self.LeftGridSizer.AddWindow(modifier_label, border=5, |
65 flag=wx.GROW|wx.BOTTOM) |
65 flag=wx.GROW|wx.BOTTOM) |
66 |
66 |
67 # Create radio buttons for selecting LD element modifier |
67 # Create radio buttons for selecting LD element modifier |
68 self.ModifierRadioButtons = {} |
68 self.ModifierRadioButtons = {} |
69 first = True |
69 first = True |
70 element_modifiers = ([CONTACT_NORMAL, CONTACT_REVERSE, |
70 element_modifiers = ([CONTACT_NORMAL, CONTACT_REVERSE, |
71 CONTACT_RISING, CONTACT_FALLING] |
71 CONTACT_RISING, CONTACT_FALLING] |
72 if type == "contact" |
72 if type == "contact" |
73 else [COIL_NORMAL, COIL_REVERSE, COIL_SET, |
73 else [COIL_NORMAL, COIL_REVERSE, COIL_SET, |
74 COIL_RESET, COIL_RISING, COIL_FALLING]) |
74 COIL_RESET, COIL_RISING, COIL_FALLING]) |
75 modifiers_label = [_("Normal"), _("Negated")] + \ |
75 modifiers_label = [_("Normal"), _("Negated")] + \ |
76 ([_("Set"), _("Reset")] if type == "coil" else []) + \ |
76 ([_("Set"), _("Reset")] if type == "coil" else []) + \ |
77 [_("Rising Edge"), _("Falling Edge")] |
77 [_("Rising Edge"), _("Falling Edge")] |
78 |
78 |
79 for modifier, label in zip(element_modifiers, modifiers_label): |
79 for modifier, label in zip(element_modifiers, modifiers_label): |
80 radio_button = wx.RadioButton(self, label=label, |
80 radio_button = wx.RadioButton(self, label=label, |
81 style=(wx.RB_GROUP if first else 0)) |
81 style=(wx.RB_GROUP if first else 0)) |
82 radio_button.SetValue(first) |
82 radio_button.SetValue(first) |
83 self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) |
83 self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) |
84 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
84 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
85 self.ModifierRadioButtons[modifier] = radio_button |
85 self.ModifierRadioButtons[modifier] = radio_button |
86 first = False |
86 first = False |
87 |
87 |
88 # Create label for LD element variable |
88 # Create label for LD element variable |
89 element_variable_label = wx.StaticText(self, label=_('Variable:')) |
89 element_variable_label = wx.StaticText(self, label=_('Variable:')) |
90 self.LeftGridSizer.AddWindow(element_variable_label, border=5, |
90 self.LeftGridSizer.AddWindow(element_variable_label, border=5, |
91 flag=wx.GROW|wx.TOP) |
91 flag=wx.GROW|wx.TOP) |
92 |
92 |
93 # Create a combo box for defining LD element variable |
93 # Create a combo box for defining LD element variable |
94 self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT) |
94 self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT) |
95 self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, |
95 self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, |
96 self.ElementVariable) |
96 self.ElementVariable) |
97 self.Bind(wx.EVT_TEXT, self.OnVariableChanged, |
97 self.Bind(wx.EVT_TEXT, self.OnVariableChanged, |
98 self.ElementVariable) |
98 self.ElementVariable) |
99 self.LeftGridSizer.AddWindow(self.ElementVariable, border=5, |
99 self.LeftGridSizer.AddWindow(self.ElementVariable, border=5, |
100 flag=wx.GROW|wx.TOP) |
100 flag=wx.GROW|wx.TOP) |
101 |
101 |
102 # Add preview panel and associated label to sizers |
102 # Add preview panel and associated label to sizers |
103 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
103 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
104 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
104 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
105 |
105 |
106 # Add buttons sizer to sizers |
106 # Add buttons sizer to sizers |
107 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
107 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
108 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
108 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
109 |
109 |
110 # Save LD element class |
110 # Save LD element class |
111 self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) |
111 self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) |
112 |
112 |
113 # Extract list of variables defined in POU |
113 # Extract list of variables defined in POU |
114 self.RefreshVariableList() |
114 self.RefreshVariableList() |
115 |
115 |
116 # Set values in ElementVariable |
116 # Set values in ElementVariable |
117 for name, (var_type, value_type) in self.VariableList.iteritems(): |
117 for name, (var_type, value_type) in self.VariableList.iteritems(): |
118 # Only select BOOL variable and avoid input for coil |
118 # Only select BOOL variable and avoid input for coil |
119 if (type == "contact" or var_type != "Input") and \ |
119 if (type == "contact" or var_type != "Input") and \ |
120 value_type == "BOOL": |
120 value_type == "BOOL": |
121 self.ElementVariable.Append(name) |
121 self.ElementVariable.Append(name) |
122 |
122 |
123 self.Fit() |
123 self.Fit() |
124 # Normal radio button is default control having keyboard focus |
124 # Normal radio button is default control having keyboard focus |
125 self.ModifierRadioButtons[element_modifiers[0]].SetFocus() |
125 self.ModifierRadioButtons[element_modifiers[0]].SetFocus() |
126 |
126 |
127 def GetElementModifier(self): |
127 def GetElementModifier(self): |
128 """ |
128 """ |
129 Return modifier selected for LD element |
129 Return modifier selected for LD element |
130 @return: Modifier selected (None if not found) |
130 @return: Modifier selected (None if not found) |
131 """ |
131 """ |