[IPython-dev] Comments on IPython Qt widgets

Brian Granger ellisonbg at gmail.com
Mon Feb 7 23:15:38 EST 2011


Charlie,

> I was playing around with the new Qt  widgets in 0.11-dev the other day and
> was very impressed.  I tried throwing together a quick plugin to add an
> IPython console to the Qt-based program Quantum GIS [QGIS][1].  Creating the
> plugin was easy enough as QGIS runs an embedded Python interpreter and
> exposes a lot of PyQt4 functionality.  However, I noticed a couple of things
> and was wondering if anyone on this list had any comments to share:
>
> - The shell is based on a stripped down version of `ipython-qtconsole` and
> works but is very, very slow for some reason.  The is a delay of a couple of
> seconds between when an action is triggered and a response comes back to the
> terminal.  The only guess I have that may explain this behavior is that QGIS
> is a C++ application that embeds a Python interpreter whereas
> ipython-qtconsole is a pure PyQt4 program.  Perhaps QGIS is not letting the
> Python threads run as often as a pure PyQt4 program would.
> This could be a QGIS-specific problem, but I was wondering if anyone else
> had the chance to run the IPython Qt widget in an embedded interpreter and
> noticed similar results?

In general the ipython-qtconsole should be quite fast.  But for that
to be the case, the qt event loop has to be running.  If the C++ is
not letting the qt event loop run often enough, you would definitely
see quite slow behavior.

> - Currently, the only IPython kernel available for use with the Qt widget
> runs the IPython interpreter in a separate process.  For QGIS, it would be
> very nice to have the option of running an IPython kernel inside the same
> process as the Qt widgets.  IPython would then have direct access to the
> QGIS interface and would be able to inspect and operatie on the PyQt4
> objects that compose the GUI providing a powerful tool for users performing
> spatial analysis and developers building plugins.
> Are there any plans to develop IPython kernels that do not run
> in separate processes?  I spent a few days trying to build one myself by
> wrapping an InteractiveShell, but I feel like I am flailing a little bit
> when it comes to creating a kernel_manager that will integrate with the Qt
> frontend.  If anyone has any design advice on how to implement an in-process
> kernel I would love to hear it.

There is interest in having an in process IPython, but I honestly
think it will not work very well at all.  This is mostly because of
the GIL.  I would simply turn the model inside out.  If you run the
QGIS code that has all the PyQt widgets in the IPython kernel (start
the kernel with the pyqt event loop running using --pylab qt) your
ipython session will have all the access that it needs.  IOW, don't
embed IPython in your app, embed your app in IPython.  If this model
doesn't work for you, we can talk more about how to get started on an
in process IPython widget, but it will be a significant amount of work
I'm afraid.

> The plugin is available on [GitHub][2] under the tag `0.1` if anyone feels
> interested in checking it out as an IPython use case.  The 0.1 version is
> really quite simple---about 5-10 lines in console.py that do the actual
> implementation.  To use:
>   - Install QGIS
>   - Clone project as a sub-directory of ~/.qgis/python/plugins/
>   - Run `make` (runs PyQt4 dev tools on ui and qrc files)
>   - Launch QGIS and enable Plugin through Plugins -> Manage Plugins menu
>
> Keep up the good work on IPython development!

Thanks!

Brian

> -Charlie
> [1]: http://www.qgis.org
> [2]: http://www.github.com/Sharpie/qgis-ipython/tree/0.1
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the IPython-dev mailing list