[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 17:14:44 EDT 2010


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"





More information about the ParaView mailing list