controls/PouInstanceVariablesPanel.py
changeset 1948 b9a3f771aaab
parent 1881 091005ec69c4
child 2437 105c20fdeb19
equal deleted inserted replaced
1947:7c2cd9d33070 1948:b9a3f771aaab
    28 
    28 
    29 import wx
    29 import wx
    30 import wx.lib.agw.customtreectrl as CT
    30 import wx.lib.agw.customtreectrl as CT
    31 import wx.lib.buttons
    31 import wx.lib.buttons
    32 
    32 
    33 from PLCControler import \
    33 from plcopen.types_enums import *
    34     ITEMS_VARIABLE, \
       
    35     ITEM_CONFIGURATION, \
       
    36     ITEM_RESOURCE, \
       
    37     ITEM_POU, \
       
    38     ITEM_TRANSITION, \
       
    39     ITEM_ACTION
       
    40 
    34 
    41 from util.BitmapLibrary import GetBitmap
    35 from util.BitmapLibrary import GetBitmap
    42 
    36 
    43 
    37 
    44 # Customize CustomTreeItem for adding icon on item right
    38 # Customize CustomTreeItem for adding icon on item right
   218     def SetPouType(self, tagname, pou_instance=None):
   212     def SetPouType(self, tagname, pou_instance=None):
   219         if self.Controller is not None:
   213         if self.Controller is not None:
   220             if tagname == "Project":
   214             if tagname == "Project":
   221                 config_name = self.Controller.GetProjectMainConfigurationName()
   215                 config_name = self.Controller.GetProjectMainConfigurationName()
   222                 if config_name is not None:
   216                 if config_name is not None:
   223                     tagname = self.Controller.ComputeConfigurationName(config_name)
   217                     tagname = ComputeConfigurationName(config_name)
   224             if pou_instance is not None:
   218             if pou_instance is not None:
   225                 self.PouInstance = pou_instance
   219                 self.PouInstance = pou_instance
   226 
   220 
   227             if self.PouTagName != tagname:
   221             if self.PouTagName != tagname:
   228                 self.PouTagName = tagname
   222                 self.PouTagName = tagname
   314                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   308                 item, item_cookie = self.VariablesList.GetNextChild(root, item_cookie)
   315 
   309 
   316     def EditButtonCallback(self, infos):
   310     def EditButtonCallback(self, infos):
   317         var_class = infos.var_class
   311         var_class = infos.var_class
   318         if var_class == ITEM_RESOURCE:
   312         if var_class == ITEM_RESOURCE:
   319             tagname = self.Controller.ComputeConfigurationResourceName(
   313             tagname = ComputeConfigurationResourceName(
   320                 self.InstanceChoice.GetStringSelection(),
   314                 self.InstanceChoice.GetStringSelection(),
   321                 infos.name)
   315                 infos.name)
   322         elif var_class == ITEM_TRANSITION:
   316         elif var_class == ITEM_TRANSITION:
   323             tagname = self.Controller.ComputePouTransitionName(
   317             tagname = ComputePouTransitionName(
   324                 self.PouTagName.split("::")[1],
   318                 self.PouTagName.split("::")[1],
   325                 infos.name)
   319                 infos.name)
   326         elif var_class == ITEM_ACTION:
   320         elif var_class == ITEM_ACTION:
   327             tagname = self.Controller.ComputePouActionName(
   321             tagname = ComputePouActionName(
   328                 self.PouTagName.split("::")[1],
   322                 self.PouTagName.split("::")[1],
   329                 infos.name)
   323                 infos.name)
   330         else:
   324         else:
   331             var_class = ITEM_POU
   325             var_class = ITEM_POU
   332             tagname = self.Controller.ComputePouName(infos.type)
   326             tagname = ComputePouName(infos.type)
   333         self.ParentWindow.EditProjectElement(var_class, tagname)
   327         self.ParentWindow.EditProjectElement(var_class, tagname)
   334 
   328 
   335     def DebugButtonCallback(self, infos):
   329     def DebugButtonCallback(self, infos):
   336         if self.InstanceChoice.GetSelection() != -1:
   330         if self.InstanceChoice.GetSelection() != -1:
   337             var_class = infos.var_class
   331             var_class = infos.var_class
   344                 self.ParentWindow.AddDebugVariable(var_path, force=True)
   338                 self.ParentWindow.AddDebugVariable(var_path, force=True)
   345             elif var_class == ITEM_TRANSITION:
   339             elif var_class == ITEM_TRANSITION:
   346                 self.ParentWindow.OpenDebugViewer(
   340                 self.ParentWindow.OpenDebugViewer(
   347                     var_class,
   341                     var_class,
   348                     var_path,
   342                     var_path,
   349                     self.Controller.ComputePouTransitionName(
   343                     ComputePouTransitionName(
   350                         self.PouTagName.split("::")[1],
   344                         self.PouTagName.split("::")[1],
   351                         infos.name))
   345                         infos.name))
   352             elif var_class == ITEM_ACTION:
   346             elif var_class == ITEM_ACTION:
   353                 self.ParentWindow.OpenDebugViewer(
   347                 self.ParentWindow.OpenDebugViewer(
   354                     var_class,
   348                     var_class,
   355                     var_path,
   349                     var_path,
   356                     self.Controller.ComputePouActionName(
   350                     ComputePouActionName(
   357                         self.PouTagName.split("::")[1],
   351                         self.PouTagName.split("::")[1],
   358                         infos.name))
   352                         infos.name))
   359             else:
   353             else:
   360                 self.ParentWindow.OpenDebugViewer(
   354                 self.ParentWindow.OpenDebugViewer(
   361                     var_class,
   355                     var_class,
   362                     var_path,
   356                     var_path,
   363                     self.Controller.ComputePouName(infos.type))
   357                     ComputePouName(infos.type))
   364 
   358 
   365     def DebugButtonDClickCallback(self, infos):
   359     def DebugButtonDClickCallback(self, infos):
   366         if self.InstanceChoice.GetSelection() != -1:
   360         if self.InstanceChoice.GetSelection() != -1:
   367             if infos.var_class in ITEMS_VARIABLE:
   361             if infos.var_class in ITEMS_VARIABLE:
   368                 self.ParentWindow.AddDebugVariable(
   362                 self.ParentWindow.AddDebugVariable(
   418 
   412 
   419                 elif item_infos.var_class not in ITEMS_VARIABLE:
   413                 elif item_infos.var_class not in ITEMS_VARIABLE:
   420                     instance_path = self.InstanceChoice.GetStringSelection()
   414                     instance_path = self.InstanceChoice.GetStringSelection()
   421                     if item_infos.var_class == ITEM_RESOURCE:
   415                     if item_infos.var_class == ITEM_RESOURCE:
   422                         if instance_path != "":
   416                         if instance_path != "":
   423                             tagname = self.Controller.ComputeConfigurationResourceName(
   417                             tagname = ComputeConfigurationResourceName(
   424                                 instance_path,
   418                                 instance_path,
   425                                 item_infos.name)
   419                                 item_infos.name)
   426                         else:
   420                         else:
   427                             tagname = None
   421                             tagname = None
   428                     else:
   422                     else:
   429                         parent_infos = self.VariablesList.GetPyData(selected_item.GetParent())
   423                         parent_infos = self.VariablesList.GetPyData(selected_item.GetParent())
   430                         if item_infos.var_class == ITEM_ACTION:
   424                         if item_infos.var_class == ITEM_ACTION:
   431                             tagname = self.Controller.ComputePouActionName(parent_infos.type, item_infos.name)
   425                             tagname = ComputePouActionName(parent_infos.type, item_infos.name)
   432                         elif item_infos.var_class == ITEM_TRANSITION:
   426                         elif item_infos.var_class == ITEM_TRANSITION:
   433                             tagname = self.Controller.ComputePouTransitionName(parent_infos.type, item_infos.name)
   427                             tagname = ComputePouTransitionName(parent_infos.type, item_infos.name)
   434                         else:
   428                         else:
   435                             tagname = self.Controller.ComputePouName(item_infos.type)
   429                             tagname = ComputePouName(item_infos.type)
   436                     if tagname is not None:
   430                     if tagname is not None:
   437                         if instance_path != "":
   431                         if instance_path != "":
   438                             item_path = "%s.%s" % (instance_path, item_infos.name)
   432                             item_path = "%s.%s" % (instance_path, item_infos.name)
   439                         else:
   433                         else:
   440                             item_path = None
   434                             item_path = None