controls/PouInstanceVariablesPanel.py
changeset 1343 a76a020b8822
parent 1281 47131e3388f4
child 1348 aee0a7eb833a
equal deleted inserted replaced
1342:c17507a10807 1343:a76a020b8822
    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
    26 import wx.lib.agw.customtreectrl as CT
    28 import wx.lib.agw.customtreectrl as CT
    27 
       
    28 import wx.lib.imageutils
       
    29 import wx.lib.buttons
    29 import wx.lib.buttons
    30 GrayedBitmapCache = {}
       
    31 def SetBitmapLabel(self, bitmap, createOthers=True):
       
    32     """
       
    33     Set the bitmap to display normally.
       
    34     This is the only one that is required. If
       
    35     createOthers is True, then the other bitmaps
       
    36     will be generated on the fly.  Currently,
       
    37     only the disabled bitmap is generated.
       
    38     """
       
    39     self.bmpLabel = bitmap
       
    40     if bitmap is not None and createOthers:
       
    41         GrayBitmap=GrayedBitmapCache.get(bitmap,None)
       
    42         if GrayBitmap is None:
       
    43             image = wx.ImageFromBitmap(bitmap)
       
    44             wx.lib.imageutils.grayOut(image)
       
    45             GrayBitmap = wx.BitmapFromImage(image)
       
    46             GrayedBitmapCache[bitmap] = GrayBitmap
       
    47         self.SetBitmapDisabled(GrayBitmap)
       
    48 wx.lib.buttons.GenBitmapButton.SetBitmapLabel = SetBitmapLabel
       
    49 
    30 
    50 try:
    31 try:
    51     import matplotlib
    32     import matplotlib
    52     matplotlib.use('WX')
    33     matplotlib.use('WX')
    53     USE_MPL = True
    34     USE_MPL = True
    54 except:
    35 except:
    55     USE_MPL = False
    36     USE_MPL = False
    56 
    37 
       
    38 # Customize CustomTreeItem for adding icon on item right
       
    39 CT.GenericTreeItem._rightimages = []
       
    40 
       
    41 def SetRightImages(self, images):
       
    42     self._rightimages = images
       
    43 CT.GenericTreeItem.SetRightImages = SetRightImages
       
    44 
       
    45 def GetRightImages(self):
       
    46     return self._rightimages
       
    47 CT.GenericTreeItem.GetRightImages = GetRightImages
       
    48 
       
    49 
       
    50 class CustomTreeCtrlWithRightImage(CT.CustomTreeCtrl):
       
    51 
       
    52     def SetRightImageList(self, imageList):
       
    53         self._imageListRight = imageList
       
    54 
       
    55     def GetLineHeight(self, item):
       
    56         height = CT.CustomTreeCtrl.GetLineHeight(self, item)
       
    57         rightimages = item.GetRightImages()
       
    58         if len(rightimages) > 0:
       
    59             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    60             return max(height, r_image_h + 8)
       
    61         return height
       
    62 
       
    63     def GetItemRightImagesBBox(self, item):
       
    64         rightimages = item.GetRightImages()
       
    65         if len(rightimages) > 0:
       
    66             w, h = self.GetClientSize()
       
    67             total_h = self.GetLineHeight(item)
       
    68             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    69             
       
    70             bbox_width = (r_image_w + 4) * len(rightimages) + 4
       
    71             bbox_height = r_image_h + 8
       
    72             bbox_x = w - bbox_width
       
    73             bbox_y = item.GetY() + ((total_h > r_image_h) and [(total_h-r_image_h)/2] or [0])[0]
       
    74             
       
    75             return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)
       
    76         
       
    77         return None
       
    78 
       
    79     def IsOverItemRightImage(self, item, point):
       
    80         rightimages = item.GetRightImages()
       
    81         if len(rightimages) > 0:
       
    82             point = self.CalcUnscrolledPosition(point)
       
    83             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
    84             images_bbx = self.GetItemRightImagesBBox(item)
       
    85             
       
    86             rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
       
    87                            r_image_w, r_image_h)
       
    88             for r_image in rightimages:
       
    89                 if rect.Inside(point):
       
    90                     return r_image
       
    91                 rect.x += r_image_w + 4
       
    92             
       
    93             return None
       
    94                 
       
    95     def PaintItem(self, item, dc, level, align):
       
    96         CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)
       
    97         
       
    98         rightimages = item.GetRightImages()
       
    99         if len(rightimages) > 0:
       
   100             images_bbx = self.GetItemRightImagesBBox(item)
       
   101             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
       
   102             
       
   103             dc.SetBrush(wx.WHITE_BRUSH)
       
   104             dc.SetPen(wx.TRANSPARENT_PEN)
       
   105             
       
   106             bg_width = (r_image_w + 4) * len(rightimages) + 4
       
   107             bg_height = r_image_h + 8
       
   108             dc.DrawRectangle(images_bbx.x, images_bbx.y, 
       
   109                              images_bbx.width, images_bbx.height)
       
   110             x_pos = images_bbx.x + 4
       
   111             for r_image in rightimages:
       
   112                 self._imageListRight.Draw(
       
   113                     r_image, dc, x_pos, images_bbx.y + 4,
       
   114                     wx.IMAGELIST_DRAW_TRANSPARENT)
       
   115                 x_pos += r_image_w + 4
       
   116     
       
   117 _ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
       
   118 
    57 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
   119 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
    58 from util.BitmapLibrary import GetBitmap
   120 from util.BitmapLibrary import GetBitmap
    59 
   121 
    60 class PouInstanceVariablesPanel(wx.Panel):
   122 class PouInstanceVariablesPanel(wx.Panel):
    61     
   123     
    78               bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
   140               bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
    79         self.DebugButton.SetToolTipString(_("Debug instance"))
   141         self.DebugButton.SetToolTipString(_("Debug instance"))
    80         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
   142         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
    81                 self.DebugButton)
   143                 self.DebugButton)
    82         
   144         
    83         self.VariablesList = CT.CustomTreeCtrl(self,
   145         self.VariablesList = CustomTreeCtrlWithRightImage(self,
    84               style=wx.SUNKEN_BORDER,
   146               style=wx.SUNKEN_BORDER,
    85               agwStyle=CT.TR_NO_BUTTONS|
   147               agwStyle=CT.TR_NO_BUTTONS|
    86                        CT.TR_SINGLE|
   148                        CT.TR_SINGLE|
    87                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
   149                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
    88                        CT.TR_HIDE_ROOT|
   150                        CT.TR_HIDE_ROOT|
    94         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
   156         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
    95                 self.OnVariablesListItemActivated)
   157                 self.OnVariablesListItemActivated)
    96         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
   158         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
    97         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
   159         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
    98         
   160         
       
   161         self.TreeRightImageList = wx.ImageList(24, 24)
       
   162         self.InstanceGraphImage = self.TreeRightImageList.Add(GetBitmap("instance_graph"))
       
   163         self.EditImage = self.TreeRightImageList.Add(GetBitmap("edit"))
       
   164         self.DebugInstanceImage = self.TreeRightImageList.Add(GetBitmap("debug_instance"))
       
   165         self.VariablesList.SetRightImageList(self.TreeRightImageList)
       
   166         
       
   167         self.ButtonCallBacks = {
       
   168             self.InstanceGraphImage: _ButtonCallbacks(
       
   169                 self.GraphButtonCallback, None),
       
   170             self.EditImage: _ButtonCallbacks(
       
   171                 self.EditButtonCallback, None),
       
   172             self.DebugInstanceImage: _ButtonCallbacks(
       
   173                 self.DebugButtonCallback, self.DebugButtonDClickCallback)}
       
   174         
    99         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
   175         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
   100         buttons_sizer.AddWindow(self.ParentButton)
   176         buttons_sizer.AddWindow(self.ParentButton)
   101         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
   177         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
   102         buttons_sizer.AddWindow(self.DebugButton)
   178         buttons_sizer.AddWindow(self.DebugButton)
   103         buttons_sizer.AddGrowableCol(1)
   179         buttons_sizer.AddGrowableCol(1)
   172                 if var_infos.get("type", None) is not None:
   248                 if var_infos.get("type", None) is not None:
   173                     text = "%(name)s (%(type)s)" % var_infos
   249                     text = "%(name)s (%(type)s)" % var_infos
   174                 else:
   250                 else:
   175                     text = var_infos["name"]
   251                     text = var_infos["name"]
   176                 
   252                 
   177                 panel = wx.Panel(self.VariablesList)
   253                 right_images = []
   178                     
       
   179                 buttons = []
       
   180                 if var_infos["class"] in ITEMS_VARIABLE:
   254                 if var_infos["class"] in ITEMS_VARIABLE:
   181                     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
   182                         (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
   256                         (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
   183                          self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
   257                          self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
   184                         graph_button = wx.lib.buttons.GenBitmapButton(panel, 
   258                         right_images.append(self.InstanceGraphImage)
   185                               bitmap=GetBitmap("instance_graph"), 
       
   186                               size=wx.Size(28, 28), style=wx.NO_BORDER)
       
   187                         self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
       
   188                         buttons.append(graph_button)
       
   189                 elif var_infos["edit"]:
   259                 elif var_infos["edit"]:
   190                     edit_button = wx.lib.buttons.GenBitmapButton(panel, 
   260                     right_images.append(self.EditImage)
   191                           bitmap=GetBitmap("edit"), 
       
   192                           size=wx.Size(28, 28), style=wx.NO_BORDER)
       
   193                     self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
       
   194                     buttons.append(edit_button)
       
   195                 
   261                 
   196                 if var_infos["debug"] and self.Debug:
   262                 if var_infos["debug"] and self.Debug:
   197                     debug_button = wx.lib.buttons.GenBitmapButton(panel, 
   263                     right_images.append(self.DebugInstanceImage)
   198                           bitmap=GetBitmap("debug_instance"), 
   264                 
   199                           size=wx.Size(28, 28), style=wx.NO_BORDER)
   265                 item = self.VariablesList.AppendItem(root, text)
   200                     self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
   266                 item.SetRightImages(right_images)
   201                     debug_button.Bind(wx.EVT_LEFT_DCLICK, self.GenDebugButtonDClickCallback(var_infos))
       
   202                     buttons.append(debug_button)
       
   203                 
       
   204                 button_num = len(buttons)
       
   205                 if button_num > 0:
       
   206                     panel.SetSize(wx.Size(button_num * 32, 28))
       
   207                     panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
       
   208                     panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
       
   209                     panel.SetSizer(panel_sizer)
       
   210                     
       
   211                     for button in buttons:
       
   212                         panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
       
   213                     panel_sizer.Layout()
       
   214                     
       
   215                 else:
       
   216                     panel.Destroy()
       
   217                     panel = None
       
   218                 
       
   219                 item = self.VariablesList.AppendItem(root, text, wnd=panel)
       
   220                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
   267                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
   221                 self.VariablesList.SetPyData(item, var_infos)
   268                 self.VariablesList.SetPyData(item, var_infos)
   222             
   269             
   223         self.RefreshInstanceChoice()
   270         self.RefreshInstanceChoice()
   224         self.RefreshButtons()
   271         self.RefreshButtons()
   257                     for child in panel.GetChildren():
   304                     for child in panel.GetChildren():
   258                         if child.GetName() != "edit":
   305                         if child.GetName() != "edit":
   259                             child.Enable(enabled)
   306                             child.Enable(enabled)
   260                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   307                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   261     
   308     
   262     def GenEditButtonCallback(self, infos):
   309     def EditButtonCallback(self, infos):
   263         def EditButtonCallback(event):
   310         var_class = infos["class"]
       
   311         if var_class == ITEM_RESOURCE:
       
   312             tagname = self.Controller.ComputeConfigurationResourceName(
       
   313                 self.InstanceChoice.GetStringSelection(), 
       
   314                 infos["name"])
       
   315         elif var_class == ITEM_TRANSITION:
       
   316             tagname = self.Controller.ComputePouTransitionName(
       
   317                 self.PouTagName.split("::")[1],
       
   318                 infos["name"])
       
   319         elif var_class == ITEM_ACTION:
       
   320             tagname = self.Controller.ComputePouActionName(
       
   321                 self.PouTagName.split("::")[1],
       
   322                 infos["name"])
       
   323         else:
       
   324             var_class = ITEM_POU
       
   325             tagname = self.Controller.ComputePouName(infos["type"])
       
   326         self.ParentWindow.EditProjectElement(var_class, tagname)
       
   327     
       
   328     def DebugButtonCallback(self, infos):
       
   329         if self.InstanceChoice.GetSelection() != -1:
   264             var_class = infos["class"]
   330             var_class = infos["class"]
   265             if var_class == ITEM_RESOURCE:
   331             var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   266                 tagname = self.Controller.ComputeConfigurationResourceName(
   332                                   infos["name"])
   267                     self.InstanceChoice.GetStringSelection(), 
   333             if var_class in ITEMS_VARIABLE:
   268                     infos["name"])
   334                 self.ParentWindow.AddDebugVariable(var_path, force=True)
   269             elif var_class == ITEM_TRANSITION:
   335             elif var_class == ITEM_TRANSITION:
   270                 tagname = self.Controller.ComputePouTransitionName(
   336                 self.ParentWindow.OpenDebugViewer(
   271                     self.PouTagName.split("::")[1],
   337                     var_class,
   272                     infos["name"])
   338                     var_path,
       
   339                     self.Controller.ComputePouTransitionName(
       
   340                         self.PouTagName.split("::")[1],
       
   341                         infos["name"]))
   273             elif var_class == ITEM_ACTION:
   342             elif var_class == ITEM_ACTION:
   274                 tagname = self.Controller.ComputePouActionName(
   343                 self.ParentWindow.OpenDebugViewer(
   275                     self.PouTagName.split("::")[1],
   344                     var_class,
   276                     infos["name"])
   345                     var_path,
       
   346                     self.Controller.ComputePouActionName(
       
   347                         self.PouTagName.split("::")[1],
       
   348                         infos["name"]))
   277             else:
   349             else:
   278                 var_class = ITEM_POU
   350                 self.ParentWindow.OpenDebugViewer(
   279                 tagname = self.Controller.ComputePouName(infos["type"])
   351                     var_class,
   280             self.ParentWindow.EditProjectElement(var_class, tagname)
   352                     var_path,
   281             event.Skip()
   353                     self.Controller.ComputePouName(infos["type"]))
   282         return EditButtonCallback
   354     
   283     
   355     def DebugButtonDClickCallback(self, infos):
   284     def GenDebugButtonCallback(self, infos):
   356         if self.InstanceChoice.GetSelection() != -1:
   285         def DebugButtonCallback(event):
   357             if infos["class"] in ITEMS_VARIABLE:
   286             if self.InstanceChoice.GetSelection() != -1:
   358                 self.ParentWindow.AddDebugVariable(
   287                 var_class = infos["class"]
   359                     "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
       
   360                                infos["name"]), 
       
   361                     force=True,
       
   362                     graph=True)
       
   363     
       
   364     def GraphButtonCallback(self, infos):
       
   365         if self.InstanceChoice.GetSelection() != -1:
       
   366             if infos["class"] in ITEMS_VARIABLE:
   288                 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   367                 var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   289                                       infos["name"])
   368                                       infos["name"])
   290                 if var_class in ITEMS_VARIABLE:
   369                 self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
   291                     self.ParentWindow.AddDebugVariable(var_path, force=True)
       
   292                 elif var_class == ITEM_TRANSITION:
       
   293                     self.ParentWindow.OpenDebugViewer(
       
   294                         var_class,
       
   295                         var_path,
       
   296                         self.Controller.ComputePouTransitionName(
       
   297                             self.PouTagName.split("::")[1],
       
   298                             infos["name"]))
       
   299                 elif var_class == ITEM_ACTION:
       
   300                     self.ParentWindow.OpenDebugViewer(
       
   301                         var_class,
       
   302                         var_path,
       
   303                         self.Controller.ComputePouActionName(
       
   304                             self.PouTagName.split("::")[1],
       
   305                             infos["name"]))
       
   306                 else:
       
   307                     self.ParentWindow.OpenDebugViewer(
       
   308                         var_class,
       
   309                         var_path,
       
   310                         self.Controller.ComputePouName(infos["type"]))
       
   311             event.Skip()
       
   312         return DebugButtonCallback
       
   313     
       
   314     def GenDebugButtonDClickCallback(self, infos):
       
   315         def DebugButtonDClickCallback(event):
       
   316             if self.InstanceChoice.GetSelection() != -1:
       
   317                 if infos["class"] in ITEMS_VARIABLE:
       
   318                     self.ParentWindow.AddDebugVariable(
       
   319                         "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
       
   320                                    infos["name"]), 
       
   321                         force=True,
       
   322                         graph=True)
       
   323             event.Skip()
       
   324         return DebugButtonDClickCallback
       
   325     
       
   326     def GenGraphButtonCallback(self, infos):
       
   327         def GraphButtonCallback(event):
       
   328             if self.InstanceChoice.GetSelection() != -1:
       
   329                 if infos["class"] in ITEMS_VARIABLE:
       
   330                     var_path = "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
       
   331                                           infos["name"])
       
   332                     self.ParentWindow.OpenDebugViewer(infos["class"], var_path, infos["type"])
       
   333             event.Skip()
       
   334         return GraphButtonCallback
       
   335     
   370     
   336     def ShowInstanceChoicePopup(self):
   371     def ShowInstanceChoicePopup(self):
   337         self.InstanceChoice.SetFocusFromKbd()
   372         self.InstanceChoice.SetFocusFromKbd()
   338         size = self.InstanceChoice.GetSize()
   373         size = self.InstanceChoice.GetSize()
   339         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   374         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   362             self.ParentWindow.OpenDebugViewer(
   397             self.ParentWindow.OpenDebugViewer(
   363                 self.PouInfos["class"],
   398                 self.PouInfos["class"],
   364                 self.InstanceChoice.GetStringSelection(),
   399                 self.InstanceChoice.GetStringSelection(),
   365                 self.PouTagName)
   400                 self.PouTagName)
   366         event.Skip()
   401         event.Skip()
   367         
   402     
   368     def OnVariablesListItemActivated(self, event):
   403     def OnVariablesListItemActivated(self, event):
   369         selected_item = event.GetItem()
   404         selected_item = event.GetItem()
   370         if selected_item is not None and selected_item.IsOk():
   405         if selected_item is not None and selected_item.IsOk():
   371             item_infos = self.VariablesList.GetPyData(selected_item)
   406             item_infos = self.VariablesList.GetPyData(selected_item)
   372             if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
   407             if item_infos is not None:
   373                 instance_path = self.InstanceChoice.GetStringSelection()
   408                 
   374                 if item_infos["class"] == ITEM_RESOURCE:
   409                 item_button = self.VariablesList.IsOverItemRightImage(
   375                     if instance_path != "":
   410                     selected_item, event.GetPoint())
   376                         tagname = self.Controller.ComputeConfigurationResourceName(
   411                 if item_button is not None:
   377                                        instance_path, 
   412                     callback = self.ButtonCallBacks[item_button].dclick
   378                                        item_infos["name"])
   413                     if callback is not None:
       
   414                         callback(item_infos)
       
   415                 
       
   416                 elif item_infos["class"] not in ITEMS_VARIABLE:
       
   417                     instance_path = self.InstanceChoice.GetStringSelection()
       
   418                     if item_infos["class"] == ITEM_RESOURCE:
       
   419                         if instance_path != "":
       
   420                             tagname = self.Controller.ComputeConfigurationResourceName(
       
   421                                            instance_path, 
       
   422                                            item_infos["name"])
       
   423                         else:
       
   424                             tagname = None
   379                     else:
   425                     else:
   380                         tagname = None
   426                         tagname = self.Controller.ComputePouName(item_infos["type"])
   381                 else:
   427                     if tagname is not None:
   382                     tagname = self.Controller.ComputePouName(item_infos["type"])
   428                         if instance_path != "":
   383                 if tagname is not None:
   429                             item_path = "%s.%s" % (instance_path, item_infos["name"])
   384                     if instance_path != "":
   430                         else:
   385                         item_path = "%s.%s" % (instance_path, item_infos["name"])
   431                             item_path = None
   386                     else:
   432                         self.SetPouType(tagname, item_path)
   387                         item_path = None
   433                         self.ParentWindow.SelectProjectTreeItem(tagname)
   388                     self.SetPouType(tagname, item_path)
       
   389                     self.ParentWindow.SelectProjectTreeItem(tagname)
       
   390         event.Skip()
   434         event.Skip()
   391     
   435     
   392     def OnVariablesListLeftDown(self, event):
   436     def OnVariablesListLeftDown(self, event):
   393         if self.InstanceChoice.GetSelection() == -1:
   437         if self.InstanceChoice.GetSelection() == -1:
   394             wx.CallAfter(self.ShowInstanceChoicePopup)
   438             wx.CallAfter(self.ShowInstanceChoicePopup)
   395         else:
   439         else:
   396             instance_path = self.InstanceChoice.GetStringSelection()
   440             instance_path = self.InstanceChoice.GetStringSelection()
   397             item, flags = self.VariablesList.HitTest(event.GetPosition())
   441             item, flags = self.VariablesList.HitTest(event.GetPosition())
   398             if item is not None and flags & CT.TREE_HITTEST_ONITEMLABEL:
   442             if item is not None:
   399                 item_infos = self.VariablesList.GetPyData(item)
   443                 item_infos = self.VariablesList.GetPyData(item)
   400                 if item_infos is not None and item_infos["class"] in ITEMS_VARIABLE:
   444                 if item_infos is not None:
       
   445                     
       
   446                     item_button = self.VariablesList.IsOverItemRightImage(
       
   447                         item, event.GetPosition())
       
   448                     if item_button is not None:
       
   449                         callback = self.ButtonCallBacks[item_button].leftdown
       
   450                         if callback is not None:
       
   451                             callback(item_infos)
       
   452                 
       
   453                 elif flags & CT.TREE_HITTEST_ONITEMLABEL and item_infos["class"] in ITEMS_VARIABLE:
   401                     self.ParentWindow.EnsureTabVisible(
   454                     self.ParentWindow.EnsureTabVisible(
   402                         self.ParentWindow.DebugVariablePanel)
   455                         self.ParentWindow.DebugVariablePanel)
   403                     item_path = "%s.%s" % (instance_path, item_infos["name"])
   456                     item_path = "%s.%s" % (instance_path, item_infos["name"])
   404                     data = wx.TextDataObject(str((item_path, "debug")))
   457                     data = wx.TextDataObject(str((item_path, "debug")))
   405                     dragSource = wx.DropSource(self.VariablesList)
   458                     dragSource = wx.DropSource(self.VariablesList)