<div>New (Experimental!) Plugin</div><div>====================</div><div><br></div><div>I just uploaded an alpha version of a plugin that allows an IPython kernel to be integrated into QGIS. This in turn allows external IPython-powered consoles to connect to QGIS and execute commands or inspect data. Version 0.2 of the plugin is now available from PyQGIS and is flagged &quot;Experimental&quot;:</div>


<div><br></div><div>    <a href="http://spatialserver.net/pyqgis_1.0/contributed/ipython_console.zip" target="_blank">http://spatialserver.net/pyqgis_1.0/contributed/ipython_console.zip</a></div><div><br></div><div>I am making the announcement here, because I feel that the current state of the plugin makes it most interesting to developers. I have tested the plugin with QGIS 1.7.0 on OS X 10.6 and Ubuntu 11.4 and it appears to be usable.</div>


<div><br></div><div><div>Bug reports and pull requests are welcomed at GitHub:</div><div><br></div><div>  <a href="https://github.com/Sharpie/qgis-ipython">https://github.com/Sharpie/qgis-ipython</a></div></div><div><br>

</div><div><br></div><div>What is IPython?</div><div>=============</div><div><br></div><div>IPython is a __really__ nice shell for performing interactive work in the Python programming language. Some killer features IPython provides compared to the standard Python console are:</div>

<div><br></div>
<div>  - Tab completion for object and method names.</div><div>  - Function call tips that provide information about arguments on-the fly.</div><div>  - Easy access to docstrings.</div><div>  - &quot;magic&quot; commands that allow users to turn complex function calls into simple, customized command lines.</div>


<div><br></div><div>Additionally, the v0.11 release completely re-factored the project and brought about many exciting changes:</div><div><br></div><div>  - A distributed two-process system where computational kernels handle the details of executing code and may be controlled by one or more console processes that handle the details of sending user input and formatting kernel output.</div>


<div>  - A new PyQt-based console with plenty of neat tricks such as Pygments-based highlighting of source code and inline display of Matplotlib graphs.</div><div>  - A high-level framework for performing parallel computing in an interactive fashion.</div>


<div><br></div><div>For more information about IPython, see:</div><div><br></div><div>  The IPython website:</div><div>    <a href="http://www.ipython.org" target="_blank">http://www.ipython.org</a></div><div><br></div><div>

  The manual section on interactive computing:</div>
<div>    <a href="http://ipython.org/ipython-doc/stable/interactive/index.html" target="_blank">http://ipython.org/ipython-doc/stable/interactive/index.html</a></div><div><br></div><div>  A talk by Fernando Perez at SciPy 2011 which details many features of v0.11:</div>


<div>    <a href="http://www.archive.org/details/Wednesday-203-6-IpythonANewArchitectureForInteractiveAndParallel" target="_blank">http://www.archive.org/details/Wednesday-203-6-IpythonANewArchitectureForInteractiveAndParallel</a></div>

<div>
<br></div><div><br></div><div>How Does the Plugin Work?</div><div>=====================</div><div><br></div><div>The IPython plugin requires following dependencies to be installed:</div><div><br></div><div>  - Python 2.6 or 2.7</div>

<div>  - IPython v0.11 or v0.12-dev</div><div>  - PyZMQ</div><div>  - Pygments</div>
<div>  - Matplotlib</div><div><br></div><div>Unfortunately, Windows users are currently out of luck as QGIS appears to be pinned to the version of Python provided by OSGEO4W which is currently at 2.5.x.</div><div><br></div>


<div>The plugin provides one new entry to the &quot;Plugins&quot; menu called &quot;External IPython Console&quot;. This launches an external process, based on `ipython-qtconsole`, that communicates with an IPython kernel __running inside of QGIS__. This means that every command entered through the console is actually executed inside of QGIS.</div>

<div><br></div><div>The only downside I have noticed to running the console in a process separated from QGIS is that the IPython console window cannot be docked or otherwise integrated into the QGIS GUI.</div><div><br></div>

<div>__IMPORTANT NOTE__</div><div><br></div><div>One currently has to be careful when closing external Python consoles because they can terminate the IPython kernel running inside of QGIS which has the unfortunate side effect of causing QGIS to quit. The recommended way to shut down an external console is to close the window and select &quot;No, just this Console&quot; when asked if you would like to quit the Kernel. Choosing &quot;Yes, quit everything&quot; or running the `exit()` command in the IPython shell will cause QGIS to quit as well.</div>

<div><br></div><div>I am working on finding a way around this issue so that it will be more difficult for users to accidentally terminate QGIS when all they wanted to do was close the IPython console.</div><div><br></div>

<div><br></div><div>Future Directions</div><div>=============</div><div><br></div><div>There are plenty of things that need to be cleaned up in order to achieve a smoother user interface such as better error messages and figuring out how to handle situations where the kernel dies and needs to be restarted.</div>

<div><br></div><div>There are also many exciting possibilities that could be explored such as using the parallel computing framework to build faster tools for GIS analysis or using the IPython communication protocol make it easier for other programs to communicate with QGIS.</div>

<div><br></div><div>If QGIS upgrades to version 2 of the SIP API, another exciting development possibility is to replace the current Python console with an IPython console that does not run in a separate process.</div><div>

<br></div><div>I have done some initial work on this front and managed to get a proof-of-concept build that successfully ran the IPython console:</div><div><br></div><div>    <a href="https://github.com/Sharpie/Quantum-GIS/tree/ipython-console">https://github.com/Sharpie/Quantum-GIS/tree/ipython-console</a></div>

<div><br></div><div>The biggest challenge in upgrading to version 2 of the SIP API appears to finding areas in the Python code where QString methods are used and replacing them with equivalent Python string methods. The branch above is very much an experiment---many things were simply commented out.</div>

<div><br></div><div><br></div><div>-Charlie</div>