PLCControler.py
changeset 1330 96b242e4c59d
parent 1328 a2f2981df9b0
child 1331 38c5de794e62
equal deleted inserted replaced
1328:a2f2981df9b0 1330:96b242e4c59d
   842     def PastePou(self, pou_type, pou_xml):
   842     def PastePou(self, pou_type, pou_xml):
   843         '''
   843         '''
   844         Adds the POU defined by 'pou_xml' to the current project with type 'pou_type'
   844         Adds the POU defined by 'pou_xml' to the current project with type 'pou_type'
   845         '''
   845         '''
   846         try:
   846         try:
   847             new_pou = LoadPou(pou_xml)
   847             new_pou, error = LoadPou(pou_xml)
   848         except:
   848         except:
       
   849             error = ""
       
   850         if error is not None:
   849             return _("Couldn't paste non-POU object.")
   851             return _("Couldn't paste non-POU object.")
   850         
   852         
   851         name = new_pou.getname()
   853         name = new_pou.getname()
   852         
   854         
   853         idx = 0
   855         idx = 0
  2205             # Get ids already by all the instances in edited element
  2207             # Get ids already by all the instances in edited element
  2206             used_id = dict([(instance.getlocalId(), True) for instance in element.getinstances()])
  2208             used_id = dict([(instance.getlocalId(), True) for instance in element.getinstances()])
  2207             new_id = {}
  2209             new_id = {}
  2208             
  2210             
  2209             try:
  2211             try:
  2210                 instances = LoadPouInstances(text.encode("utf-8"), bodytype)
  2212                 instances, error = LoadPouInstances(text.encode("utf-8"), bodytype)
  2211                 if len(instances) == 0:
       
  2212                     raise ValueError
       
  2213             except:
  2213             except:
       
  2214                 instances, error = [], ""
       
  2215             if error is not None or len(instances) == 0:
  2214                 return _("Invalid plcopen element(s)!!!")
  2216                 return _("Invalid plcopen element(s)!!!")
  2215             
  2217             
  2216             exclude = {}
  2218             exclude = {}
  2217             for instance in instances:
  2219             for instance in instances:
  2218                 element.addinstance(instance)
  2220                 element.addinstance(instance)
  3061                 new_instance["Task"] = ""
  3063                 new_instance["Task"] = ""
  3062                 instances_data.append(new_instance)
  3064                 instances_data.append(new_instance)
  3063             return tasks_data, instances_data
  3065             return tasks_data, instances_data
  3064 
  3066 
  3065     def OpenXMLFile(self, filepath):
  3067     def OpenXMLFile(self, filepath):
  3066         #try:
  3068         self.Project, error = LoadProject(filepath)
  3067         self.Project = LoadProject(filepath)
  3069         if self.Project is None:
  3068         #except Exception, e:
  3070             return _("Project file syntax error:\n\n") + error
  3069         #    return _("Project file syntax error:\n\n") + str(e)
       
  3070         self.SetFilePath(filepath)
  3071         self.SetFilePath(filepath)
  3071         self.CreateProjectBuffer(True)
  3072         self.CreateProjectBuffer(True)
  3072         self.ProgramChunks = []
  3073         self.ProgramChunks = []
  3073         self.ProgramOffset = 0
  3074         self.ProgramOffset = 0
  3074         self.NextCompiledProject = self.Copy(self.Project)
  3075         self.NextCompiledProject = self.Copy(self.Project)
  3075         self.CurrentCompiledProject = None
  3076         self.CurrentCompiledProject = None
  3076         self.Buffering = False
  3077         self.Buffering = False
  3077         self.CurrentElementEditing = None
  3078         self.CurrentElementEditing = None
  3078         return None
  3079         return error
  3079         
  3080         
  3080     def SaveXMLFile(self, filepath = None):
  3081     def SaveXMLFile(self, filepath = None):
  3081         if not filepath and self.FilePath == "":
  3082         if not filepath and self.FilePath == "":
  3082             return False
  3083             return False
  3083         else:
  3084         else: