29 CONTACT_RISING, CONTACT_FALLING, COIL_NORMAL, COIL_REVERSE, COIL_SET, \ |
29 CONTACT_RISING, CONTACT_FALLING, COIL_NORMAL, COIL_REVERSE, COIL_SET, \ |
30 COIL_RESET, COIL_RISING, COIL_FALLING |
30 COIL_RESET, COIL_RISING, COIL_FALLING |
31 from graphics.LD_Objects import LD_Contact, LD_Coil |
31 from graphics.LD_Objects import LD_Contact, LD_Coil |
32 from BlockPreviewDialog import BlockPreviewDialog |
32 from BlockPreviewDialog import BlockPreviewDialog |
33 |
33 |
34 #------------------------------------------------------------------------------- |
34 # ------------------------------------------------------------------------------- |
35 # Set Ladder Element Parmeters Dialog |
35 # Set Ladder Element Parmeters Dialog |
36 #------------------------------------------------------------------------------- |
36 # ------------------------------------------------------------------------------- |
37 |
37 |
38 """ |
|
39 Class that implements a dialog for defining parameters of a LD contact or coil |
|
40 graphic element |
|
41 """ |
|
42 |
38 |
43 class LDElementDialog(BlockPreviewDialog): |
39 class LDElementDialog(BlockPreviewDialog): |
44 |
40 """ |
|
41 Class that implements a dialog for defining parameters of a LD contact or coil |
|
42 graphic element |
|
43 """ |
|
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, (7 if type == "contact" else 9), |
60 (7 if type == "contact" else 9), None, 2, 1) |
60 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 = \ |
76 ([_("Set"), _("Reset")] if type == "coil" else []) + \ |
76 [_("Normal"), _("Negated")] + \ |
77 [_("Rising Edge"), _("Falling Edge")] |
77 ([_("Set"), _("Reset")] if type == "coil" else []) + \ |
78 |
78 [_("Rising Edge"), _("Falling Edge")] |
|
79 |
79 for modifier, label in zip(element_modifiers, modifiers_label): |
80 for modifier, label in zip(element_modifiers, modifiers_label): |
80 radio_button = wx.RadioButton(self, label=label, |
81 radio_button = wx.RadioButton(self, label=label, |
81 style=(wx.RB_GROUP if first else 0)) |
82 style=(wx.RB_GROUP if first else 0)) |
82 radio_button.SetValue(first) |
83 radio_button.SetValue(first) |
83 self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) |
84 self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) |
84 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
85 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
85 self.ModifierRadioButtons[modifier] = radio_button |
86 self.ModifierRadioButtons[modifier] = radio_button |
86 first = False |
87 first = False |
87 |
88 |
88 # Create label for LD element variable |
89 # Create label for LD element variable |
89 element_variable_label = wx.StaticText(self, label=_('Variable:')) |
90 element_variable_label = wx.StaticText(self, label=_('Variable:')) |
90 self.LeftGridSizer.AddWindow(element_variable_label, border=5, |
91 self.LeftGridSizer.AddWindow(element_variable_label, border=5, |
91 flag=wx.GROW|wx.TOP) |
92 flag=wx.GROW | wx.TOP) |
92 |
93 |
93 # Create a combo box for defining LD element variable |
94 # Create a combo box for defining LD element variable |
94 self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT) |
95 self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT) |
95 self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, |
96 self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, |
96 self.ElementVariable) |
97 self.ElementVariable) |
97 self.Bind(wx.EVT_TEXT, self.OnVariableChanged, |
98 self.Bind(wx.EVT_TEXT, self.OnVariableChanged, |
98 self.ElementVariable) |
99 self.ElementVariable) |
99 self.LeftGridSizer.AddWindow(self.ElementVariable, border=5, |
100 self.LeftGridSizer.AddWindow(self.ElementVariable, border=5, |
100 flag=wx.GROW|wx.TOP) |
101 flag=wx.GROW | wx.TOP) |
101 |
102 |
102 # Add preview panel and associated label to sizers |
103 # Add preview panel and associated label to sizers |
103 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
104 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
104 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
105 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
105 |
106 |
106 # Add buttons sizer to sizers |
107 # Add buttons sizer to sizers |
107 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
108 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
108 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
109 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
109 |
110 |
110 # Save LD element class |
111 # Save LD element class |
111 self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) |
112 self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) |
112 |
113 |
113 # Extract list of variables defined in POU |
114 # Extract list of variables defined in POU |
114 self.RefreshVariableList() |
115 self.RefreshVariableList() |
115 |
116 |
116 # Set values in ElementVariable |
117 # Set values in ElementVariable |
117 for name, (var_type, value_type) in self.VariableList.iteritems(): |
118 for name, (var_type, value_type) in self.VariableList.iteritems(): |
118 # Only select BOOL variable and avoid input for coil |
119 # Only select BOOL variable and avoid input for coil |
119 if (type == "contact" or var_type != "Input") and \ |
120 if (type == "contact" or var_type != "Input") and \ |
120 value_type == "BOOL": |
121 value_type == "BOOL": |
121 self.ElementVariable.Append(name) |
122 self.ElementVariable.Append(name) |
122 |
123 |
123 self.Fit() |
124 self.Fit() |
124 # Normal radio button is default control having keyboard focus |
125 # Normal radio button is default control having keyboard focus |
125 self.ModifierRadioButtons[element_modifiers[0]].SetFocus() |
126 self.ModifierRadioButtons[element_modifiers[0]].SetFocus() |
126 |
127 |
127 def GetElementModifier(self): |
128 def GetElementModifier(self): |
128 """ |
129 """ |
129 Return modifier selected for LD element |
130 Return modifier selected for LD element |
130 @return: Modifier selected (None if not found) |
131 @return: Modifier selected (None if not found) |
131 """ |
132 """ |