Adding message dialog for PLCOpen XML syntax errors.
authorlaurent
Wed, 19 May 2010 22:16:29 +0200
changeset 500 b3499ff87178
parent 499 cecb4369fa42
child 501 edfa63d3c26d
Adding message dialog for PLCOpen XML syntax errors.
PLCControler.py
PLCOpenEditor.py
--- a/PLCControler.py	Mon May 10 21:36:11 2010 +0200
+++ b/PLCControler.py	Wed May 19 22:16:29 2010 +0200
@@ -2562,7 +2562,10 @@
         self.Project = plcopen.project()
         for child in tree.childNodes:
             if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "project":
-                self.Project.loadXMLTree(child, ["xmlns", "xmlns:xhtml", "xmlns:xsi", "xsi:schemaLocation"])
+                try:
+                    result = self.Project.loadXMLTree(child, ["xmlns", "xmlns:xhtml", "xmlns:xsi", "xsi:schemaLocation"])
+                except ValueError, e:
+                    return _("Project file syntax error:\n\n") + str(e)
                 self.SetFilePath(filepath)
                 self.Project.RefreshElementUsingTree()
                 self.Project.RefreshDataTypeHierarchy()
--- a/PLCOpenEditor.py	Mon May 10 21:36:11 2010 +0200
+++ b/PLCOpenEditor.py	Wed May 19 22:16:29 2010 +0200
@@ -2504,12 +2504,15 @@
     def __init__(self, parent, fileOpen = None):
         IDEFrame.__init__(self, parent)
         
+        result = None
+        
         # Open the filepath if defined
         if fileOpen is not None and os.path.isfile(fileOpen):
             # Create a new controller
             self.Controler = PLCControler()
-            self.Controler.OpenXMLFile(fileOpen)
-            self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+            result = self.Controler.OpenXMLFile(fileOpen)
+            if result is None:
+                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
         
         # Define PLCOpenEditor icon
         self.SetIcon(wx.Icon(os.path.join(CWD,"Images", "poe.ico"),wx.BITMAP_TYPE_ICO))
@@ -2517,6 +2520,9 @@
         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
         
         self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+        
+        if result is not None:
+            self.ShowErrorMessage(result)
 
     def OnCloseFrame(self, event):
         if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
@@ -2595,16 +2601,23 @@
             directory = os.path.dirname(filepath)
         else:
             directory = os.getcwd()
+        
+        result = None
+        
         dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
         if dialog.ShowModal() == wx.ID_OK:
             filepath = dialog.GetPath()
             if os.path.isfile(filepath):
                 self.ResetView()
                 self.Controler = PLCControler()
-                self.Controler.OpenXMLFile(filepath)
-                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                result = self.Controler.OpenXMLFile(filepath)
+                if result is None:
+                    self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
         dialog.Destroy()
+        
+        if result is not None:
+            self.ShowErrorMessage(result)
     
     def OnCloseProjectMenu(self, event):
         if not self.CheckSaveBeforeClosing():