Executer: Abort, Continue buttons for error messages, too

This commit is contained in:
DeepSOIC 2015-11-03 14:46:49 +03:00
parent 2010121f2e
commit 6d168f31b0

View File

@ -40,11 +40,11 @@ def executeFeature(obj):
FreeCAD.ActiveDocument.abortTransaction() FreeCAD.ActiveDocument.abortTransaction()
raise raise
except Exception as err: except Exception as err:
mb = QtGui.QMessageBox() try:
mb.setIcon(mb.Icon.Warning) error(obj,err.message)
mb.setText("While excuting feature '"+obj.Name+"', an error occured:\n" + err.message) except CancelError:
mb.setWindowTitle("Error") FreeCAD.ActiveDocument.abortTransaction()
mb.exec_() raise
finally: finally:
globalIsCreatingLatticeFeature = False globalIsCreatingLatticeFeature = False
@ -53,14 +53,26 @@ def warning(obj,message):
''' '''
warning(obj,message): smart warning message function. If feature is being warning(obj,message): smart warning message function. If feature is being
created, a warning message pops up. If otherwise, the warning is printed created, a warning message pops up. If otherwise, the warning is printed
into console. to the console/report view.
''' '''
_showMsg(obj, message, _type= u'Warning')
def error(obj,message):
'''
error(obj, message): smart error message function. If feature is being
created, an error message pops up. If otherwise, the error is printed
to the console/report view.
'''
_showMsg(obj, message, _type= u'Error')
def _showMsg(obj, message, _type):
'''showMsg(obj, message, _type): convenience function, contains the shared code of error() and warning()'''
global globalIsCreatingLatticeFeature global globalIsCreatingLatticeFeature
if globalIsCreatingLatticeFeature: if globalIsCreatingLatticeFeature:
mb = QtGui.QMessageBox() mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning) mb.setIcon(mb.Icon.Warning)
mb.setText(u"Warning: \n" + message) mb.setText(_type + u": \n" + message)
mb.setWindowTitle("Warning") mb.setWindowTitle(_type)
btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort)
btnOK = mb.addButton("Continue",QtGui.QMessageBox.ButtonRole.ActionRole) btnOK = mb.addButton("Continue",QtGui.QMessageBox.ButtonRole.ActionRole)
mb.setDefaultButton(btnOK) mb.setDefaultButton(btnOK)
@ -69,10 +81,16 @@ def warning(obj,message):
raise CancelError() raise CancelError()
else: else:
if obj is not None: if _type == 'Warning':
FreeCAD.Console.PrintWarning(obj.Name + ": " + message) printfunc = FreeCAD.Console.PrintWarning
else: else:
FreeCAD.Console.PrintWarning(message) printfunc = FreeCAD.Console.PrintError
if obj is not None:
printfunc(obj.Name + ": " + message)
else:
printfunc(message)
class CancelError(Exception): class CancelError(Exception):
def __init__(self): def __init__(self):