controls/PouInstanceVariablesPanel.py
branch1.1 Korean release
changeset 1384 02fe382c4511
parent 1369 9bd4c783c98d
child 1498 b11045a2f17c
equal deleted inserted replaced
1280:72a826dfcfbb 1384:02fe382c4511
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
       
    25 from collections import namedtuple
       
    26 
    25 import wx
    27 import wx
       
    28 import wx.lib.agw.customtreectrl as CT
    26 import wx.lib.buttons
    29 import wx.lib.buttons
    27 import wx.lib.agw.customtreectrl as CT
    30 
    28 
    31 # Customize CustomTreeItem for adding icon on item right
    29 try:
    32 CT.GenericTreeItem._rightimages = []
    30     import matplotlib
    33 
    31     matplotlib.use('WX')
    34 def SetRightImages(self, images):
    32     USE_MPL = True
    35     self._rightimages = images
    33 except:
    36 CT.GenericTreeItem.SetRightImages = SetRightImages
    34     USE_MPL = False
    37 
       
    38 def GetRightImages(self):
       
    39     return self._rightimages
       
    40 CT.GenericTreeItem.GetRightImages = GetRightImages
       
    41 
       
    42 
       
    43 class CustomTreeCtrlWithRightImage(CT.CustomTreeCtrl):
       
    44 
       
    45     def SetRightImageList(self, imageList):
       
    46         self._imageListRight = imageList
       
    47 
       
    48     def GetLineHeight(self, item):
       
    49         height = CT.CustomTreeCtrl.GetLineHeight(self, item)
       
    50         rightimages = item.GetRightImages()
       
    51         if len(rightimages) > 0:
       
    52             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    53             return max(height, r_image_h + 8)
       
    54         return height
       
    55 
       
    56     def GetItemRightImagesBBox(self, item):
       
    57         rightimages = item.GetRightImages()
       
    58         if len(rightimages) > 0:
       
    59             w, h = self.GetClientSize()
       
    60             total_h = self.GetLineHeight(item)
       
    61             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    62             
       
    63             bbox_width = (r_image_w + 4) * len(rightimages) + 4
       
    64             bbox_height = r_image_h + 8
       
    65             bbox_x = w - bbox_width
       
    66             bbox_y = item.GetY() + ((total_h > r_image_h) and [(total_h-r_image_h)/2] or [0])[0]
       
    67             
       
    68             return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)
       
    69         
       
    70         return None
       
    71 
       
    72     def IsOverItemRightImage(self, item, point):
       
    73         rightimages = item.GetRightImages()
       
    74         if len(rightimages) > 0:
       
    75             point = self.CalcUnscrolledPosition(point)
       
    76             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    77             images_bbx = self.GetItemRightImagesBBox(item)
       
    78             
       
    79             rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
       
    80                            r_image_w, r_image_h)
       
    81             for r_image in rightimages:
       
    82                 if rect.Inside(point):
       
    83                     return r_image
       
    84                 rect.x += r_image_w + 4
       
    85             
       
    86             return None
       
    87                 
       
    88     def PaintItem(self, item, dc, level, align):
       
    89         CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)
       
    90         
       
    91         rightimages = item.GetRightImages()
       
    92         if len(rightimages) > 0:
       
    93             images_bbx = self.GetItemRightImagesBBox(item)
       
    94             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    95             
       
    96             dc.SetBrush(wx.WHITE_BRUSH)
       
    97             dc.SetPen(wx.TRANSPARENT_PEN)
       
    98             
       
    99             bg_width = (r_image_w + 4) * len(rightimages) + 4
       
   100             bg_height = r_image_h + 8
       
   101             dc.DrawRectangle(images_bbx.x, images_bbx.y, 
       
   102                              images_bbx.width, images_bbx.height)
       
   103             x_pos = images_bbx.x + 4
       
   104             for r_image in rightimages:
       
   105                 self._imageListRight.Draw(
       
   106                     r_image, dc, x_pos, images_bbx.y + 4,
       
   107                     wx.IMAGELIST_DRAW_TRANSPARENT)
       
   108                 x_pos += r_image_w + 4
       
   109     
       
   110 _ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
    35 
   111 
    36 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
   112 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
    37 from util.BitmapLibrary import GetBitmap
   113 from util.BitmapLibrary import GetBitmap
    38 
   114 
    39 class PouInstanceVariablesPanel(wx.Panel):
   115 class PouInstanceVariablesPanel(wx.Panel):
    40     
   116 
    41     def __init__(self, parent, window, controller, debug):
   117     def __init__(self, parent, window, controller, debug):
    42         wx.Panel.__init__(self, name='PouInstanceTreePanel', 
   118         wx.Panel.__init__(self, name='PouInstanceTreePanel', 
    43                 parent=parent, pos=wx.Point(0, 0), 
   119                 parent=parent, pos=wx.Point(0, 0), 
    44                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
   120                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
    45         
   121         
    57               bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
   133               bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
    58         self.DebugButton.SetToolTipString(_("Debug instance"))
   134         self.DebugButton.SetToolTipString(_("Debug instance"))
    59         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
   135         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
    60                 self.DebugButton)
   136                 self.DebugButton)
    61         
   137         
    62         self.VariablesList = CT.CustomTreeCtrl(self,
   138         self.VariablesList = CustomTreeCtrlWithRightImage(self,
    63               style=wx.SUNKEN_BORDER,
   139               style=wx.SUNKEN_BORDER,
    64               agwStyle=CT.TR_NO_BUTTONS|
   140               agwStyle=CT.TR_NO_BUTTONS|
    65                        CT.TR_SINGLE|
   141                        CT.TR_SINGLE|
    66                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
   142                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
    67                        CT.TR_HIDE_ROOT|
   143                        CT.TR_HIDE_ROOT|
    73         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
   149         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
    74                 self.OnVariablesListItemActivated)
   150                 self.OnVariablesListItemActivated)
    75         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
   151         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
    76         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
   152         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
    77         
   153         
       
   154         self.TreeRightImageList = wx.ImageList(24, 24)
       
   155         self.EditImage = self.TreeRightImageList.Add(GetBitmap("edit"))
       
   156         self.DebugInstanceImage = self.TreeRightImageList.Add(GetBitmap("debug_instance"))
       
   157         self.VariablesList.SetRightImageList(self.TreeRightImageList)
       
   158         
       
   159         self.ButtonCallBacks = {
       
   160             self.EditImage: _ButtonCallbacks(
       
   161                 self.EditButtonCallback, None),
       
   162             self.DebugInstanceImage: _ButtonCallbacks(
       
   163                 self.DebugButtonCallback, self.DebugButtonDClickCallback)}
       
   164         
    78         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
   165         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
    79         buttons_sizer.AddWindow(self.ParentButton)
   166         buttons_sizer.AddWindow(self.ParentButton)
    80         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
   167         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
    81         buttons_sizer.AddWindow(self.DebugButton)
   168         buttons_sizer.AddWindow(self.DebugButton)
    82         buttons_sizer.AddGrowableCol(1)
   169         buttons_sizer.AddGrowableCol(1)
   145             self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   232             self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   146         else:
   233         else:
   147             self.PouInfos = None
   234             self.PouInfos = None
   148         if self.PouInfos is not None:
   235         if self.PouInfos is not None:
   149             root = self.VariablesList.AddRoot("")
   236             root = self.VariablesList.AddRoot("")
   150             for var_infos in self.PouInfos["variables"]:
   237             for var_infos in self.PouInfos.variables:
   151                 if var_infos.get("type", None) is not None:
   238                 if var_infos.type is not None:
   152                     text = "%(name)s (%(type)s)" % var_infos
   239                     text = "%s (%s)" % (var_infos.name, var_infos.type)
   153                 else:
   240                 else:
   154                     text = var_infos["name"]
   241                     text = var_infos.name
   155                 
   242                 
   156                 panel = wx.Panel(self.VariablesList)
   243                 right_images = []
   157                     
   244                 if var_infos.edit:
   158                 buttons = []
   245                     right_images.append(self.EditImage)
   159                 if var_infos["class"] in ITEMS_VARIABLE:
   246                 
   160                     if (not USE_MPL and var_infos["debug"] and self.Debug and
   247                 if var_infos.debug and self.Debug:
   161                         (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
   248                     right_images.append(self.DebugInstanceImage)
   162                          self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
   249                 
   163                         graph_button = wx.lib.buttons.GenBitmapButton(panel, 
   250                 item = self.VariablesList.AppendItem(root, text)
   164                               bitmap=GetBitmap("instance_graph"), 
   251                 item.SetRightImages(right_images)
   165                               size=wx.Size(28, 28), style=wx.NO_BORDER)
   252                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos.var_class))
   166                         self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
       
   167                         buttons.append(graph_button)
       
   168                 elif var_infos["edit"]:
       
   169                     edit_button = wx.lib.buttons.GenBitmapButton(panel, 
       
   170                           bitmap=GetBitmap("edit"), 
       
   171                           size=wx.Size(28, 28), style=wx.NO_BORDER)
       
   172                     self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
       
   173                     buttons.append(edit_button)
       
   174                 
       
   175                 if var_infos["debug"] and self.Debug:
       
   176                     debug_button = wx.lib.buttons.GenBitmapButton(panel, 
       
   177                           bitmap=GetBitmap("debug_instance"), 
       
   178                           size=wx.Size(28, 28), style=wx.NO_BORDER)
       
   179                     self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
       
   180                     debug_button.Bind(wx.EVT_LEFT_DCLICK, self.GenDebugButtonDClickCallback(var_infos))
       
   181                     buttons.append(debug_button)
       
   182                 
       
   183                 button_num = len(buttons)
       
   184                 if button_num > 0:
       
   185                     panel.SetSize(wx.Size(button_num * 32, 28))
       
   186                     panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
       
   187                     panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
       
   188                     panel.SetSizer(panel_sizer)
       
   189                     
       
   190                     for button in buttons:
       
   191                         panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
       
   192                     panel_sizer.Layout()
       
   193                     
       
   194                 else:
       
   195                     panel.Destroy()
       
   196                     panel = None
       
   197                 
       
   198                 item = self.VariablesList.AppendItem(root, text, wnd=panel)
       
   199                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
       
   200                 self.VariablesList.SetPyData(item, var_infos)
   253                 self.VariablesList.SetPyData(item, var_infos)
   201             
   254             
   202         self.RefreshInstanceChoice()
   255         self.RefreshInstanceChoice()
   203         self.RefreshButtons()
   256         self.RefreshButtons()
   204         
   257         
   211             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   264             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   212             for instance in instances:
   265             for instance in instances:
   213                 self.InstanceChoice.Append(instance)
   266                 self.InstanceChoice.Append(instance)
   214             if len(instances) == 1:
   267             if len(instances) == 1:
   215                 self.PouInstance = instances[0]
   268                 self.PouInstance = instances[0]
   216             if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
   269             if self.PouInfos.var_class in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
   217                 self.PouInstance = None
   270                 self.PouInstance = None
   218                 self.InstanceChoice.SetSelection(0)
   271                 self.InstanceChoice.SetSelection(0)
   219             elif self.PouInstance in instances:
   272             elif self.PouInstance in instances:
   220                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   273                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   221             else:
   274             else:
   222                 self.PouInstance = None
   275                 self.PouInstance = None
   223                 self.InstanceChoice.SetValue(_("Select an instance"))
   276                 self.InstanceChoice.SetValue(_("Select an instance"))
   224     
   277     
   225     def RefreshButtons(self):
   278     def RefreshButtons(self):
   226         enabled = self.InstanceChoice.GetSelection() != -1
   279         enabled = self.InstanceChoice.GetSelection() != -1
   227         self.ParentButton.Enable(enabled and self.PouInfos["class"] != ITEM_CONFIGURATION)
   280         self.ParentButton.Enable(enabled and self.PouInfos.var_class != ITEM_CONFIGURATION)
   228         self.DebugButton.Enable(enabled and self.PouInfos["debug"] and self.Debug)
   281         self.DebugButton.Enable(enabled and self.PouInfos.debug and self.Debug)
   229         
   282         
   230         root = self.VariablesList.GetRootItem()
   283         root = self.VariablesList.GetRootItem()
   231         if root is not None and root.IsOk():
   284         if root is not None and root.IsOk():
   232             item, item_cookie = self.VariablesList.GetFirstChild(root)
   285             item, item_cookie = self.VariablesList.GetFirstChild(root)
   233             while item is not None and item.IsOk():
   286             while item is not None and item.IsOk():
   236                     for child in panel.GetChildren():
   289                     for child in panel.GetChildren():
   237                         if child.GetName() != "edit":
   290                         if child.GetName() != "edit":
   238                             child.Enable(enabled)
   291                             child.Enable(enabled)
   239                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   292                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   240     
   293     
   241     def GenEditButtonCallback(self, infos):
   294     def EditButtonCallback(self, infos):
   242         def EditButtonCallback(event):
   295         var_class = infos.var_class
   243             var_class = infos["class"]
   296         if var_class == ITEM_RESOURCE:
   244             if var_class == ITEM_RESOURCE:
   297             tagname = self.Controller.ComputeConfigurationResourceName(
   245                 tagname = self.Controller.ComputeConfigurationResourceName(
   298                 self.InstanceChoice.GetStringSelection(), 
   246                     self.InstanceChoice.GetStringSelection(), 
   299                 infos.name)
   247                     infos["name"])
   300         elif var_class == ITEM_TRANSITION:
       
   301             tagname = self.Controller.ComputePouTransitionName(
       
   302                 self.PouTagName.split("::")[1],
       
   303                 infos.name)
       
   304         elif var_class == ITEM_ACTION:
       
   305             tagname = self.Controller.ComputePouActionName(
       
   306                 self.PouTagName.split("::")[1],
       
   307                 infos.name)
       
   308         else:
       
   309             var_class = ITEM_POU
       
   310             tagname = self.Controller.ComputePouName(infos.type)
       
   311         self.ParentWindow.EditProjectElement(var_class, tagname)
       
   312     
       
   313     def DebugButtonCallback(self, infos):
       
   314         if self.InstanceChoice.GetSelection() != -1:
       
   315             var_class = infos.var_class
       
   316             var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
       
   317                                   infos.name)
       
   318             if var_class in ITEMS_VARIABLE:
       
   319                 self.ParentWindow.AddDebugVariable(var_path, force=True)
   248             elif var_class == ITEM_TRANSITION:
   320             elif var_class == ITEM_TRANSITION:
   249                 tagname = self.Controller.ComputePouTransitionName(
   321                 self.ParentWindow.OpenDebugViewer(
   250                     self.PouTagName.split("::")[1],
   322                     var_class,
   251                     infos["name"])
   323                     var_path,
       
   324                     self.Controller.ComputePouTransitionName(
       
   325                         self.PouTagName.split("::")[1],
       
   326                         infos.name))
   252             elif var_class == ITEM_ACTION:
   327             elif var_class == ITEM_ACTION:
   253                 tagname = self.Controller.ComputePouActionName(
   328                 self.ParentWindow.OpenDebugViewer(
   254                     self.PouTagName.split("::")[1],
   329                     var_class,
   255                     infos["name"])
   330                     var_path,
       
   331                     self.Controller.ComputePouActionName(
       
   332                         self.PouTagName.split("::")[1],
       
   333                         infos.name))
   256             else:
   334             else:
   257                 var_class = ITEM_POU
   335                 self.ParentWindow.OpenDebugViewer(
   258                 tagname = self.Controller.ComputePouName(infos["type"])
   336                     var_class,
   259             self.ParentWindow.EditProjectElement(var_class, tagname)
   337                     var_path,
   260             event.Skip()
   338                     self.Controller.ComputePouName(infos.type))
   261         return EditButtonCallback
   339     
   262     
   340     def DebugButtonDClickCallback(self, infos):
   263     def GenDebugButtonCallback(self, infos):
   341         if self.InstanceChoice.GetSelection() != -1:
   264         def DebugButtonCallback(event):
   342             if infos.var_class in ITEMS_VARIABLE:
   265             if self.InstanceChoice.GetSelection() != -1:
   343                 self.ParentWindow.AddDebugVariable(
   266                 var_class = infos["class"]
   344                     "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   267                 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   345                                infos.name), 
   268                                       infos["name"])
   346                     force=True,
   269                 if var_class in ITEMS_VARIABLE:
   347                     graph=True)
   270                     self.ParentWindow.AddDebugVariable(var_path, force=True)
       
   271                 elif var_class == ITEM_TRANSITION:
       
   272                     self.ParentWindow.OpenDebugViewer(
       
   273                         var_class,
       
   274                         var_path,
       
   275                         self.Controller.ComputePouTransitionName(
       
   276                             self.PouTagName.split("::")[1],
       
   277                             infos["name"]))
       
   278                 elif var_class == ITEM_ACTION:
       
   279                     self.ParentWindow.OpenDebugViewer(
       
   280                         var_class,
       
   281                         var_path,
       
   282                         self.Controller.ComputePouActionName(
       
   283                             self.PouTagName.split("::")[1],
       
   284                             infos["name"]))
       
   285                 else:
       
   286                     self.ParentWindow.OpenDebugViewer(
       
   287                         var_class,
       
   288                         var_path,
       
   289                         self.Controller.ComputePouName(infos["type"]))
       
   290             event.Skip()
       
   291         return DebugButtonCallback
       
   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     
       
   305     def GenGraphButtonCallback(self, infos):
       
   306         def GraphButtonCallback(event):
       
   307             if self.InstanceChoice.GetSelection() != -1:
       
   308                 if infos["class"] in ITEMS_VARIABLE:
       
   309                     var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
       
   310                                           infos["name"])
       
   311                     self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
       
   312             event.Skip()
       
   313         return GraphButtonCallback
       
   314     
   348     
   315     def ShowInstanceChoicePopup(self):
   349     def ShowInstanceChoicePopup(self):
   316         self.InstanceChoice.SetFocusFromKbd()
   350         self.InstanceChoice.SetFocusFromKbd()
   317         size = self.InstanceChoice.GetSize()
   351         size = self.InstanceChoice.GetSize()
   318         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   352         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   337         event.Skip()
   371         event.Skip()
   338         
   372         
   339     def OnDebugButtonClick(self, event):
   373     def OnDebugButtonClick(self, event):
   340         if self.InstanceChoice.GetSelection() != -1:
   374         if self.InstanceChoice.GetSelection() != -1:
   341             self.ParentWindow.OpenDebugViewer(
   375             self.ParentWindow.OpenDebugViewer(
   342                 self.PouInfos["class"],
   376                 self.PouInfos.var_class,
   343                 self.InstanceChoice.GetStringSelection(),
   377                 self.InstanceChoice.GetStringSelection(),
   344                 self.PouTagName)
   378                 self.PouTagName)
   345         event.Skip()
   379         event.Skip()
   346         
   380     
   347     def OnVariablesListItemActivated(self, event):
   381     def OnVariablesListItemActivated(self, event):
   348         selected_item = event.GetItem()
   382         selected_item = event.GetItem()
   349         if selected_item is not None and selected_item.IsOk():
   383         if selected_item is not None and selected_item.IsOk():
   350             item_infos = self.VariablesList.GetPyData(selected_item)
   384             item_infos = self.VariablesList.GetPyData(selected_item)
   351             if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
   385             if item_infos is not None:
   352                 instance_path = self.InstanceChoice.GetStringSelection()
   386                 
   353                 if item_infos["class"] == ITEM_RESOURCE:
   387                 item_button = self.VariablesList.IsOverItemRightImage(
   354                     if instance_path != "":
   388                     selected_item, event.GetPoint())
   355                         tagname = self.Controller.ComputeConfigurationResourceName(
   389                 if item_button is not None:
   356                                        instance_path, 
   390                     callback = self.ButtonCallBacks[item_button].dclick
   357                                        item_infos["name"])
   391                     if callback is not None:
       
   392                         callback(item_infos)
       
   393                 
       
   394                 elif item_infos.var_class not in ITEMS_VARIABLE:
       
   395                     instance_path = self.InstanceChoice.GetStringSelection()
       
   396                     if item_infos.var_class == ITEM_RESOURCE:
       
   397                         if instance_path != "":
       
   398                             tagname = self.Controller.ComputeConfigurationResourceName(
       
   399                                            instance_path, 
       
   400                                            item_infos.name)
       
   401                         else:
       
   402                             tagname = None
   358                     else:
   403                     else:
   359                         tagname = None
   404                         tagname = self.Controller.ComputePouName(item_infos.type)
   360                 else:
   405                     if tagname is not None:
   361                     tagname = self.Controller.ComputePouName(item_infos["type"])
   406                         if instance_path != "":
   362                 if tagname is not None:
   407                             item_path = "%s.%s" % (instance_path, item_infos.name)
   363                     if instance_path != "":
   408                         else:
   364                         item_path = "%s.%s" % (instance_path, item_infos["name"])
   409                             item_path = None
   365                     else:
   410                         self.SetPouType(tagname, item_path)
   366                         item_path = None
   411                         self.ParentWindow.SelectProjectTreeItem(tagname)
   367                     self.SetPouType(tagname, item_path)
       
   368                     self.ParentWindow.SelectProjectTreeItem(tagname)
       
   369         event.Skip()
   412         event.Skip()
   370     
   413     
   371     def OnVariablesListLeftDown(self, event):
   414     def OnVariablesListLeftDown(self, event):
   372         if self.InstanceChoice.GetSelection() == -1:
   415         if self.InstanceChoice.GetSelection() == -1:
   373             wx.CallAfter(self.ShowInstanceChoicePopup)
   416             wx.CallAfter(self.ShowInstanceChoicePopup)
   374         else:
   417         else:
   375             instance_path = self.InstanceChoice.GetStringSelection()
   418             instance_path = self.InstanceChoice.GetStringSelection()
   376             item, flags = self.VariablesList.HitTest(event.GetPosition())
   419             item, flags = self.VariablesList.HitTest(event.GetPosition())
   377             if item is not None and flags & CT.TREE_HITTEST_ONITEMLABEL:
   420             if item is not None:
   378                 item_infos = self.VariablesList.GetPyData(item)
   421                 item_infos = self.VariablesList.GetPyData(item)
   379                 if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE:
   422                 if item_infos is not None:
   380                     self.ParentWindow.EnsureTabVisible(
   423                     
   381                         self.ParentWindow.DebugVariablePanel)
   424                     item_button = self.VariablesList.IsOverItemRightImage(
   382                     item_path = "%s.%s" % (instance_path, item_infos["name"])
   425                         item, event.GetPosition())
   383                     data = wx.TextDataObject(str((item_path, "debug")))
   426                     if item_button is not None:
   384                     dragSource = wx.DropSource(self.VariablesList)
   427                         callback = self.ButtonCallBacks[item_button].leftdown
   385                     dragSource.SetData(data)
   428                         if callback is not None:
   386                     dragSource.DoDragDrop()
   429                             callback(item_infos)
       
   430                 
       
   431                     elif (flags & CT.TREE_HITTEST_ONITEMLABEL and 
       
   432                           item_infos.var_class in ITEMS_VARIABLE):
       
   433                         self.ParentWindow.EnsureTabVisible(
       
   434                             self.ParentWindow.DebugVariablePanel)
       
   435                         item_path = "%s.%s" % (instance_path, item_infos.name)
       
   436                         data = wx.TextDataObject(str((item_path, "debug")))
       
   437                         dragSource = wx.DropSource(self.VariablesList)
       
   438                         dragSource.SetData(data)
       
   439                         dragSource.DoDragDrop()
   387         event.Skip()
   440         event.Skip()
   388 
   441 
   389     def OnVariablesListKeyDown(self, event):
   442     def OnVariablesListKeyDown(self, event):
   390         keycode = event.GetKeyCode()
   443         keycode = event.GetKeyCode()
   391         if keycode != wx.WXK_LEFT:
   444         if keycode != wx.WXK_LEFT: