50 self.ParentButton) |
50 self.ParentButton) |
51 |
51 |
52 self.InstanceChoice = wx.ComboBox(self, size=wx.Size(0, 0), style=wx.CB_READONLY) |
52 self.InstanceChoice = wx.ComboBox(self, size=wx.Size(0, 0), style=wx.CB_READONLY) |
53 self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged, |
53 self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged, |
54 self.InstanceChoice) |
54 self.InstanceChoice) |
55 self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown) |
|
56 |
55 |
57 self.DebugButton = wx.lib.buttons.GenBitmapButton(self, |
56 self.DebugButton = wx.lib.buttons.GenBitmapButton(self, |
58 bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER) |
57 bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER) |
59 self.ParentButton.SetToolTipString(_("Debug instance")) |
58 self.DebugButton.SetToolTipString(_("Debug instance")) |
60 self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, |
59 self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, |
61 self.DebugButton) |
60 self.DebugButton) |
62 |
61 |
63 self.VariablesList = CT.CustomTreeCtrl(self, |
62 self.VariablesList = CT.CustomTreeCtrl(self, |
64 style=wx.SUNKEN_BORDER, |
63 style=wx.SUNKEN_BORDER, |
72 self.VariablesList.SetSpacing(5) |
71 self.VariablesList.SetSpacing(5) |
73 self.VariablesList.DoSelectItem = lambda *x,**y:True |
72 self.VariablesList.DoSelectItem = lambda *x,**y:True |
74 self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED, |
73 self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED, |
75 self.OnVariablesListItemActivated) |
74 self.OnVariablesListItemActivated) |
76 self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown) |
75 self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown) |
|
76 self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown) |
77 |
77 |
78 buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0) |
78 buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0) |
79 buttons_sizer.AddWindow(self.ParentButton) |
79 buttons_sizer.AddWindow(self.ParentButton) |
80 buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW) |
80 buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW) |
81 buttons_sizer.AddWindow(self.DebugButton) |
81 buttons_sizer.AddWindow(self.DebugButton) |
110 self.Controller = controller |
110 self.Controller = controller |
111 |
111 |
112 self.RefreshView() |
112 self.RefreshView() |
113 |
113 |
114 def SetPouType(self, tagname, pou_instance=None): |
114 def SetPouType(self, tagname, pou_instance=None): |
115 if self.Controller is not None: |
115 if self.Controller is not None: |
116 self.PouTagName = tagname |
116 if tagname == "Project": |
117 if self.PouTagName == "Project": |
|
118 config_name = self.Controller.GetProjectMainConfigurationName() |
117 config_name = self.Controller.GetProjectMainConfigurationName() |
119 if config_name is not None: |
118 if config_name is not None: |
120 self.PouTagName = self.Controller.ComputeConfigurationName(config_name) |
119 tagname = self.Controller.ComputeConfigurationName(config_name) |
121 if pou_instance is not None: |
120 if pou_instance is not None: |
122 self.PouInstance = pou_instance |
121 self.PouInstance = pou_instance |
123 |
122 |
124 self.RefreshView() |
123 if self.PouTagName != tagname: |
|
124 self.PouTagName = tagname |
|
125 self.RefreshView() |
|
126 else: |
|
127 self.RefreshInstanceChoice() |
|
128 else: |
|
129 self.RefreshView() |
125 |
130 |
126 def ResetView(self): |
131 def ResetView(self): |
127 self.Controller = None |
132 self.Controller = None |
128 |
133 |
129 self.PouTagName = None |
134 self.PouTagName = None |
131 self.PouInstance = None |
136 self.PouInstance = None |
132 |
137 |
133 self.RefreshView() |
138 self.RefreshView() |
134 |
139 |
135 def RefreshView(self): |
140 def RefreshView(self): |
|
141 self.Freeze() |
136 self.VariablesList.DeleteAllItems() |
142 self.VariablesList.DeleteAllItems() |
137 self.InstanceChoice.Clear() |
|
138 self.InstanceChoice.SetValue("") |
|
139 |
143 |
140 if self.Controller is not None and self.PouTagName is not None: |
144 if self.Controller is not None and self.PouTagName is not None: |
141 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug) |
145 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug) |
142 else: |
146 else: |
143 self.PouInfos = None |
147 self.PouInfos = None |
171 if var_infos["debug"] and self.Debug: |
175 if var_infos["debug"] and self.Debug: |
172 debug_button = wx.lib.buttons.GenBitmapButton(panel, |
176 debug_button = wx.lib.buttons.GenBitmapButton(panel, |
173 bitmap=GetBitmap("debug_instance"), |
177 bitmap=GetBitmap("debug_instance"), |
174 size=wx.Size(28, 28), style=wx.NO_BORDER) |
178 size=wx.Size(28, 28), style=wx.NO_BORDER) |
175 self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button) |
179 self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button) |
|
180 debug_button.Bind(wx.EVT_LEFT_DCLICK, self.GenDebugButtonDClickCallback(var_infos)) |
176 buttons.append(debug_button) |
181 buttons.append(debug_button) |
177 |
182 |
178 button_num = len(buttons) |
183 button_num = len(buttons) |
179 if button_num > 0: |
184 if button_num > 0: |
180 panel.SetSize(wx.Size(button_num * 32, 28)) |
185 panel.SetSize(wx.Size(button_num * 32, 28)) |
192 |
197 |
193 item = self.VariablesList.AppendItem(root, text, wnd=panel) |
198 item = self.VariablesList.AppendItem(root, text, wnd=panel) |
194 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"])) |
199 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"])) |
195 self.VariablesList.SetPyData(item, var_infos) |
200 self.VariablesList.SetPyData(item, var_infos) |
196 |
201 |
|
202 self.RefreshInstanceChoice() |
|
203 self.RefreshButtons() |
|
204 |
|
205 self.Thaw() |
|
206 |
|
207 def RefreshInstanceChoice(self): |
|
208 self.InstanceChoice.Clear() |
|
209 self.InstanceChoice.SetValue("") |
|
210 if self.Controller is not None and self.PouInfos is not None: |
197 instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug) |
211 instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug) |
198 for instance in instances: |
212 for instance in instances: |
199 self.InstanceChoice.Append(instance) |
213 self.InstanceChoice.Append(instance) |
200 if len(instances) == 1: |
214 if len(instances) == 1: |
201 self.PouInstance = instances[0] |
215 self.PouInstance = instances[0] |
205 elif self.PouInstance in instances: |
219 elif self.PouInstance in instances: |
206 self.InstanceChoice.SetStringSelection(self.PouInstance) |
220 self.InstanceChoice.SetStringSelection(self.PouInstance) |
207 else: |
221 else: |
208 self.PouInstance = None |
222 self.PouInstance = None |
209 self.InstanceChoice.SetValue(_("Select an instance")) |
223 self.InstanceChoice.SetValue(_("Select an instance")) |
210 |
224 |
211 self.RefreshButtons() |
|
212 |
|
213 def RefreshButtons(self): |
225 def RefreshButtons(self): |
214 enabled = self.InstanceChoice.GetSelection() != -1 |
226 enabled = self.InstanceChoice.GetSelection() != -1 |
215 self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION) |
227 self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION) |
216 self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug) |
228 self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug) |
217 |
229 |
276 var_path, |
288 var_path, |
277 self.Controller.ComputePouName(infos["type"])) |
289 self.Controller.ComputePouName(infos["type"])) |
278 event.Skip() |
290 event.Skip() |
279 return DebugButtonCallback |
291 return DebugButtonCallback |
280 |
292 |
|
293 def GenDebugButtonDClickCallback(self, infos): |
|
294 def DebugButtonDClickCallback(event): |
|
295 if self.InstanceChoice.GetSelection() != -1: |
|
296 if infos["class"] in ITEMS_VARIABLE: |
|
297 self.ParentWindow.AddDebugVariable( |
|
298 "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
|
299 infos["name"]), |
|
300 force=True, |
|
301 graph=True) |
|
302 event.Skip() |
|
303 return DebugButtonDClickCallback |
|
304 |
281 def GenGraphButtonCallback(self, infos): |
305 def GenGraphButtonCallback(self, infos): |
282 def GraphButtonCallback(event): |
306 def GraphButtonCallback(event): |
283 if self.InstanceChoice.GetSelection() != -1: |
307 if self.InstanceChoice.GetSelection() != -1: |
284 if infos["class"] in ITEMS_VARIABLE: |
308 if infos["class"] in ITEMS_VARIABLE: |
285 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
309 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
319 self.InstanceChoice.GetStringSelection(), |
343 self.InstanceChoice.GetStringSelection(), |
320 self.PouTagName) |
344 self.PouTagName) |
321 event.Skip() |
345 event.Skip() |
322 |
346 |
323 def OnVariablesListItemActivated(self, event): |
347 def OnVariablesListItemActivated(self, event): |
324 if self.InstanceChoice.GetSelection() != -1: |
348 selected_item = event.GetItem() |
325 instance_path = self.InstanceChoice.GetStringSelection() |
349 if selected_item is not None and selected_item.IsOk(): |
326 selected_item = event.GetItem() |
350 item_infos = self.VariablesList.GetPyData(selected_item) |
327 if selected_item is not None and selected_item.IsOk(): |
351 if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE: |
328 item_infos = self.VariablesList.GetPyData(selected_item) |
352 instance_path = self.InstanceChoice.GetStringSelection() |
329 if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE: |
353 if item_infos["class"] == ITEM_RESOURCE: |
330 if item_infos["class"] == ITEM_RESOURCE: |
354 if instance_path != "": |
331 tagname = self.Controller.ComputeConfigurationResourceName( |
355 tagname = self.Controller.ComputeConfigurationResourceName( |
332 instance_path, |
356 instance_path, |
333 item_infos["name"]) |
357 item_infos["name"]) |
334 else: |
358 else: |
335 tagname = self.Controller.ComputePouName(item_infos["type"]) |
359 tagname = None |
336 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
360 else: |
337 wx.CallAfter(self.SetPouType, tagname, item_path) |
361 tagname = self.Controller.ComputePouName(item_infos["type"]) |
338 wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname) |
362 if tagname is not None: |
|
363 if instance_path != "": |
|
364 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
|
365 else: |
|
366 item_path = None |
|
367 self.SetPouType(tagname, item_path) |
|
368 self.ParentWindow.SelectProjectTreeItem(tagname) |
339 event.Skip() |
369 event.Skip() |
340 |
370 |
341 def OnVariablesListLeftDown(self, event): |
371 def OnVariablesListLeftDown(self, event): |
342 if self.InstanceChoice.GetSelection() == -1: |
372 if self.InstanceChoice.GetSelection() == -1: |
343 wx.CallAfter(self.ShowInstanceChoicePopup) |
373 wx.CallAfter(self.ShowInstanceChoicePopup) |
345 instance_path = self.InstanceChoice.GetStringSelection() |
375 instance_path = self.InstanceChoice.GetStringSelection() |
346 item, flags = self.VariablesList.HitTest(event.GetPosition()) |
376 item, flags = self.VariablesList.HitTest(event.GetPosition()) |
347 if item is not None and flags & CT.TREE_HITTEST_ONITEMLABEL: |
377 if item is not None and flags & CT.TREE_HITTEST_ONITEMLABEL: |
348 item_infos = self.VariablesList.GetPyData(item) |
378 item_infos = self.VariablesList.GetPyData(item) |
349 if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE: |
379 if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE: |
|
380 self.ParentWindow.EnsureTabVisible( |
|
381 self.ParentWindow.DebugVariablePanel) |
350 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
382 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
351 data = wx.TextDataObject(str((item_path, "debug"))) |
383 data = wx.TextDataObject(str((item_path, "debug"))) |
352 dragSource = wx.DropSource(self.VariablesList) |
384 dragSource = wx.DropSource(self.VariablesList) |
353 dragSource.SetData(data) |
385 dragSource.SetData(data) |
354 dragSource.DoDragDrop() |
386 dragSource.DoDragDrop() |
355 event.Skip() |
387 event.Skip() |
356 |
388 |
357 def OnInstanceChoiceLeftDown(self, event): |
389 def OnVariablesListKeyDown(self, event): |
358 event.Skip() |
390 keycode = event.GetKeyCode() |
|
391 if keycode != wx.WXK_LEFT: |
|
392 event.Skip() |
|
393 |