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