[Paraview] python plugin custom dialog causes paraview to hang

m.c.wilkins at massey.ac.nz m.c.wilkins at massey.ac.nz
Wed Jun 16 18:33:08 EDT 2010


Hi,

I hang my head in shame, I really should have thrown my code into a
nonparaview test app.  I will do that in future.

Pat you simply are the best!  Thank you so much.

The business about self.acceptfoo vs self, acceptfoo arises from my
lack of understanding about the slots/signals in Qt.  I've seen stuff
like:

   QObject.connect(a, SIGNAL("clicked()"), a, SLOT("quit()"))

which indicate you put target object, then the slot, but also stuff
like:

   QObject.connect(a, SIGNAL("clicked()"), self.rejectfoo)

which I guess you use when the target of the signal is not a Qt SLOT
as such.

Anyway, I am very thankful to you Pat, and this list in general.

Matt

On Wed, Jun 16, 2010 at 06:11:01PM -0400, pat marion wrote:
> Hi,
> 
> So at the very end of that email that you linked, I mentioned the problem that
> paraview hangs when it encounters a runtime error, instead of reporting the
> error.  I haven't had the chance to investigate the problem, but it's really
> annoying!
> 
> Anyway, I think your problem is just a few typos... try adding:
> 
> 
> from PyQt4.QtCore import *
> 
> 
> at the top.  Also, you had commas instead of periods in two places:
> 
> foo,input1  --> foo.input1
> self, acceptfoo  --> self.acceptfoo
> 
> 
> I debugged the problems by running your script in regular python.  I commented
> out the callback_wrapper and then just added:
> 
> import sys
> app = QApplication(sys.argv)
> 
> before the main script begins.  Doing it this way made it easy to spot the
> typos.
> 
> 
> Pat
> 
> 
> On Wed, Jun 16, 2010 at 5:14 PM, <m.c.wilkins at massey.ac.nz> wrote:
> 
> 
>     Hi,
> 
>     I am writing a Python plugin, and I want to popup a custom dialog.
>     For simple dialogs I have found:
> 
>       import PyQt4.QtGui
>       l = PyQt4.QtGui.QInputDialog.getText(wid, 'Slice', 'Length')
> 
>     to work fine.  But I need more complicate dialogs.  I just can't get
>     the signals/slots to work.  Yes I have read
> 
>       http://paraview.markmail.org/message/6h767kpak5dcoqwt
> 
>     (thanks Pat), otherwise surely I would not have made it this far!
> 
>     Here is my plugin, and any time I uncomment either of the connect
>     lines, paraview (built from git about a week ago) just hangs.  Without
>     those lines, the dialog doesn't work of course; I can cancel it with
>     the window decorator, but that is it.
> 
>     Thank you for any help, this is beyond me, just reading the definition
>     of callback_wrapper makes my head hurt, I hope it doesn't hurt yours
>     ;-)
> 
>     Matt
> 
> 
>     from PyQt4.QtGui import *
> 
>     def callback_wrapper(func):
>       v = paraview.vtk.vtkObject()
>       def wrap(*args, **kwargs):
>          v._args = args
>          v._kwargs = kwargs
>          v.Modified()
>       def callback(o, e): func(*v._args, **v._kwargs)
>       v.AddObserver("ModifiedEvent", callback)
>       return wrap
> 
>     class MyDialog(QDialog):
> 
>       def __init__(self, *args):
>          QDialog.__init__(self, *args)
> 
>          buttonBox = QDialogButtonBox()
>          okButton = buttonBox.addButton(buttonBox.Ok)
>          cancelButton = buttonBox.addButton(buttonBox.Cancel)
> 
>          label0 = QLabel("Foo", self)
>          self.le0 = le0 = QLineEdit(self)
> 
>          label1 = QLabel("Bar", self)
>          self.le1 = le1 = QLineEdit(self)
> 
>          # either of these lines cause paraview to lock up
>          #QObject.connect(okButton, SIGNAL("clicked()"), self, acceptfoo)
>          #QObject.connect(cancelButton, SIGNAL("clicked()"), self.rejectfoo)
> 
>          layout = QGridLayout()
>          layout.addWidget(label0, 0, 0)
>          layout.addWidget(le0, 0, 1)
>          layout.addWidget(label1, 1, 0)
>          layout.addWidget(le1, 1, 1)
>          layout.addWidget(buttonBox, 2, 0, 1, 2)
>          self.setLayout(layout)
> 
>       @callback_wrapper
>       def acceptfoo(self):
>          self.input0 = self.le0.text()
>          self.input1 = self.le1.text()
>          self.accept()
> 
>       @callback_wrapper
>       def rejectfoo(self):
>          print "Doing reject"
>          self.reject()
> 
> 
>     foo = MyDialog()
>     if foo.exec_():
>       print "OK:", foo.input0, foo,input1
>     else:
>       print "They cancelled"
> 
> 
> 
>     _______________________________________________
>     Powered by www.kitware.com
> 
>     Visit other Kitware open-source projects at http://www.kitware.com/
>     opensource/opensource.html
> 
>     Please keep messages on-topic and check the ParaView Wiki at: http://
>     paraview.org/Wiki/ParaView
> 
>     Follow this link to subscribe/unsubscribe:
>     http://www.paraview.org/mailman/listinfo/paraview
> 
> 


More information about the ParaView mailing list