controls/PouInstanceVariablesPanel.py
changeset 687 629680fb0582
parent 686 3216bf5f711d
child 692 e00ce7077bfc
equal deleted inserted replaced
686:3216bf5f711d 687:629680fb0582
    46         self.InstanceChoice = wx.ComboBox(name='InstanceChoice', 
    46         self.InstanceChoice = wx.ComboBox(name='InstanceChoice', 
    47               parent=self, pos=wx.Point(0, 0),
    47               parent=self, pos=wx.Point(0, 0),
    48               size=wx.Size(0, 28), style=wx.CB_READONLY)
    48               size=wx.Size(0, 28), style=wx.CB_READONLY)
    49         self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
    49         self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
    50                 self.InstanceChoice)
    50                 self.InstanceChoice)
       
    51         self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown)
    51         
    52         
    52         self.DebugButton = wx.lib.buttons.GenBitmapButton(
    53         self.DebugButton = wx.lib.buttons.GenBitmapButton(
    53               name='DebugButton', parent=self, 
    54               name='DebugButton', parent=self, 
    54               bitmap=window.GenerateBitmap("debug"), 
    55               bitmap=window.GenerateBitmap("debug"), 
    55               pos=wx.Point(0, 0), size=wx.Size(28, 28), 
    56               pos=wx.Point(0, 0), size=wx.Size(28, 28), 
    56               style=wx.NO_BORDER)
    57               style=wx.NO_BORDER)
    57         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
    58         self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
    58                 self.DebugButton)
    59                 self.DebugButton)
    59     
    60         
    60         self.VariablesList = CT.CustomTreeCtrl(
    61         self.VariablesList = CT.CustomTreeCtrl(
    61               name='VariablesList', parent=self,
    62               name='VariablesList', parent=self,
    62               pos=wx.Point(0, 0), size=wx.Size(0, 0), 
    63               pos=wx.Point(0, 0), size=wx.Size(0, 0), 
    63               style=wx.SUNKEN_BORDER,
    64               style=wx.SUNKEN_BORDER,
    64               agwStyle=CT.TR_NO_BUTTONS|
    65               agwStyle=CT.TR_NO_BUTTONS|
    65                        CT.TR_SINGLE|
    66                        CT.TR_SINGLE|
    66                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
    67                        CT.TR_HAS_VARIABLE_ROW_HEIGHT|
    67                        CT.TR_HIDE_ROOT|
    68                        CT.TR_HIDE_ROOT|
    68                        CT.TR_NO_LINES|
    69                        CT.TR_NO_LINES|
    69                        CT.TR_ALIGN_WINDOWS_RIGHT)
    70                        getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
    70         self.VariablesList.SetIndent(0)
    71         self.VariablesList.SetIndent(0)
    71         self.VariablesList.SetSpacing(5)
    72         self.VariablesList.SetSpacing(5)
    72         self.VariablesList.DoSelectItem = lambda *x,**y:True
    73         self.VariablesList.DoSelectItem = lambda *x,**y:True
    73         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
    74         self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
    74                 self.OnVariablesListItemActivated)
    75                 self.OnVariablesListItemActivated)
       
    76         self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
    75         
    77         
    76         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
    78         buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
    77         buttons_sizer.AddWindow(self.ParentButton, 0, border=0, flag=0)
    79         buttons_sizer.AddWindow(self.ParentButton, 0, border=0, flag=0)
    78         buttons_sizer.AddWindow(self.InstanceChoice, 0, border=0, flag=wx.GROW)
    80         buttons_sizer.AddWindow(self.InstanceChoice, 0, border=0, flag=wx.GROW)
    79         buttons_sizer.AddWindow(self.DebugButton, 0, border=0, flag=0)
    81         buttons_sizer.AddWindow(self.DebugButton, 0, border=0, flag=0)
   104     def SetTreeImageList(self, tree_image_list):
   106     def SetTreeImageList(self, tree_image_list):
   105         self.VariablesList.SetImageList(tree_image_list)
   107         self.VariablesList.SetImageList(tree_image_list)
   106     
   108     
   107     def SetController(self, controller):
   109     def SetController(self, controller):
   108         self.Controller = controller
   110         self.Controller = controller
   109      
   111     
       
   112         self.RefreshView()
       
   113     
   110     def SetPouType(self, tagname, pou_instance=None):
   114     def SetPouType(self, tagname, pou_instance=None):
   111         self.PouTagName = tagname
   115         self.PouTagName = tagname
   112         if pou_instance is not None:
   116         if pou_instance is not None:
   113             self.PouInstance = pou_instance
   117             self.PouInstance = pou_instance
   114         
   118         
   115         self.RefreshView()
   119         self.RefreshView()
   116     
   120     
   117     def ResetView(self):
   121     def ResetView(self):
       
   122         self.Controller = None
       
   123         
   118         self.PouTagName = None
   124         self.PouTagName = None
   119         self.PouInfos = None
   125         self.PouInfos = None
   120         self.PouInstance = None
   126         self.PouInstance = None
   121         
   127         
   122         self.RefreshView()
   128         self.RefreshView()
   123     
   129     
   124     def RefreshView(self):
   130     def RefreshView(self):
   125         self.VariablesList.DeleteAllItems()
   131         self.VariablesList.DeleteAllItems()
   126         self.InstanceChoice.Clear()
   132         self.InstanceChoice.Clear()
       
   133         self.InstanceChoice.SetValue("")
   127         
   134         
   128         if self.PouTagName is not None:
   135         if self.PouTagName is not None:
   129             self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   136             self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
   130         else:
   137         else:
   131             self.PouInfos = None
   138             self.PouInfos = None
   181                 self.VariablesList.SetPyData(item, var_infos)
   188                 self.VariablesList.SetPyData(item, var_infos)
   182             
   189             
   183             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   190             instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
   184             for instance in instances:
   191             for instance in instances:
   185                 self.InstanceChoice.Append(instance)
   192                 self.InstanceChoice.Append(instance)
       
   193             if len(instances) == 1:
       
   194                 self.PouInstance = instances[0]
   186             if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
   195             if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
   187                 self.PouInstance = None
   196                 self.PouInstance = None
   188                 self.InstanceChoice.SetSelection(0)
   197                 self.InstanceChoice.SetSelection(0)
   189             elif self.PouInstance in instances:
   198             elif self.PouInstance in instances:
   190                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   199                 self.InstanceChoice.SetStringSelection(self.PouInstance)
   248                                           infos["name"])
   257                                           infos["name"])
   249                     self.ParentWindow.OpenGraphicViewer(var_path)
   258                     self.ParentWindow.OpenGraphicViewer(var_path)
   250             event.Skip()
   259             event.Skip()
   251         return GraphButtonCallback
   260         return GraphButtonCallback
   252     
   261     
       
   262     def ShowInstanceChoicePopup(self):
       
   263         self.InstanceChoice.SetFocusFromKbd()
       
   264         size = self.InstanceChoice.GetSize()
       
   265         event = wx.MouseEvent(wx.EVT_LEFT_DOWN._getEvtType())
       
   266         event.m_x = size.width / 2
       
   267         event.m_y = size.height / 2
       
   268         event.SetEventObject(self.InstanceChoice)
       
   269         #event = wx.KeyEvent(wx.EVT_KEY_DOWN._getEvtType())
       
   270         #event.m_keyCode = wx.WXK_SPACE
       
   271         self.InstanceChoice.GetEventHandler().ProcessEvent(event)
       
   272     
   253     def OnParentButtonClick(self, event):
   273     def OnParentButtonClick(self, event):
   254         if self.InstanceChoice.GetSelection() != -1:
   274         if self.InstanceChoice.GetSelection() != -1:
   255             parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
   275             parent_path = self.InstanceChoice.GetStringSelection().rsplit(".", 1)[0]
   256             tagname = self.Controller.GetPouInstanceTagname(parent_path, self.Debug)
   276             tagname = self.Controller.GetPouInstanceTagName(parent_path, self.Debug)
   257             if tagname is not None:
   277             if tagname is not None:
   258                 wx.CallAfter(self.SetPouType, tagname, parent_path)
   278                 wx.CallAfter(self.SetPouType, tagname, parent_path)
   259                 wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   279                 wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   260         event.Skip()
   280         event.Skip()
   261         
   281         
   275         if self.InstanceChoice.GetSelection() != -1:
   295         if self.InstanceChoice.GetSelection() != -1:
   276             instance_path = self.InstanceChoice.GetStringSelection()
   296             instance_path = self.InstanceChoice.GetStringSelection()
   277             selected_item = event.GetItem()
   297             selected_item = event.GetItem()
   278             if selected_item is not None and selected_item.IsOk():
   298             if selected_item is not None and selected_item.IsOk():
   279                 item_infos = self.VariablesList.GetPyData(selected_item)
   299                 item_infos = self.VariablesList.GetPyData(selected_item)
   280                 if item_infos["class"] not in ITEMS_VARIABLE:
   300                 if item_infos is not None and item_infos["class"] not in ITEMS_VARIABLE:
   281                     if item_infos["class"] == ITEM_RESOURCE:
   301                     if item_infos["class"] == ITEM_RESOURCE:
   282                         tagname = self.Controller.ComputeConfigurationResourceName(
   302                         tagname = self.Controller.ComputeConfigurationResourceName(
   283                                        instance_path, 
   303                                        instance_path, 
   284                                        item_infos["name"])
   304                                        item_infos["name"])
   285                     else:
   305                     else:
   287                     item_path = "%s.%s" % (instance_path, item_infos["name"])
   307                     item_path = "%s.%s" % (instance_path, item_infos["name"])
   288                     wx.CallAfter(self.SetPouType, tagname, item_path)
   308                     wx.CallAfter(self.SetPouType, tagname, item_path)
   289                     wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   309                     wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, tagname)
   290         event.Skip()
   310         event.Skip()
   291     
   311     
   292     
   312     def OnVariablesListLeftDown(self, event):
       
   313         if self.InstanceChoice.GetSelection() == -1:
       
   314             wx.CallAfter(self.ShowInstanceChoicePopup)
       
   315         event.Skip()
       
   316         
       
   317     def OnInstanceChoiceLeftDown(self, event):
       
   318         event.Skip()