Monday 29 November 2010

Adding a GUI to a Python script

We can quite easily add a GUI to a Python script by using the PyQt module (http://wiki.python.org/moin/PyQt ).

As an example, I use a command-line script described in a previous post (in Italian): La pendenza topografica lungo direzioni variabili (http://gisoftw.blogspot.com/2010/06/la-pendenza-topografica-lungo-direzioni.html). This script calculates the directional slope of a DEM along orientations defined in an accompanying grid. These orientations typically vary in space and can represent for instance wind directions or glacial flows.

A more recent version of this script has also a GUI, obtained by changing just a few tens of code lines and without the need of Qt Designer (http://qt.nokia.com). In this last version, the GUI manages the definition of the input files and calculates the output slope grids according to two methods: a central differences method and Horn (1981) method. One can look at http://www.malg.eu/opensoftware/dem/directionalslope.php for additional details, download and a case study.

A valuable book for learning GUI scripting in Python is Rapid GUI Programming with Python and Qt, by Mark Summerfield (http://www.qtrac.eu/pyqtbook.html ). As a development environment, Python(x,y) (http://code.google.com/p/pythonxy) has all the required dependencies, so that one can start coding GUI without additional installations.

No comments: