--- a/PLCControler.py Fri Sep 27 09:32:39 2013 +0900
+++ b/PLCControler.py Sat Sep 28 15:59:50 2013 +0900
@@ -844,8 +844,10 @@
Adds the POU defined by 'pou_xml' to the current project with type 'pou_type'
'''
try:
- new_pou = LoadPou(pou_xml)
+ new_pou, error = LoadPou(pou_xml)
except:
+ error = ""
+ if error is not None:
return _("Couldn't paste non-POU object.")
name = new_pou.getname()
@@ -2207,10 +2209,10 @@
new_id = {}
try:
- instances = LoadPouInstances(text.encode("utf-8"), bodytype)
- if len(instances) == 0:
- raise ValueError
+ instances, error = LoadPouInstances(text.encode("utf-8"), bodytype)
except:
+ instances, error = [], ""
+ if error is not None or len(instances) == 0:
return _("Invalid plcopen element(s)!!!")
exclude = {}
@@ -2285,24 +2287,25 @@
instance.translate(*diff)
return new_id, connections
-
+
+ # Return the current pou editing instances idx
+ def GetEditedElementInstancesIds(self, tagname, debug = False):
+ element = self.GetEditedElement(tagname, debug)
+ if element is not None:
+ return element.getinstancesIds()
+ return []
+
# Return the current pou editing informations
- def GetEditedElementInstanceInfos(self, tagname, id = None, exclude = [], debug = False):
- infos = {}
- instance = None
+ def GetEditedElementInstanceInfos(self, tagname, id, debug = False):
element = self.GetEditedElement(tagname, debug)
if element is not None:
- # if id is defined
- if id is not None:
- instance = element.getinstance(id)
- else:
- instance = element.getrandomInstance(exclude)
- if instance is not None:
- infos = instance.getinfos()
- if infos["type"] in ["input", "output", "inout"]:
- var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug)
- infos["specific_values"]["value_type"] = var_type
- return infos
+ instance = element.getinstance(id)
+ if instance is not None:
+ infos = instance.getinfos()
+ if infos["type"] in ["input", "output", "inout"]:
+ var_type = self.GetEditedElementVarValueType(tagname, infos["specific_values"]["name"], debug)
+ infos["specific_values"]["value_type"] = var_type
+ return infos
return None
def ClearEditedElementExecutionOrder(self, tagname):
@@ -3063,10 +3066,9 @@
return tasks_data, instances_data
def OpenXMLFile(self, filepath):
- #try:
- self.Project = LoadProject(filepath)
- #except Exception, e:
- # return _("Project file syntax error:\n\n") + str(e)
+ self.Project, error = LoadProject(filepath)
+ if self.Project is None:
+ return _("Project file syntax error:\n\n") + error
self.SetFilePath(filepath)
self.CreateProjectBuffer(True)
self.ProgramChunks = []
@@ -3075,7 +3077,7 @@
self.CurrentCompiledProject = None
self.Buffering = False
self.CurrentElementEditing = None
- return None
+ return error
def SaveXMLFile(self, filepath = None):
if not filepath and self.FilePath == "":