[Paraview] Error dialogs in python shell plugin

m.c.wilkins at massey.ac.nz m.c.wilkins at massey.ac.nz
Wed May 26 18:37:15 EDT 2010


Hi,

Following up on my own post here...

> I would like to popup a dialog box when there is an error in the
> plugin.  How can I do that?  If the user doesn't have the python shell
> open, they can't even see the output of a print statement.

This I can do now using the advice from Pat (in previous posting which
I can't link to right now since it isn't archived, but the subject was
"Getting user input while in python shell plugin").  I just import
PyQt4.QtGui and go from there.

> Secondly how can one gracefully end a python shell plugin?   A
> sys.exit() just kills paraview since the plugin is running in the
> same process I guess.  Throwing an exception is OK if the user has the
> python shell open, otherwise it is just a silent failure.

So the failure won't be silent now, since I can popup a warning or
error box, then I can just raise an exception to stop execution.  For
completeness here we go:

import PyQt4.QtGui

# this is a dummy widget to use as the parent for other widgets that need a parent
wid = PyQt4.QtGui.QWidget()

# get some user input
ret = PyQt4.QtGui.QInputDialog.getText(wid, 'hi', 'first question')

# do some other stuff

# oh dear a warning
ret = PyQt4.QtGui.QMessageBox.warning(wid, 'hi', 'there was a recoverable problem', PyQt4.QtGui.QMessageBox.Abort, PyQt4.QtGui.QMessageBox.Retry, PyQt4.QtGui.QMessageBox.NoButton)

if ret == PyQt4.QtGui.QMessageBox.Abort:
   raise ValueError, "pooed out"
else:
   ret = PyQt4.QtGui.QInputDialog.getText(wid, 'hi', 'second question')


Matt




More information about the ParaView mailing list