[Paraview] Getting user input while in python shell plugin

m.c.wilkins at massey.ac.nz m.c.wilkins at massey.ac.nz
Thu May 27 17:51:24 EDT 2010


Hi,

Thank you both Pat and Utkarsh.

QApplication.activeWindow() appears to just work fine at finding the
main window.  As a fall back looping through
QApplication.topLevelWidgets() and doing a check like this:

   isinstance(wid, PyQt4.QtGui.QMainWindow) and re.search('kitware paraview', wid.windowTitle(), re.IGNORECASE)

works OK too (obviously I'm making an assumption about the title).

Thanks again

Matt Wilkins

On Thu, May 27, 2010 at 10:33:31AM -0400, Utkarsh Ayachit wrote:
> Doh! didn't realize you were going to call it from python. Stick with
> what Pat suggested :).
> 
> Utkarsh
> 
> On Thu, May 27, 2010 at 10:18 AM, pat marion <pat.marion at kitware.com> wrote:
> > Paraview doesn't have a way to pass pointers to QObjects from c++ to python,
> > or vice versa.  You can use PyQt wrapped methods to search for named widgets
> > though.
> >
> > Pat
> >
> > On Thu, May 27, 2010 at 8:52 AM, Utkarsh Ayachit
> > <utkarsh.ayachit at kitware.com> wrote:
> >>
> >> Alternatively use: pqCoreUtilities::mainWidget() -- it tries to find
> >> an active mainwindow by default.
> >>
> >> Utkarsh
> >>
> >> On Wed, May 26, 2010 at 7:09 PM, pat marion <pat.marion at kitware.com>
> >> wrote:
> >> >>> The only thing I couldn't immediately figure out from that post, was
> >> >>> what
> >> >>> to do with widgets that need a parent
> >> >
> >> > You could use QApplication.activeWindow(), you might get the mainwindow
> >> > or
> >> > python dialog.  Or you could cycle thru the list of
> >> > QApplication.topLevelWidgets() to look for the paraview mainwindow.
> >> >
> >> > Pat
> >> >
> >> > On Wed, May 26, 2010 at 6:27 PM, <m.c.wilkins at massey.ac.nz> wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> On Wed, May 26, 2010 at 11:18:29AM -0400, pat marion wrote:
> >> >> > If you want to use PyQt4, see
> >> >> > http://paraview.markmail.org/message/6h767kpak5dcoqwt
> >> >>
> >> >> Thank you, this is what I needed, good stuff.  The only thing I
> >> >> couldn't immediately figure out from that post, was what to do with
> >> >> widgets that need a parent, because I couldn't get hold of the main
> >> >> paraview window widget.  Anyway this is what I did:
> >> >>
> >> >> ---
> >> >> 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.Ok, PyQt4.QtGui.QMessageBox.NoButton,
> >> >> PyQt4.QtGui.QMessageBox.NoButton)
> >> >>
> >> >> # maybe get some more input
> >> >> ret = PyQt4.QtGui.QInputDialog.getText(wid, 'hi', 'second question')
> >> >> ---
> >> >>
> >> >>
> >> >> Thanks
> >> >>
> >> >> Matt
> >> >>
> >> >>
> >> >
> >> >
> >> > _______________________________________________
> >> > 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