48 @param connection: True if transition value can be defined by a |
48 @param connection: True if transition value can be defined by a |
49 connection (default: True) |
49 connection (default: True) |
50 """ |
50 """ |
51 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
51 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
52 title=_('Edit transition')) |
52 title=_('Edit transition')) |
53 |
53 |
54 # Init common sizers |
54 # Init common sizers |
55 self._init_sizers(2, 0, 8, None, 2, 1) |
55 self._init_sizers(2, 0, 8, None, 2, 1) |
56 |
56 |
57 # Create label for transition type |
57 # Create label for transition type |
58 type_label = wx.StaticText(self, label=_('Type:')) |
58 type_label = wx.StaticText(self, label=_('Type:')) |
59 self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
59 self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
60 |
60 |
61 # Create combo box for selecting reference value |
61 # Create combo box for selecting reference value |
62 reference = wx.ComboBox(self, style=wx.CB_READONLY) |
62 reference = wx.ComboBox(self, style=wx.CB_READONLY) |
63 reference.Append("") |
63 reference.Append("") |
64 for transition in controller.GetEditedElementTransitions(tagname): |
64 for transition in controller.GetEditedElementTransitions(tagname): |
65 reference.Append(transition) |
65 reference.Append(transition) |
66 self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, reference) |
66 self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, reference) |
67 |
67 |
68 # Create Text control for defining inline value |
68 # Create Text control for defining inline value |
69 inline = wx.TextCtrl(self) |
69 inline = wx.TextCtrl(self) |
70 self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline) |
70 self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline) |
71 |
71 |
72 # Create radio buttons for selecting power rail type |
72 # Create radio buttons for selecting power rail type |
73 self.TypeRadioButtons = {} |
73 self.TypeRadioButtons = {} |
74 first = True |
74 first = True |
75 for type, label, control in [('reference', _('Reference'), reference), |
75 for type, label, control in [('reference', _('Reference'), reference), |
76 ('inline', _('Inline'), inline), |
76 ('inline', _('Inline'), inline), |
77 ('connection', _('Connection'), None)]: |
77 ('connection', _('Connection'), None)]: |
78 radio_button = wx.RadioButton(self, label=label, |
78 radio_button = wx.RadioButton(self, label=label, |
79 style=(wx.RB_GROUP if first else 0)) |
79 style=(wx.RB_GROUP if first else 0)) |
80 radio_button.SetValue(first) |
80 radio_button.SetValue(first) |
81 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
81 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
82 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
82 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
83 if control is not None: |
83 if control is not None: |
84 control.Enable(first) |
84 control.Enable(first) |
85 self.LeftGridSizer.AddWindow(control, flag=wx.GROW) |
85 self.LeftGridSizer.AddWindow(control, flag=wx.GROW) |
86 self.TypeRadioButtons[type] = (radio_button, control) |
86 self.TypeRadioButtons[type] = (radio_button, control) |
87 first = False |
87 first = False |
88 |
88 |
89 # Create label for transition priority |
89 # Create label for transition priority |
90 priority_label = wx.StaticText(self, label=_('Priority:')) |
90 priority_label = wx.StaticText(self, label=_('Priority:')) |
91 self.LeftGridSizer.AddWindow(priority_label, flag=wx.GROW) |
91 self.LeftGridSizer.AddWindow(priority_label, flag=wx.GROW) |
92 |
92 |
93 # Create spin control for defining priority value |
93 # Create spin control for defining priority value |
94 self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
94 self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) |
95 self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority) |
95 self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority) |
96 self.LeftGridSizer.AddWindow(self.Priority, flag=wx.GROW) |
96 self.LeftGridSizer.AddWindow(self.Priority, flag=wx.GROW) |
97 |
97 |
98 # Add preview panel and associated label to sizers |
98 # Add preview panel and associated label to sizers |
99 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
99 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
100 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
100 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
101 |
101 |
102 # Add buttons sizer to sizers |
102 # Add buttons sizer to sizers |
103 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
103 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
104 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
104 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
105 |
105 |
106 self.Fit() |
106 self.Fit() |
107 |
107 |
108 # Reference radio button is default control having keyboard focus |
108 # Reference radio button is default control having keyboard focus |
109 self.TypeRadioButtons["reference"][0].SetFocus() |
109 self.TypeRadioButtons["reference"][0].SetFocus() |
110 |
110 |
111 def GetTransitionType(self): |
111 def GetTransitionType(self): |
112 """ |
112 """ |
113 Return type selected for SFC transition and associated value |
113 Return type selected for SFC transition and associated value |
114 @return: Type selected and associated value (None if no value) |
114 @return: Type selected and associated value (None if no value) |
115 """ |
115 """ |
122 elif isinstance(control, wx.TextCtrl): |
122 elif isinstance(control, wx.TextCtrl): |
123 return type, control.GetValue() |
123 return type, control.GetValue() |
124 else: |
124 else: |
125 return type, None |
125 return type, None |
126 return None, None |
126 return None, None |
127 |
127 |
128 def SetValues(self, values): |
128 def SetValues(self, values): |
129 """ |
129 """ |
130 Set default SFC transition parameters |
130 Set default SFC transition parameters |
131 @param values: Transition parameters values |
131 @param values: Transition parameters values |
132 """ |
132 """ |
133 # Extract transition value according to type |
133 # Extract transition value according to type |
134 type_value = values.get("value", None) |
134 type_value = values.get("value", None) |
135 |
135 |
136 # For each parameters defined, set corresponding control value |
136 # For each parameters defined, set corresponding control value |
137 for name, value in values.items(): |
137 for name, value in values.items(): |
138 |
138 |
139 # Parameter is SFC transition priority |
139 # Parameter is SFC transition priority |
140 if name == "priority": |
140 if name == "priority": |
141 self.Priority.SetValue(values["priority"]) |
141 self.Priority.SetValue(values["priority"]) |
142 |
142 |
143 # Parameter is SFC transition type |
143 # Parameter is SFC transition type |
144 elif name == "type": |
144 elif name == "type": |
145 for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
145 for type, (radio, control) in self.TypeRadioButtons.iteritems(): |
146 radio.SetValue(type == value) |
146 radio.SetValue(type == value) |
147 if control is not None: |
147 if control is not None: |
150 if type == value: |
150 if type == value: |
151 if isinstance(control, wx.ComboBox): |
151 if isinstance(control, wx.ComboBox): |
152 control.SetStringSelection(type_value) |
152 control.SetStringSelection(type_value) |
153 elif isinstance(control, wx.TextCtrl): |
153 elif isinstance(control, wx.TextCtrl): |
154 control.ChangeValue(type_value) |
154 control.ChangeValue(type_value) |
155 |
155 |
156 # Refresh preview panel |
156 # Refresh preview panel |
157 self.RefreshPreview() |
157 self.RefreshPreview() |
158 |
158 |
159 def GetValues(self): |
159 def GetValues(self): |
160 """ |
160 """ |
161 Return SFC transition parameters defined in dialog |
161 Return SFC transition parameters defined in dialog |
162 @return: {parameter_name: parameter_value,...} |
162 @return: {parameter_name: parameter_value,...} |
163 """ |
163 """ |
164 values = {"priority" : self.Priority.GetValue()} |
164 values = {"priority" : self.Priority.GetValue()} |
165 values["type"], values["value"] = self.GetTransitionType() |
165 values["type"], values["value"] = self.GetTransitionType() |
166 values["width"], values["height"] = self.Element.GetSize() |
166 values["width"], values["height"] = self.Element.GetSize() |
167 return values |
167 return values |
168 |
168 |
169 def OnOK(self, event): |
169 def OnOK(self, event): |
170 """ |
170 """ |
171 Called when dialog OK button is pressed |
171 Called when dialog OK button is pressed |
172 Test if parameters defined are valid |
172 Test if parameters defined are valid |
173 @param event: wx.Event from OK button |
173 @param event: wx.Event from OK button |
174 """ |
174 """ |
175 message = None |
175 message = None |
176 |
176 |
177 # Get transition type and value associated |
177 # Get transition type and value associated |
178 type, value = self.GetTransitionType() |
178 type, value = self.GetTransitionType() |
179 |
179 |
180 # Test that value associated to type is defined |
180 # Test that value associated to type is defined |
181 if type != "connection" and value == "": |
181 if type != "connection" and value == "": |
182 message = _("Form isn't complete. %s must be filled!") % type |
182 message = _("Form isn't complete. %s must be filled!") % type |
183 |
183 |
184 # Show error message if an error is detected |
184 # Show error message if an error is detected |
185 if message is not None: |
185 if message is not None: |
186 self.ShowErrorMessage(message) |
186 self.ShowErrorMessage(message) |
187 |
187 |
188 else: |
188 else: |
189 # Call BlockPreviewDialog function |
189 # Call BlockPreviewDialog function |
190 BlockPreviewDialog.OnOK(self, event) |
190 BlockPreviewDialog.OnOK(self, event) |
191 |
191 |
192 def OnTypeChanged(self, event): |
192 def OnTypeChanged(self, event): |