controls/PouInstanceVariablesPanel.py
changeset 1730 64d8f52bc8c8
parent 1669 54da2cfe0180
child 1736 7e61baa047f0
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    57         rightimages = item.GetRightImages()
    57         rightimages = item.GetRightImages()
    58         if len(rightimages) > 0:
    58         if len(rightimages) > 0:
    59             w, h = self.GetClientSize()
    59             w, h = self.GetClientSize()
    60             total_h = self.GetLineHeight(item)
    60             total_h = self.GetLineHeight(item)
    61             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    61             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    62             
    62 
    63             bbox_width = (r_image_w + 4) * len(rightimages) + 4
    63             bbox_width = (r_image_w + 4) * len(rightimages) + 4
    64             bbox_height = r_image_h + 8
    64             bbox_height = r_image_h + 8
    65             bbox_x = w - bbox_width
    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]
    66             bbox_y = item.GetY() + ((total_h > r_image_h) and [(total_h-r_image_h)/2] or [0])[0]
    67             
    67 
    68             return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)
    68             return wx.Rect(bbox_x, bbox_y, bbox_width, bbox_height)
    69         
    69 
    70         return None
    70         return None
    71 
    71 
    72     def IsOverItemRightImage(self, item, point):
    72     def IsOverItemRightImage(self, item, point):
    73         rightimages = item.GetRightImages()
    73         rightimages = item.GetRightImages()
    74         if len(rightimages) > 0:
    74         if len(rightimages) > 0:
    75             point = self.CalcUnscrolledPosition(point)
    75             point = self.CalcUnscrolledPosition(point)
    76             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    76             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    77             images_bbx = self.GetItemRightImagesBBox(item)
    77             images_bbx = self.GetItemRightImagesBBox(item)
    78             
    78 
    79             rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
    79             rect = wx.Rect(images_bbx.x + 4, images_bbx.y + 4,
    80                            r_image_w, r_image_h)
    80                            r_image_w, r_image_h)
    81             for r_image in rightimages:
    81             for r_image in rightimages:
    82                 if rect.Inside(point):
    82                 if rect.Inside(point):
    83                     return r_image
    83                     return r_image
    84                 rect.x += r_image_w + 4
    84                 rect.x += r_image_w + 4
    85             
    85 
    86             return None
    86             return None
    87                 
    87 
    88     def PaintItem(self, item, dc, level, align):
    88     def PaintItem(self, item, dc, level, align):
    89         CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)
    89         CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)
    90         
    90 
    91         rightimages = item.GetRightImages()
    91         rightimages = item.GetRightImages()
    92         if len(rightimages) > 0:
    92         if len(rightimages) > 0:
    93             images_bbx = self.GetItemRightImagesBBox(item)
    93             images_bbx = self.GetItemRightImagesBBox(item)
    94             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    94             r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])
    95             
    95 
    96             dc.SetBrush(wx.TRANSPARENT_BRUSH)
    96             dc.SetBrush(wx.TRANSPARENT_BRUSH)
    97             dc.SetPen(wx.TRANSPARENT_PEN)
    97             dc.SetPen(wx.TRANSPARENT_PEN)
    98             
    98 
    99             bg_width = (r_image_w + 4) * len(rightimages) + 4
    99             bg_width = (r_image_w + 4) * len(rightimages) + 4
   100             bg_height = r_image_h + 8
   100             bg_height = r_image_h + 8
   101             dc.DrawRectangle(images_bbx.x, images_bbx.y, 
   101             dc.DrawRectangle(images_bbx.x, images_bbx.y,
   102                              images_bbx.width, images_bbx.height)
   102                              images_bbx.width, images_bbx.height)
   103             x_pos = images_bbx.x + 4
   103             x_pos = images_bbx.x + 4
   104             for r_image in rightimages:
   104             for r_image in rightimages:
   105                 self._imageListRight.Draw(
   105                 self._imageListRight.Draw(
   106                     r_image, dc, x_pos, images_bbx.y + 4,
   106                     r_image, dc, x_pos, images_bbx.y + 4,
   107                     wx.IMAGELIST_DRAW_TRANSPARENT)
   107                     wx.IMAGELIST_DRAW_TRANSPARENT)
   108                 x_pos += r_image_w + 4
   108                 x_pos += r_image_w + 4
   109     
   109 
   110 _ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
   110 _ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
   111 
   111 
   112 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
   113 from util.BitmapLibrary import GetBitmap
   113 from util.BitmapLibrary import GetBitmap
   114 
   114 
   115 class PouInstanceVariablesPanel(wx.Panel):
   115 class PouInstanceVariablesPanel(wx.Panel):
   116 
   116 
   117     def __init__(self, parent, window, controller, debug):
   117     def __init__(self, parent, window, controller, debug):
   118         wx.Panel.__init__(self, name='PouInstanceTreePanel', 
   118         wx.Panel.__init__(self, name='PouInstanceTreePanel',
   119                 parent=parent, pos=wx.Point(0, 0), 
   119                 parent=parent, pos=wx.Point(0, 0),
   120                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
   120                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
   121         
   121 
   122         self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
   122         self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
   123               bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
   123               bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
   124         self.ParentButton.SetToolTipString(_("Parent instance"))
   124         self.ParentButton.SetToolTipString(_("Parent instance"))
   125         self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
   125         self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick,
   126                 self.ParentButton)
   126                 self.ParentButton)
   127         
   127 
   128         self.InstanceChoice = wx.ComboBox(self, size=wx.Size(0, 0), style=wx.CB_READONLY)
   128         self.InstanceChoice = wx.ComboBox(self, size=wx.Size(0, 0), style=wx.CB_READONLY)
   129         self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
   129         self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
   130                 self.InstanceChoice)
   130                 self.InstanceChoice)
   131         
   131 
   132         self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
   132         self.DebugButton = wx.lib.buttons.GenBitmapButton(self,
   133               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)
   134         self.DebugButton.SetToolTipString(_("Debug instance"))
   134         self.DebugButton.SetToolTipString(_("Debug instance"))
   135         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
   135         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick,
   136                 self.DebugButton)
   136                 self.DebugButton)
   137         
   137 
   138         self.VariablesList = CustomTreeCtrlWithRightImage(self,
   138         self.VariablesList = CustomTreeCtrlWithRightImage(self,
   139               style=wx.SUNKEN_BORDER,
   139               style=wx.SUNKEN_BORDER,
   140               agwStyle=CT.TR_NO_BUTTONS|
   140               agwStyle=CT.TR_NO_BUTTONS|
   141                        CT.TR_SINGLE|
   141                        CT.TR_SINGLE|
   142                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
   142                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
   148         self.VariablesList.DoSelectItem = lambda *x,**y:True
   148         self.VariablesList.DoSelectItem = lambda *x,**y:True
   149         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
   149         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
   150                 self.OnVariablesListItemActivated)
   150                 self.OnVariablesListItemActivated)
   151         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
   151         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
   152         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
   152         self.VariablesList.Bind(wx.EVT_KEY_DOWN, self.OnVariablesListKeyDown)
   153         
   153 
   154         self.TreeRightImageList = wx.ImageList(24, 24)
   154         self.TreeRightImageList = wx.ImageList(24, 24)
   155         self.EditImage = self.TreeRightImageList.Add(GetBitmap("edit"))
   155         self.EditImage = self.TreeRightImageList.Add(GetBitmap("edit"))
   156         self.DebugInstanceImage = self.TreeRightImageList.Add(GetBitmap("debug_instance"))
   156         self.DebugInstanceImage = self.TreeRightImageList.Add(GetBitmap("debug_instance"))
   157         self.VariablesList.SetRightImageList(self.TreeRightImageList)
   157         self.VariablesList.SetRightImageList(self.TreeRightImageList)
   158         
   158 
   159         self.ButtonCallBacks = {
   159         self.ButtonCallBacks = {
   160             self.EditImage: _ButtonCallbacks(
   160             self.EditImage: _ButtonCallbacks(
   161                 self.EditButtonCallback, None),
   161                 self.EditButtonCallback, None),
   162             self.DebugInstanceImage: _ButtonCallbacks(
   162             self.DebugInstanceImage: _ButtonCallbacks(
   163                 self.DebugButtonCallback, self.DebugButtonDClickCallback)}
   163                 self.DebugButtonCallback, self.DebugButtonDClickCallback)}
   164         
   164 
   165         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)
   166         buttons_sizer.AddWindow(self.ParentButton)
   166         buttons_sizer.AddWindow(self.ParentButton)
   167         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
   167         buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
   168         buttons_sizer.AddWindow(self.DebugButton)
   168         buttons_sizer.AddWindow(self.DebugButton)
   169         buttons_sizer.AddGrowableCol(1)
   169         buttons_sizer.AddGrowableCol(1)
   170         buttons_sizer.AddGrowableRow(0)
   170         buttons_sizer.AddGrowableRow(0)
   171         
   171 
   172         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
   172         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
   173         main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
   173         main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
   174         main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
   174         main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
   175         main_sizer.AddGrowableCol(0)
   175         main_sizer.AddGrowableCol(0)
   176         main_sizer.AddGrowableRow(1)
   176         main_sizer.AddGrowableRow(1)
   177         
   177 
   178         self.SetSizer(main_sizer)
   178         self.SetSizer(main_sizer)
   179         
   179 
   180         self.ParentWindow = window
   180         self.ParentWindow = window
   181         self.Controller = controller
   181         self.Controller = controller
   182         self.Debug = debug
   182         self.Debug = debug
   183         if not self.Debug:
   183         if not self.Debug:
   184             self.DebugButton.Hide()
   184             self.DebugButton.Hide()
   185         
   185 
   186         self.PouTagName = None
   186         self.PouTagName = None
   187         self.PouInfos = None
   187         self.PouInfos = None
   188         self.PouInstance = None
   188         self.PouInstance = None
   189         
   189 
   190     def __del__(self):
   190     def __del__(self):
   191         self.Controller = None
   191         self.Controller = None
   192     
   192 
   193     def SetTreeImageList(self, tree_image_list):
   193     def SetTreeImageList(self, tree_image_list):
   194         self.VariablesList.SetImageList(tree_image_list)
   194         self.VariablesList.SetImageList(tree_image_list)
   195     
   195 
   196     def SetController(self, controller):
   196     def SetController(self, controller):
   197         self.Controller = controller
   197         self.Controller = controller
   198     
   198 
   199         self.RefreshView()
   199         self.RefreshView()
   200     
   200 
   201     def SetPouType(self, tagname, pou_instance=None):
   201     def SetPouType(self, tagname, pou_instance=None):
   202         if self.Controller is not None:
   202         if self.Controller is not None:
   203             if tagname == "Project":
   203             if tagname == "Project":
   204                 config_name = self.Controller.GetProjectMainConfigurationName()
   204                 config_name = self.Controller.GetProjectMainConfigurationName()
   205                 if config_name is not None:
   205                 if config_name is not None:
   206                     tagname = self.Controller.ComputeConfigurationName(config_name)
   206                     tagname = self.Controller.ComputeConfigurationName(config_name)
   207             if pou_instance is not None:
   207             if pou_instance is not None:
   208                 self.PouInstance = pou_instance
   208                 self.PouInstance = pou_instance
   209             
   209 
   210             if self.PouTagName != tagname:
   210             if self.PouTagName != tagname:
   211                 self.PouTagName = tagname
   211                 self.PouTagName = tagname
   212                 self.RefreshView()
   212                 self.RefreshView()
   213             else:
   213             else:
   214                 self.RefreshInstanceChoice()
   214                 self.RefreshInstanceChoice()
   215         else:
   215         else:
   216             self.RefreshView()
   216             self.RefreshView()
   217     
   217 
   218     def ResetView(self):
   218     def ResetView(self):
   219         self.Controller = None
   219         self.Controller = None
   220         
   220 
   221         self.PouTagName = None
   221         self.PouTagName = None
   222         self.PouInfos = None
   222         self.PouInfos = None
   223         self.PouInstance = None
   223         self.PouInstance = None
   224         
   224 
   225         self.RefreshView()
   225         self.RefreshView()
   226     
   226 
   227     def RefreshView(self):
   227     def RefreshView(self):
   228         self.Freeze()
   228         self.Freeze()
   229         self.VariablesList.DeleteAllItems()
   229         self.VariablesList.DeleteAllItems()
   230         
   230 
   231         if self.Controller is not None and self.PouTagName is not None:
   231         if self.Controller is not None and self.PouTagName is not None:
   232             if self.PouTagName.split('::')[0] in ['A', 'T']:
   232             if self.PouTagName.split('::')[0] in ['A', 'T']:
   233                 self.PouInfos = self.Controller.GetPouVariables('P::%s' % self.PouTagName.split('::')[1], self.Debug)
   233                 self.PouInfos = self.Controller.GetPouVariables('P::%s' % self.PouTagName.split('::')[1], self.Debug)
   234             else:
   234             else:
   235                 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   235                 self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   242             for var_infos in self.PouInfos.variables:
   242             for var_infos in self.PouInfos.variables:
   243                 if var_infos.type is not None:
   243                 if var_infos.type is not None:
   244                     text = "%s (%s)" % (var_infos.name, var_infos.type)
   244                     text = "%s (%s)" % (var_infos.name, var_infos.type)
   245                 else:
   245                 else:
   246                     text = var_infos.name
   246                     text = var_infos.name
   247                 
   247 
   248                 right_images = []
   248                 right_images = []
   249                 if var_infos.edit:
   249                 if var_infos.edit:
   250                     right_images.append(self.EditImage)
   250                     right_images.append(self.EditImage)
   251                 
   251 
   252                 if var_infos.debug and self.Debug:
   252                 if var_infos.debug and self.Debug:
   253                     right_images.append(self.DebugInstanceImage)
   253                     right_images.append(self.DebugInstanceImage)
   254                 
   254 
   255                 item = self.VariablesList.AppendItem(root, text)
   255                 item = self.VariablesList.AppendItem(root, text)
   256                 item.SetRightImages(right_images)
   256                 item.SetRightImages(right_images)
   257                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos.var_class))
   257                 self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos.var_class))
   258                 self.VariablesList.SetPyData(item, var_infos)
   258                 self.VariablesList.SetPyData(item, var_infos)
   259             
   259 
   260         self.RefreshInstanceChoice()
   260         self.RefreshInstanceChoice()
   261         self.RefreshButtons()
   261         self.RefreshButtons()
   262         
   262 
   263         self.Thaw()
   263         self.Thaw()
   264     
   264 
   265     def RefreshInstanceChoice(self):
   265     def RefreshInstanceChoice(self):
   266         self.InstanceChoice.Clear()
   266         self.InstanceChoice.Clear()
   267         self.InstanceChoice.SetValue("")
   267         self.InstanceChoice.SetValue("")
   268         if self.Controller is not None and self.PouInfos is not None:
   268         if self.Controller is not None and self.PouInfos is not None:
   269             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   269             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   277             elif self.PouInstance in instances:
   277             elif self.PouInstance in instances:
   278                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   278                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   279             else:
   279             else:
   280                 self.PouInstance = None
   280                 self.PouInstance = None
   281                 self.InstanceChoice.SetValue(_("Select an instance"))
   281                 self.InstanceChoice.SetValue(_("Select an instance"))
   282     
   282 
   283     def RefreshButtons(self):
   283     def RefreshButtons(self):
   284         enabled = self.InstanceChoice.GetSelection() != -1
   284         enabled = self.InstanceChoice.GetSelection() != -1
   285         self.ParentButton.Enable(enabled and self.PouInfos.var_class != ITEM_CONFIGURATION)
   285         self.ParentButton.Enable(enabled and self.PouInfos.var_class != ITEM_CONFIGURATION)
   286         self.DebugButton.Enable(enabled and self.PouInfos.debug and self.Debug)
   286         self.DebugButton.Enable(enabled and self.PouInfos.debug and self.Debug)
   287         
   287 
   288         root = self.VariablesList.GetRootItem()
   288         root = self.VariablesList.GetRootItem()
   289         if root is not None and root.IsOk():
   289         if root is not None and root.IsOk():
   290             item, item_cookie = self.VariablesList.GetFirstChild(root)
   290             item, item_cookie = self.VariablesList.GetFirstChild(root)
   291             while item is not None and item.IsOk():
   291             while item is not None and item.IsOk():
   292                 panel = self.VariablesList.GetItemWindow(item)
   292                 panel = self.VariablesList.GetItemWindow(item)
   293                 if panel is not None:
   293                 if panel is not None:
   294                     for child in panel.GetChildren():
   294                     for child in panel.GetChildren():
   295                         if child.GetName() != "edit":
   295                         if child.GetName() != "edit":
   296                             child.Enable(enabled)
   296                             child.Enable(enabled)
   297                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   297                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   298     
   298 
   299     def EditButtonCallback(self, infos):
   299     def EditButtonCallback(self, infos):
   300         var_class = infos.var_class
   300         var_class = infos.var_class
   301         if var_class == ITEM_RESOURCE:
   301         if var_class == ITEM_RESOURCE:
   302             tagname = self.Controller.ComputeConfigurationResourceName(
   302             tagname = self.Controller.ComputeConfigurationResourceName(
   303                 self.InstanceChoice.GetStringSelection(), 
   303                 self.InstanceChoice.GetStringSelection(),
   304                 infos.name)
   304                 infos.name)
   305         elif var_class == ITEM_TRANSITION:
   305         elif var_class == ITEM_TRANSITION:
   306             tagname = self.Controller.ComputePouTransitionName(
   306             tagname = self.Controller.ComputePouTransitionName(
   307                 self.PouTagName.split("::")[1],
   307                 self.PouTagName.split("::")[1],
   308                 infos.name)
   308                 infos.name)
   312                 infos.name)
   312                 infos.name)
   313         else:
   313         else:
   314             var_class = ITEM_POU
   314             var_class = ITEM_POU
   315             tagname = self.Controller.ComputePouName(infos.type)
   315             tagname = self.Controller.ComputePouName(infos.type)
   316         self.ParentWindow.EditProjectElement(var_class, tagname)
   316         self.ParentWindow.EditProjectElement(var_class, tagname)
   317     
   317 
   318     def DebugButtonCallback(self, infos):
   318     def DebugButtonCallback(self, infos):
   319         if self.InstanceChoice.GetSelection() != -1:
   319         if self.InstanceChoice.GetSelection() != -1:
   320             var_class = infos.var_class
   320             var_class = infos.var_class
   321             instance_path = self.InstanceChoice.GetStringSelection()
   321             instance_path = self.InstanceChoice.GetStringSelection()
   322             if self.PouTagName.split("::")[0] in ["A", "T"]:
   322             if self.PouTagName.split("::")[0] in ["A", "T"]:
   342             else:
   342             else:
   343                 self.ParentWindow.OpenDebugViewer(
   343                 self.ParentWindow.OpenDebugViewer(
   344                     var_class,
   344                     var_class,
   345                     var_path,
   345                     var_path,
   346                     self.Controller.ComputePouName(infos.type))
   346                     self.Controller.ComputePouName(infos.type))
   347     
   347 
   348     def DebugButtonDClickCallback(self, infos):
   348     def DebugButtonDClickCallback(self, infos):
   349         if self.InstanceChoice.GetSelection() != -1:
   349         if self.InstanceChoice.GetSelection() != -1:
   350             if infos.var_class in ITEMS_VARIABLE:
   350             if infos.var_class in ITEMS_VARIABLE:
   351                 self.ParentWindow.AddDebugVariable(
   351                 self.ParentWindow.AddDebugVariable(
   352                     "%s.%s" % (self.InstanceChoice.GetStringSelection(), 
   352                     "%s.%s" % (self.InstanceChoice.GetStringSelection(),
   353                                infos.name), 
   353                                infos.name),
   354                     force=True,
   354                     force=True,
   355                     graph=True)
   355                     graph=True)
   356     
   356 
   357     def ShowInstanceChoicePopup(self):
   357     def ShowInstanceChoicePopup(self):
   358         self.InstanceChoice.SetFocusFromKbd()
   358         self.InstanceChoice.SetFocusFromKbd()
   359         size = self.InstanceChoice.GetSize()
   359         size = self.InstanceChoice.GetSize()
   360         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   360         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
   361         event.x = size.width / 2
   361         event.x = size.width / 2
   362         event.y = size.height / 2
   362         event.y = size.height / 2
   363         event.SetEventObject(self.InstanceChoice)
   363         event.SetEventObject(self.InstanceChoice)
   364         #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
   364         #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
   365         #event.m_keyCode = wx.WXK_SPACE
   365         #event.m_keyCode = wx.WXK_SPACE
   366         self.InstanceChoice.GetEventHandler().ProcessEvent(event)
   366         self.InstanceChoice.GetEventHandler().ProcessEvent(event)
   367     
   367 
   368     def OnParentButtonClick(self, event):
   368     def OnParentButtonClick(self, event):
   369         if self.InstanceChoice.GetSelection() != -1:
   369         if self.InstanceChoice.GetSelection() != -1:
   370             parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
   370             parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
   371             tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
   371             tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
   372             if tagname is not None:
   372             if tagname is not None:
   373                 wx.CallAfter(self.SetPouType, tagname, parent_path)
   373                 wx.CallAfter(self.SetPouType, tagname, parent_path)
   374                 wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   374                 wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   375         event.Skip()
   375         event.Skip()
   376         
   376 
   377     def OnInstanceChoiceChanged(self, event):
   377     def OnInstanceChoiceChanged(self, event):
   378         self.RefreshButtons()
   378         self.RefreshButtons()
   379         event.Skip()
   379         event.Skip()
   380         
   380 
   381     def OnDebugButtonClick(self, event):
   381     def OnDebugButtonClick(self, event):
   382         if self.InstanceChoice.GetSelection() != -1:
   382         if self.InstanceChoice.GetSelection() != -1:
   383             self.ParentWindow.OpenDebugViewer(
   383             self.ParentWindow.OpenDebugViewer(
   384                 self.PouInfos.var_class,
   384                 self.PouInfos.var_class,
   385                 self.InstanceChoice.GetStringSelection(),
   385                 self.InstanceChoice.GetStringSelection(),
   386                 self.PouTagName)
   386                 self.PouTagName)
   387         event.Skip()
   387         event.Skip()
   388     
   388 
   389     def OnVariablesListItemActivated(self, event):
   389     def OnVariablesListItemActivated(self, event):
   390         selected_item = event.GetItem()
   390         selected_item = event.GetItem()
   391         if selected_item is not None and selected_item.IsOk():
   391         if selected_item is not None and selected_item.IsOk():
   392             item_infos = self.VariablesList.GetPyData(selected_item)
   392             item_infos = self.VariablesList.GetPyData(selected_item)
   393             if item_infos is not None:
   393             if item_infos is not None:
   394                 
   394 
   395                 item_button = self.VariablesList.IsOverItemRightImage(
   395                 item_button = self.VariablesList.IsOverItemRightImage(
   396                     selected_item, event.GetPoint())
   396                     selected_item, event.GetPoint())
   397                 if item_button is not None:
   397                 if item_button is not None:
   398                     callback = self.ButtonCallBacks[item_button].dclick
   398                     callback = self.ButtonCallBacks[item_button].dclick
   399                     if callback is not None:
   399                     if callback is not None:
   400                         callback(item_infos)
   400                         callback(item_infos)
   401                 
   401 
   402                 elif item_infos.var_class not in ITEMS_VARIABLE:
   402                 elif item_infos.var_class not in ITEMS_VARIABLE:
   403                     instance_path = self.InstanceChoice.GetStringSelection()
   403                     instance_path = self.InstanceChoice.GetStringSelection()
   404                     if item_infos.var_class == ITEM_RESOURCE:
   404                     if item_infos.var_class == ITEM_RESOURCE:
   405                         if instance_path != "":
   405                         if instance_path != "":
   406                             tagname = self.Controller.ComputeConfigurationResourceName(
   406                             tagname = self.Controller.ComputeConfigurationResourceName(
   407                                            instance_path, 
   407                                            instance_path,
   408                                            item_infos.name)
   408                                            item_infos.name)
   409                         else:
   409                         else:
   410                             tagname = None
   410                             tagname = None
   411                     else:
   411                     else:
   412                         parent_infos = self.VariablesList.GetPyData(selected_item.GetParent())
   412                         parent_infos = self.VariablesList.GetPyData(selected_item.GetParent())
   422                         else:
   422                         else:
   423                             item_path = None
   423                             item_path = None
   424                         self.SetPouType(tagname, item_path)
   424                         self.SetPouType(tagname, item_path)
   425                         self.ParentWindow.SelectProjectTreeItem(tagname)
   425                         self.ParentWindow.SelectProjectTreeItem(tagname)
   426         event.Skip()
   426         event.Skip()
   427     
   427 
   428     def OnVariablesListLeftDown(self, event):
   428     def OnVariablesListLeftDown(self, event):
   429         if self.InstanceChoice.GetSelection() == -1:
   429         if self.InstanceChoice.GetSelection() == -1:
   430             wx.CallAfter(self.ShowInstanceChoicePopup)
   430             wx.CallAfter(self.ShowInstanceChoicePopup)
   431         else:
   431         else:
   432             instance_path = self.InstanceChoice.GetStringSelection()
   432             instance_path = self.InstanceChoice.GetStringSelection()
   433             item, flags = self.VariablesList.HitTest(event.GetPosition())
   433             item, flags = self.VariablesList.HitTest(event.GetPosition())
   434             if item is not None:
   434             if item is not None:
   435                 item_infos = self.VariablesList.GetPyData(item)
   435                 item_infos = self.VariablesList.GetPyData(item)
   436                 if item_infos is not None:
   436                 if item_infos is not None:
   437                     
   437 
   438                     item_button = self.VariablesList.IsOverItemRightImage(
   438                     item_button = self.VariablesList.IsOverItemRightImage(
   439                         item, event.GetPosition())
   439                         item, event.GetPosition())
   440                     if item_button is not None:
   440                     if item_button is not None:
   441                         callback = self.ButtonCallBacks[item_button].leftdown
   441                         callback = self.ButtonCallBacks[item_button].leftdown
   442                         if callback is not None:
   442                         if callback is not None:
   443                             callback(item_infos)
   443                             callback(item_infos)
   444                 
   444 
   445                     elif (flags & CT.TREE_HITTEST_ONITEMLABEL and 
   445                     elif (flags & CT.TREE_HITTEST_ONITEMLABEL and
   446                           item_infos.var_class in ITEMS_VARIABLE):
   446                           item_infos.var_class in ITEMS_VARIABLE):
   447                         self.ParentWindow.EnsureTabVisible(
   447                         self.ParentWindow.EnsureTabVisible(
   448                             self.ParentWindow.DebugVariablePanel)
   448                             self.ParentWindow.DebugVariablePanel)
   449                         item_path = "%s.%s" % (instance_path, item_infos.name)
   449                         item_path = "%s.%s" % (instance_path, item_infos.name)
   450                         data = wx.TextDataObject(str((item_path, "debug")))
   450                         data = wx.TextDataObject(str((item_path, "debug")))
   455 
   455 
   456     def OnVariablesListKeyDown(self, event):
   456     def OnVariablesListKeyDown(self, event):
   457         keycode = event.GetKeyCode()
   457         keycode = event.GetKeyCode()
   458         if keycode != wx.WXK_LEFT:
   458         if keycode != wx.WXK_LEFT:
   459             event.Skip()
   459             event.Skip()
   460