plugger.py
changeset 19 73257cea38bd
parent 18 0fac6d621a24
child 20 d3cb5020997b
equal deleted inserted replaced
18:0fac6d621a24 19:73257cea38bd
    34     PlugMaxCount = None
    34     PlugMaxCount = None
    35     PluginMethods = []
    35     PluginMethods = []
    36 
    36 
    37     def _AddParamsMembers(self):
    37     def _AddParamsMembers(self):
    38         Classes = GenerateClassesFromXSDstring(self.XSD)[0]
    38         Classes = GenerateClassesFromXSDstring(self.XSD)[0]
    39         self.PlugParams = []
    39         self.PlugParams = None
    40         Classes = [(name, XSDclass) for name, XSDclass in Classes.items() if XSDclass.IsBaseClass]
    40         Classes = [(name, XSDclass) for name, XSDclass in Classes.items() if XSDclass.IsBaseClass]
    41         if len(Classes) == 1:
    41         if len(Classes) == 1:
    42             name, XSDclass = Classes[0]
    42             name, XSDclass = Classes[0]
    43             obj = XSDclass()
    43             obj = XSDclass()
    44             self.PlugParams = (name, obj)
    44             self.PlugParams = (name, obj)
    66         return False
    66         return False
    67         
    67         
    68     def OnPlugSave(self):
    68     def OnPlugSave(self):
    69         return True
    69         return True
    70 
    70 
    71     def GetPlugParamsAttributes(self):
    71     def GetParamsAttributes(self, path = None):
    72         return self.PlugParams[1].getElementAttributes()
    72         if path:
    73     
    73             parts = path.split(".", 1)
    74     def SetPlugParamsAttribute(self, name, value):
    74             if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
    75         attr = getattr(self.PlugParams[1], name, None)
    75                 return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
    76         if isinstance(attr, types.ClassType):
    76             elif self.PlugParams and parts[0] == self.PlugParams[0]:
    77             attr.SetValue(value)
    77                 return self.PlugParams[1].getElementInfos(parts[0], parts[1])
    78         else:
    78         else:
    79             setattr(self.PlugParams[1], name, value)
    79             params = []
       
    80             if self.MandatoryParams:
       
    81                 params.append(self.MandatoryParams[1].getElementInfos(self.MandatoryParams[0]))
       
    82             if self.PlugParams:
       
    83                 params.append(self.PlugParams[1].getElementInfos(self.PlugParams[0]))
       
    84             return params
       
    85         
       
    86     def SetParamsAttribute(self, path, value):
       
    87         parts = path.split(".", 1)
       
    88         if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
       
    89             self.MandatoryParams[1].setElementValue(parts[1], value)
       
    90         elif self.PlugParams and parts[0] == self.PlugParams[0]:
       
    91             self.PlugParams[1].setElementValue(parts[1], value)
    80 
    92 
    81     def PlugRequestSave(self):
    93     def PlugRequestSave(self):
    82         # If plugin do not have corresponding directory
    94         # If plugin do not have corresponding directory
    83         plugpath = self.PlugPath()
    95         plugpath = self.PlugPath()
    84         if not os.path.isdir(plugpath):
    96         if not os.path.isdir(plugpath):
   423         return self.ProjectPath != ""
   435         return self.ProjectPath != ""
   424     
   436     
   425     def GetProjectPath(self):
   437     def GetProjectPath(self):
   426         return self.ProjectPath
   438         return self.ProjectPath
   427     
   439     
   428     def GetTargetTypes(self):
       
   429         return self.BeremizRoot.TargetType.getChoices().keys()
       
   430     
       
   431     def ChangeTargetType(self, target_type):
       
   432         self.BeremizRoot.TargetType.addContent(target_type)
       
   433         
       
   434     def GetTargetAttributes(self):
       
   435         content = self.BeremizRoot.TargetType.getContent()
       
   436         if content:
       
   437             return content["value"].getElementAttributes()
       
   438         else:
       
   439             return []
       
   440         
       
   441     def SetTargetAttribute(self, name, value):
       
   442         content = self.BeremizRoot.TargetType.getContent()
       
   443         if content:
       
   444             attr = getattr(content["value"], name, None)
       
   445             if isinstance(attr, types.ClassType):
       
   446                 attr.SetValue(value)
       
   447             else:
       
   448                 setattr(content["value"], name, value)
       
   449     
       
   450     def GetTargetType(self):
       
   451         content = self.BeremizRoot.TargetType.getContent()
       
   452         if content:
       
   453             return content["name"]
       
   454         else:
       
   455             return ""
       
   456     
       
   457     def NewProject(self, ProjectPath, PLCParams):
   440     def NewProject(self, ProjectPath, PLCParams):
   458         """
   441         """
   459         Create a new project in an empty folder
   442         Create a new project in an empty folder
   460         @param ProjectPath: path of the folder where project have to be created
   443         @param ProjectPath: path of the folder where project have to be created
   461         @param PLCParams: properties of the PLCOpen program created
   444         @param PLCParams: properties of the PLCOpen program created