plugger.py
changeset 33 59b84ab7bf8b
parent 29 282380dea497
child 40 db12e3e11bcf
equal deleted inserted replaced
32:4bdc888e634b 33:59b84ab7bf8b
    90             return params
    90             return params
    91         
    91         
    92     def SetParamsAttribute(self, path, value, logger):
    92     def SetParamsAttribute(self, path, value, logger):
    93         # Filter IEC_Channel and Name, that have specific behavior
    93         # Filter IEC_Channel and Name, that have specific behavior
    94         if path == "BaseParams.IEC_Channel":
    94         if path == "BaseParams.IEC_Channel":
    95             return self.FindNewIEC_Channel(value,logger), False
    95             return self.FindNewIEC_Channel(value,logger), True
    96         elif path == "BaseParams.Name":
    96         elif path == "BaseParams.Name":
    97             res = self.FindNewName(value,logger)
    97             res = self.FindNewName(value,logger)
    98             self.PlugRequestSave()
    98             self.PlugRequestSave()
    99             return res, True
    99             return res, True
   100         
   100         
   219     def GetPlugRoot(self):
   219     def GetPlugRoot(self):
   220         return self.PlugParent.GetPlugRoot()
   220         return self.PlugParent.GetPlugRoot()
   221 
   221 
   222     def GetPlugInfos(self):
   222     def GetPlugInfos(self):
   223         childs = []
   223         childs = []
   224         for child in self.IterChilds():
   224         # reorder childs by IEC_channels
   225             childs.append(child.GetPlugInfos())
   225         ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChilds()]
   226         return {"name" : self.BaseParams.getName(), "type" : None, "values" : childs}
   226         if ordered:
       
   227             ordered.sort()
       
   228             for child in zip(*ordered)[1]:
       
   229                 childs.append(child.GetPlugInfos())
       
   230         return {"name" : "%s (%d)"%(self.BaseParams.getName(),self.BaseParams.getIEC_Channel()), "type" : self.BaseParams.getName(), "values" : childs}
   227     
   231     
   228     
   232     
   229     def FindNewName(self, DesiredName, logger):
   233     def FindNewName(self, DesiredName, logger):
   230         """
   234         """
   231         Changes Name to DesiredName if available, Name-N if not.
   235         Changes Name to DesiredName if available, Name-N if not.
   281         # Now, try to guess the nearest available channel
   285         # Now, try to guess the nearest available channel
   282         res = DesiredChannel
   286         res = DesiredChannel
   283         while res in AllChannels: # While channel not free
   287         while res in AllChannels: # While channel not free
   284             if res < CurrentChannel: # Want to go down ?
   288             if res < CurrentChannel: # Want to go down ?
   285                 res -=  1 # Test for n-1
   289                 res -=  1 # Test for n-1
   286                 if res < 0 : return CurrentChannel # Can't go bellow 0, do nothing
   290                 if res < 0 :
       
   291                     if logger :
       
   292                         logger.write_warning("Cannot find lower free IEC channel than %d\n"%CurrentChannel)
       
   293                     return CurrentChannel # Can't go bellow 0, do nothing
   287             else : # Want to go up ?
   294             else : # Want to go up ?
   288                 res +=  1 # Test for n-1
   295                 res +=  1 # Test for n-1
   289         # Finally set IEC Channel
   296         # Finally set IEC Channel
   290         self.BaseParams.setIEC_Channel(res)
   297         self.BaseParams.setIEC_Channel(res)
   291         if logger and DesiredChannel != res:
   298         if logger and DesiredChannel != res:
   547     
   554     
   548     def GetPlugInfos(self):
   555     def GetPlugInfos(self):
   549         childs = []
   556         childs = []
   550         for child in self.IterChilds():
   557         for child in self.IterChilds():
   551             childs.append(child.GetPlugInfos())
   558             childs.append(child.GetPlugInfos())
   552         return {"name" : os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs}
   559         return {"name" : "PLC (%s)"%os.path.split(self.ProjectPath)[1], "type" : None, "values" : childs}
   553     
   560     
   554     def NewProject(self, ProjectPath):
   561     def NewProject(self, ProjectPath):
   555         """
   562         """
   556         Create a new project in an empty folder
   563         Create a new project in an empty folder
   557         @param ProjectPath: path of the folder where project have to be created
   564         @param ProjectPath: path of the folder where project have to be created