# HG changeset patch # User etisserant # Date 1204035390 -3600 # Node ID e3d47b4bbd5da7751e45ee9a078838018e52e164 # Parent 5068ba721506ede04f1f179d5635da5c01198ae8 Better PLCGenerator exception filtering diff -r 5068ba721506 -r e3d47b4bbd5d PLCControler.py --- a/PLCControler.py Tue Feb 26 15:15:27 2008 +0100 +++ b/PLCControler.py Tue Feb 26 15:16:30 2008 +0100 @@ -414,10 +414,10 @@ programfile.write(program) programfile.close() self.ProgramFilePath = filepath - return True - except: - pass - return False + return None + except PLCGenException, e: + return e.message + return "No project opened" #------------------------------------------------------------------------------- # Project Pous management functions diff -r 5068ba721506 -r e3d47b4bbd5d PLCGenerator.py --- a/PLCGenerator.py Tue Feb 26 15:15:27 2008 +0100 +++ b/PLCGenerator.py Tue Feb 26 15:16:30 2008 +0100 @@ -37,6 +37,9 @@ datatypeComputed = {} pouComputed = {} +class PLCGenException(Exception): + pass + def ReIndentText(text, nb_spaces): compute = "" lines = text.splitlines() @@ -114,7 +117,7 @@ if pou_type in pouTypeNames: pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type]) else: - raise ValueError, "Undefined pou type" + raise PLCGenException, "Undefined pou type" pou_program.GenerateInterface(pou.getinterface()) pou_program.GenerateConnectionTypes(pou) pou_program.GenerateProgram(pou) @@ -538,7 +541,7 @@ expression = self.ComputeFBDExpression(body, connections[0], order) self.ComputedConnectors[name] = expression return expression - raise ValueError, "No connector found" + raise PLCGenException, "No connector found" def GenerateLDPaths(self, connections, body): paths = [] diff -r 5068ba721506 -r e3d47b4bbd5d PLCOpenEditor.py --- a/PLCOpenEditor.py Tue Feb 26 15:15:27 2008 +0100 +++ b/PLCOpenEditor.py Tue Feb 26 15:16:30 2008 +0100 @@ -703,8 +703,8 @@ filepath = dialog.GetPath() if os.path.isdir(os.path.dirname(filepath)): result = self.Controler.GenerateProgram(filepath) - if not result: - message = wx.MessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR) + if result is not None: + message = wx.MessageDialog(self, "Can't generate program to file %s :\n%s"%(filepath, result), "Error", wx.OK|wx.ICON_ERROR) message.ShowModal() message.Destroy() else: