242 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug) |
242 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug) |
243 else: |
243 else: |
244 self.PouInfos = None |
244 self.PouInfos = None |
245 if self.PouInfos is not None: |
245 if self.PouInfos is not None: |
246 root = self.VariablesList.AddRoot("") |
246 root = self.VariablesList.AddRoot("") |
247 for var_infos in self.PouInfos["variables"]: |
247 for var_infos in self.PouInfos.variables: |
248 if var_infos.get("type", None) is not None: |
248 if var_infos.type is not None: |
249 text = "%(name)s (%(type)s)" % var_infos |
249 text = "%s (%s)" % (var_infos.name, var_infos.type) |
250 else: |
250 else: |
251 text = var_infos["name"] |
251 text = var_infos.name |
252 |
252 |
253 right_images = [] |
253 right_images = [] |
254 if var_infos["class"] in ITEMS_VARIABLE: |
254 if var_infos.var_class in ITEMS_VARIABLE: |
255 if (not USE_MPL and var_infos["debug"] and self.Debug and |
255 if (not USE_MPL and var_infos.debug and self.Debug and |
256 (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or |
256 (self.Controller.IsOfType(var_infos.type, "ANY_NUM", True) or |
257 self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))): |
257 self.Controller.IsOfType(var_infos.type, "ANY_BIT", True))): |
258 right_images.append(self.InstanceGraphImage) |
258 right_images.append(self.InstanceGraphImage) |
259 elif var_infos["edit"]: |
259 elif var_infos.edit: |
260 right_images.append(self.EditImage) |
260 right_images.append(self.EditImage) |
261 |
261 |
262 if var_infos["debug"] and self.Debug: |
262 if var_infos.debug and self.Debug: |
263 right_images.append(self.DebugInstanceImage) |
263 right_images.append(self.DebugInstanceImage) |
264 |
264 |
265 item = self.VariablesList.AppendItem(root, text) |
265 item = self.VariablesList.AppendItem(root, text) |
266 item.SetRightImages(right_images) |
266 item.SetRightImages(right_images) |
267 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"])) |
267 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos.var_class)) |
268 self.VariablesList.SetPyData(item, var_infos) |
268 self.VariablesList.SetPyData(item, var_infos) |
269 |
269 |
270 self.RefreshInstanceChoice() |
270 self.RefreshInstanceChoice() |
271 self.RefreshButtons() |
271 self.RefreshButtons() |
272 |
272 |
279 instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug) |
279 instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug) |
280 for instance in instances: |
280 for instance in instances: |
281 self.InstanceChoice.Append(instance) |
281 self.InstanceChoice.Append(instance) |
282 if len(instances) == 1: |
282 if len(instances) == 1: |
283 self.PouInstance = instances[0] |
283 self.PouInstance = instances[0] |
284 if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]: |
284 if self.PouInfos.var_class in [ITEM_CONFIGURATION, ITEM_RESOURCE]: |
285 self.PouInstance = None |
285 self.PouInstance = None |
286 self.InstanceChoice.SetSelection(0) |
286 self.InstanceChoice.SetSelection(0) |
287 elif self.PouInstance in instances: |
287 elif self.PouInstance in instances: |
288 self.InstanceChoice.SetStringSelection(self.PouInstance) |
288 self.InstanceChoice.SetStringSelection(self.PouInstance) |
289 else: |
289 else: |
290 self.PouInstance = None |
290 self.PouInstance = None |
291 self.InstanceChoice.SetValue(_("Select an instance")) |
291 self.InstanceChoice.SetValue(_("Select an instance")) |
292 |
292 |
293 def RefreshButtons(self): |
293 def RefreshButtons(self): |
294 enabled = self.InstanceChoice.GetSelection() != -1 |
294 enabled = self.InstanceChoice.GetSelection() != -1 |
295 self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION) |
295 self.ParentButton.Enable(enabled and self.PouInfos.var_class != ITEM_CONFIGURATION) |
296 self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug) |
296 self.DebugButton.Enable(enabled and self.PouInfos.debug and self.Debug) |
297 |
297 |
298 root = self.VariablesList.GetRootItem() |
298 root = self.VariablesList.GetRootItem() |
299 if root is not None and root.IsOk(): |
299 if root is not None and root.IsOk(): |
300 item, item_cookie = self.VariablesList.GetFirstChild(root) |
300 item, item_cookie = self.VariablesList.GetFirstChild(root) |
301 while item is not None and item.IsOk(): |
301 while item is not None and item.IsOk(): |
305 if child.GetName() != "edit": |
305 if child.GetName() != "edit": |
306 child.Enable(enabled) |
306 child.Enable(enabled) |
307 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie) |
307 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie) |
308 |
308 |
309 def EditButtonCallback(self, infos): |
309 def EditButtonCallback(self, infos): |
310 var_class = infos["class"] |
310 var_class = infos.var_class |
311 if var_class == ITEM_RESOURCE: |
311 if var_class == ITEM_RESOURCE: |
312 tagname = self.Controller.ComputeConfigurationResourceName( |
312 tagname = self.Controller.ComputeConfigurationResourceName( |
313 self.InstanceChoice.GetStringSelection(), |
313 self.InstanceChoice.GetStringSelection(), |
314 infos["name"]) |
314 infos.name) |
315 elif var_class == ITEM_TRANSITION: |
315 elif var_class == ITEM_TRANSITION: |
316 tagname = self.Controller.ComputePouTransitionName( |
316 tagname = self.Controller.ComputePouTransitionName( |
317 self.PouTagName.split("::")[1], |
317 self.PouTagName.split("::")[1], |
318 infos["name"]) |
318 infos.name) |
319 elif var_class == ITEM_ACTION: |
319 elif var_class == ITEM_ACTION: |
320 tagname = self.Controller.ComputePouActionName( |
320 tagname = self.Controller.ComputePouActionName( |
321 self.PouTagName.split("::")[1], |
321 self.PouTagName.split("::")[1], |
322 infos["name"]) |
322 infos.name) |
323 else: |
323 else: |
324 var_class = ITEM_POU |
324 var_class = ITEM_POU |
325 tagname = self.Controller.ComputePouName(infos["type"]) |
325 tagname = self.Controller.ComputePouName(infos.type) |
326 self.ParentWindow.EditProjectElement(var_class, tagname) |
326 self.ParentWindow.EditProjectElement(var_class, tagname) |
327 |
327 |
328 def DebugButtonCallback(self, infos): |
328 def DebugButtonCallback(self, infos): |
329 if self.InstanceChoice.GetSelection() != -1: |
329 if self.InstanceChoice.GetSelection() != -1: |
330 var_class = infos["class"] |
330 var_class = infos.var_class |
331 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
331 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
332 infos["name"]) |
332 infos.name) |
333 if var_class in ITEMS_VARIABLE: |
333 if var_class in ITEMS_VARIABLE: |
334 self.ParentWindow.AddDebugVariable(var_path, force=True) |
334 self.ParentWindow.AddDebugVariable(var_path, force=True) |
335 elif var_class == ITEM_TRANSITION: |
335 elif var_class == ITEM_TRANSITION: |
336 self.ParentWindow.OpenDebugViewer( |
336 self.ParentWindow.OpenDebugViewer( |
337 var_class, |
337 var_class, |
338 var_path, |
338 var_path, |
339 self.Controller.ComputePouTransitionName( |
339 self.Controller.ComputePouTransitionName( |
340 self.PouTagName.split("::")[1], |
340 self.PouTagName.split("::")[1], |
341 infos["name"])) |
341 infos.name)) |
342 elif var_class == ITEM_ACTION: |
342 elif var_class == ITEM_ACTION: |
343 self.ParentWindow.OpenDebugViewer( |
343 self.ParentWindow.OpenDebugViewer( |
344 var_class, |
344 var_class, |
345 var_path, |
345 var_path, |
346 self.Controller.ComputePouActionName( |
346 self.Controller.ComputePouActionName( |
347 self.PouTagName.split("::")[1], |
347 self.PouTagName.split("::")[1], |
348 infos["name"])) |
348 infos.name)) |
349 else: |
349 else: |
350 self.ParentWindow.OpenDebugViewer( |
350 self.ParentWindow.OpenDebugViewer( |
351 var_class, |
351 var_class, |
352 var_path, |
352 var_path, |
353 self.Controller.ComputePouName(infos["type"])) |
353 self.Controller.ComputePouName(infos.type)) |
354 |
354 |
355 def DebugButtonDClickCallback(self, infos): |
355 def DebugButtonDClickCallback(self, infos): |
356 if self.InstanceChoice.GetSelection() != -1: |
356 if self.InstanceChoice.GetSelection() != -1: |
357 if infos["class"] in ITEMS_VARIABLE: |
357 if infos.var_class in ITEMS_VARIABLE: |
358 self.ParentWindow.AddDebugVariable( |
358 self.ParentWindow.AddDebugVariable( |
359 "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
359 "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
360 infos["name"]), |
360 infos.name), |
361 force=True, |
361 force=True, |
362 graph=True) |
362 graph=True) |
363 |
363 |
364 def GraphButtonCallback(self, infos): |
364 def GraphButtonCallback(self, infos): |
365 if self.InstanceChoice.GetSelection() != -1: |
365 if self.InstanceChoice.GetSelection() != -1: |
366 if infos["class"] in ITEMS_VARIABLE: |
366 if infos.var_class in ITEMS_VARIABLE: |
367 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
367 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), |
368 infos["name"]) |
368 infos.name) |
369 self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"]) |
369 self.ParentWindow.OpenDebugViewer(infos.var_class, var_path, infos.type) |
370 |
370 |
371 def ShowInstanceChoicePopup(self): |
371 def ShowInstanceChoicePopup(self): |
372 self.InstanceChoice.SetFocusFromKbd() |
372 self.InstanceChoice.SetFocusFromKbd() |
373 size = self.InstanceChoice.GetSize() |
373 size = self.InstanceChoice.GetSize() |
374 event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType()) |
374 event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType()) |
411 if item_button is not None: |
411 if item_button is not None: |
412 callback = self.ButtonCallBacks[item_button].dclick |
412 callback = self.ButtonCallBacks[item_button].dclick |
413 if callback is not None: |
413 if callback is not None: |
414 callback(item_infos) |
414 callback(item_infos) |
415 |
415 |
416 elif item_infos["class"] not in ITEMS_VARIABLE: |
416 elif item_infos.var_class not in ITEMS_VARIABLE: |
417 instance_path = self.InstanceChoice.GetStringSelection() |
417 instance_path = self.InstanceChoice.GetStringSelection() |
418 if item_infos["class"] == ITEM_RESOURCE: |
418 if item_infos.var_class == ITEM_RESOURCE: |
419 if instance_path != "": |
419 if instance_path != "": |
420 tagname = self.Controller.ComputeConfigurationResourceName( |
420 tagname = self.Controller.ComputeConfigurationResourceName( |
421 instance_path, |
421 instance_path, |
422 item_infos["name"]) |
422 item_infos.name) |
423 else: |
423 else: |
424 tagname = None |
424 tagname = None |
425 else: |
425 else: |
426 tagname = self.Controller.ComputePouName(item_infos["type"]) |
426 tagname = self.Controller.ComputePouName(item_infos.type) |
427 if tagname is not None: |
427 if tagname is not None: |
428 if instance_path != "": |
428 if instance_path != "": |
429 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
429 item_path = "%s.%s" % (instance_path, item_infos.name) |
430 else: |
430 else: |
431 item_path = None |
431 item_path = None |
432 self.SetPouType(tagname, item_path) |
432 self.SetPouType(tagname, item_path) |
433 self.ParentWindow.SelectProjectTreeItem(tagname) |
433 self.ParentWindow.SelectProjectTreeItem(tagname) |
434 event.Skip() |
434 event.Skip() |
448 if item_button is not None: |
448 if item_button is not None: |
449 callback = self.ButtonCallBacks[item_button].leftdown |
449 callback = self.ButtonCallBacks[item_button].leftdown |
450 if callback is not None: |
450 if callback is not None: |
451 callback(item_infos) |
451 callback(item_infos) |
452 |
452 |
453 elif flags & CT.TREE_HITTEST_ONITEMLABEL and item_infos["class"] in ITEMS_VARIABLE: |
453 elif flags & CT.TREE_HITTEST_ONITEMLABEL and item_infos.var_class in ITEMS_VARIABLE: |
454 self.ParentWindow.EnsureTabVisible( |
454 self.ParentWindow.EnsureTabVisible( |
455 self.ParentWindow.DebugVariablePanel) |
455 self.ParentWindow.DebugVariablePanel) |
456 item_path = "%s.%s" % (instance_path, item_infos["name"]) |
456 item_path = "%s.%s" % (instance_path, item_infos.name) |
457 data = wx.TextDataObject(str((item_path, "debug"))) |
457 data = wx.TextDataObject(str((item_path, "debug"))) |
458 dragSource = wx.DropSource(self.VariablesList) |
458 dragSource = wx.DropSource(self.VariablesList) |
459 dragSource.SetData(data) |
459 dragSource.SetData(data) |
460 dragSource.DoDragDrop() |
460 dragSource.DoDragDrop() |
461 event.Skip() |
461 event.Skip() |