Friday, December 03, 2004

RAD with Python, wxPython and Boa constructor - Part 2

Here's the second essay in a three part series on using Python, wxPython and Boa Constructor to rapidly develop cross-platform desktop applications.

But first, some clarification!

  • The Mystery of the Disappearing Post - Part 1 of this essay pulled a Houdini and mysteriously disappeared a day after it was posted. No other post was affected. I've contacted Blogger.com support but I'm pretty sure that it's gone forever.
Since it seems we'll have to do with just part 2 and 3 of a three part piece, lets get on with it...

wxPython is just a thin wrapper around another library, wxWidgets. wxWidgets is an open source GUI framework written in C++ and is cross-platform from the ground up. It works reliably on various flavours of Unix and Windows and is generally usable on the Mac. Support for other platforms like PDA's etc. is under development.

Unlike good ol', butt-ugly Tk, wxWidgets gives you a native look and feel on every platform it runs on. User's can't tell the difference between something written in wxWidgets and another application written in MFC, for example. Both will look the same.

wxWidgets is fast, stable, well-documented and under active development. It's also free (in both senses of the word). This applies to its Python wrapper, wxPython as well.

Some of the major pluses of using wxWidgets/wxPython are:

  1. Free! - I'm a sucker for free stuff. Especially good quality free stuff. The nearest thing to wxWidgets is Qt, and that costs big $$$$'s.
  2. Full-Featured - wxPython is not just a GUI toolkit, it also gives you classes to handle network programming, threads and processes, image manipulation, Databases, Printing etc. This cuts down on the number of dependencies your application has.
  3. Native Look and Feel - I've already mentioned this once, but it's important enough to bear repeating. With wxPython, your apps look like everybody else's. Many cross-platform toolkits have their own look and feel (TK comes to mind) and this tends to confuse and put off users. Others emulate the native design and just end up looking cheap. With wxPython, no one can tell that you took the easy way out! ;-P
  4. Documentation - The documentation for wxWidgets is very complete. Unfortunately, wxPython uses the documentation of wxWidgets without any changes. This can be a bit irritating since wxWidgets is written in C++ and the docs reflect that. However, if you have even a very passing familiarity with C++ (and who doesn't?), it's enough to use the docs.
  5. Demo Code - I really like this bit. wxPython comes with a very large collection of well-organised demos. These are simple, relatively small scripts that demonstrate the various widgets available. A great resource to learn from and an even better one to steal code from! ;-)

These were the features that I particularly liked. Go here to see even more reasons for using this great toolkit!

Just about everything has it's flaws and wxPython is no exception:

  1. Steep Learning Curve - wxPython is very well documented... but there's very little to get you started. The few tutorials that exists just barely get you off the ground. The only real way to learn wxPython is to start up the demos, play around with them and spend a lot of time reading their code. It's not an app killer, but it's definitely something that'll put off quite a few beginners.
  2. Documentation - There's lots of docs for wxWidgets, but none absolutely for wxPython! wxPython is just a wrapper around wxWidgets, but it's irritating to have to mentally switch between thinking in Python and thinking in C++ every time you look up the docs.
  3. Large Distribution - If, like me, you're going to be distributing your application as an .EXE (after converting it using py2exe), the size of the accompanying libraries can be a hassle. A "hello world" app is going to go from a 10-15 byte .py script to a 2.5+ Megabyte distribution! If your users are going to be downloading your product, this might be a problem!
  4. Verbose - Damn but you've got to write a lot of code to get anything done!

Anyway, that's all for now. Next time Inshallah, I'll cover Boa Constructor, which helps alleviate the code verbosity problem.

You can also check out Pythoncard. It's a wrapper around wxPython (which is itself a wrapper around wxWidgets (which is itself a wrapper...!)) and it makes writing wxPython apps a breeze. It's still under development and I wouldn't suggest it for a commercial app just yet. But it's definitely something to keep an eye on.

Till next time then!

No comments: