Friday, October 3, 2008

Rapid GUI prototyping with Python and Qt

I have recently worked with Qt which is a cross-platform application framework. Applications and user interfaces created with Qt can be deployed on many desktop and embedded environments without the need to rewrite the source code.

Qt is most notably used in KDE (K Desktop Environment) which has been built on top of it. Qt is also used in such applications as Skype, Google Earth and Photoshop Elements. What makes Qt even more interesting for the embedded devices is that Nokia acquired Trolltech, the company behind Qt, at the beginning of 2008. But that is a whole another story.

I have also had a look at Python. Python is a high-level, interpreted, object-oriented programming language. Actually it supports imperative and functional paradigms as well but I wanted to mention object-oriented specifically. I was amazed at how easy it was to learn Python when you already know languages like C++ or Java.

Python is suitable for rapid application development because it has rapid spelled all over it:
  • very readable and simple core syntax
  • large and comprehensive standard library
  • fully dynamic type system
  • automatic memory management with garbage collection

"Great," you think, "that's all nice and dandy but what is it all good for?"

Here is where Python bindings for Qt come in. PyQt exposes much of the functionality of Qt to Python. It is also possible to generate Python code from GUI designs created with Qt Designer. This makes PyQt very useful as a rapid prototyping tool for applications that will eventually be implemented in C++ because the user interface designs can be re-used without modification. With Python you can setup your application within a minute. You also avoid the need to re-compile after each change you have made since Python is interpreted.



The best part about using PyQt and Qt Designer together is that you don't necessarily have to be a programmer to test these things out. You can create your GUI design in Qt Designer, convert your work into a Python script and just run it. It happens too often that the "prototype" ends up being the basis for the actual application. Breaking the GUI design further away from the actual implementation makes it easier to discard those prototypes.

No comments: