[IPython-User] PyOS_InputHook support in pyside?

Brian Granger ellisonbg@gmail....
Mon Aug 22 21:47:36 CDT 2011


You can tap into the input hook stuff using ctypes as we do for the
wxinputhook here:


But, don't implement the logic in the same was we do for Wx.  Wx does
not have the ability to trigger events on general file descriptors, so
the approach we had to use is a bit clunky.   I would check out the
logic that is in pyqt to see the proper way of doing it using Qt
events.  It shoudn't be more than a few lines of code to pull it off.



On Sat, Aug 20, 2011 at 3:34 PM, Christopher Lee-Messer
<chris.leemesser@gmail.com> wrote:
> Hello,
> Thanks for all the great work on pyside.
> I've been using PySide in the latest enthought python distribution
> (7.1-2) and on
> my ubuntu laptop using the pyside PPA. I do interactive signal
> analysis and would
> like to incorporate pyside into my programs along with ipython. One feature that
> is quite nice about Tkinter and PyQt is that you can continue to run
> and interact
> with python at the command line while running gui widgets.
> When I try this from python's interpreter or from ipython (version 0.11) with
> pyside, the interpreter blocks while the gui elements are active. I looked into
> why by digging through the ipython code and it looks like it tries to invoke
> something called QtCore.pyqtRestoreInputHook(). This doesn't exist in PySide.
> Looking at the _tkinter.c code, it seems this is done via python's C-API using a
> pointer, PyOS_InputHook. I'd never heard of it before, but the way it appears to
> work, is that while python is waiting for text input, it calls this function to
> do idle processing--allowing for gui event processing during these idle times.
> I was hoping that PySide could include support for this. Perhaps it already does
> but I didn't find it?
> In an effort to get things working in my use case and to be helpful to the
> greater python/pyside cause, I have been experimenting with a prototype.
> Just as warning, it is written starting from a state of profound ignorance:
> I have only vague memories of Qt's and python's threading model and
> this is first
> use of Qt's QCoreApplication::processEvents() . I've made a couple of
> guesses about what QCoreApplication
> and processEvents did.
> Surprisingly, after some experimentation, my prototype appears to work, at least
> in a few individual cases I've tried.
> My development platform is python 2.7 on linux x86_64 (ubuntu 10.10)
> using pyside
> 1.05. I linked it to Qt 4.7.3 and libpython2.7 but doesn't depend on the pyside
> code, just Qt. If I knew how to use ctypes to access C++ libraries,
> it probably wouldn't even require the compilation step.
> ipython uses git, so I've put the repo at
> http://github.com/cleemesser/qt_pyos_input_hook
> Comments are welcome. However, I don't really have time right now to
> directly contribute to PySide because of my other duties. I did a
> quick look through on shiboken and company and it seemed I was
> unlikely to make it through before I ran out of weekend tim.
> I'm hoping that a PySide wizard might be able to use my code as
> motivation to easily add the equivalent functions directly to PySide
> :-)
> -chris
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

More information about the IPython-User mailing list