Sponsored Link •
|
Summary
A client has expressed interest in using the cross-platform Qt GUI library, in particular with the PyQt bindings, so I began exploring it and the tools that are available, including BlackAdder, which is recommended in the book "GUI Programming with Python: Using the Qt Toolkit" by Boudewijn Rempt.
Advertisement
|
You can find a version of the book online Here. Paper copies may be out of print; I ended up buying mine through Amazon's used book marketplace.
I think Qt is very well done. The components and GUI layout tools are written in C++. The idea is that they work on most platforms, and run very fast. And Twisted, for example, provides direct support for interfacing to PyQt GUIs.
The cleverest part of Qt is probably the "signals and slots" design. Each component has a number of signals that it produces (based on the typical events that most GUI components generate, regardless of what kind of GUI framework you use). You decide what signal you're interested in -- for example, 'clicked()' for a QButton, and you connect it to a slot, which is the function that you want called when the signal happens. The code might look like this:
self.connect(self.button, SIGNAL( "clicked()" ), self.doButtonAction)
where doButtonAction() is a method in the class that you want to be called when the button is pressed. I find this approach simple, elegant, and easy to understand and remember.
The PyQt bindings were written by Phil Thompson and provide a Python interface to the Qt library. For building PyQt systems, I really like the idea of BlackAdder, but the implementation is very unfortunate.
Just installing it was problematic; if you follow the normal installation instructions it claims to install fine, but then when you start the application it says "Python is not installed" (even though it is). I tried emailing the president of TheKompany, since I couldn't find any other way to get support (for a product I had paid for). Finally I looked on their support board, and one user explained that you had to have both Python 2.4 AND Python 2.3 installed, then when BlackAdder came up you had to go in and adjust a setting to use Python 2.4, and also the right version of PyQT (which you could download from TheKompany site, but which wasn't automatically installed when you ran the BlackAdder installer).
Once it was working, I started experimenting with the building tools. The GUI builder is called Qt Designer, and is not made by TheKompany, but rather TrollTech, and you can download this and use it for free (but with some kind of licensing restrictions that were not clear). BlackAdder automatically invokes Qt Designer when you want to create a GUI form. Qt Designer is very slick and well done, and produces an XML file which describes your form layout. There's a second tool, also free and not made by TheKompany, called pyuic. This can also be invoked from BlackAdder to produce the Python code that corresponds to the form you just laid out.
It's very convenient to have the programming environment invoke these tools for you, and it's a lot of what makes BlackAdder attractive. But I'll emphasize that you can use Qt Designer and pyuic without buying BlackAdder. In addition, the Qt documentation appears to be something you can separately download, although again it is something that BlackAdder integrates.
There's a short document that introduces BlackAdder, the most important part of which walks you through a "hello-world" type of process so you can build your first app using BlackAdder and PyQt. Unfortunately, the code in their document is wrong (both syntax and semantic errors), so I had to figure out how to change the code to make the example work.
So at this point I'm starting to get the distinct feeling that the folks at TheKompany are either not at home, working on something else (there's mention of Ruby on their website, so perhaps they've all fallen into the well of fascination with that language and stopped fixing the bugs in BlackAdder), or that they just don't care about the quality of their products. I didn't hear back from the president (I'm told I have some name recognition in the Python community so I would have thought I might have heard something).
But here's the real corker. You have to subclass the file that pyuic creates (if you modify it, you run the risk of overwriting it during a regeneration). BlackAdder does part of this for you, which is nice, and this creates a new file (it also generates a "main" for you). But while I'm adding code to this file, I have to switch back to the generated form to see what my elements are called. But when I switch back to the new file, it has ERASED SOME OF THE CODE that I just typed in! I thought maybe it was erasing back to the last save point, but it turns out it doesn't matter if you save it or not, if you switch to a different source code file and come back, chances are it will have erased some of your code. This was not a chance occurrence; it does it regularly.
BlackAdder also ignores the directory where you tell it to put projects; instead it puts them in the directory above. But that's small potatoes compared to ERASING YOUR CODE!
What's amazing to me is that all of these bugs are things that the first-time user encounters right away. But in particular, the code-erasing bug means to me that these people aren't using their own product. I find it kind of unbelievable that they are charging for a tool like this, when creators of free products (for instance, SPE) can manage to build a tool that, just for example, doesn't ERASE YOUR CODE! It's not what I've come to expect from the people in the python community.
Despite that, even if they don't give me my money back, I could still see using the broken version of BlackAdder that I have, but obviously very carefully so I don't lose code. As long as I use BlackAdder only to do its various code-generation tricks and then immediately save and quit (so it doesn't ERASE ANY CODE!), then do the rest with a normal editor, then it will cut a little bit of time off my development.
I hope that someone can tell me about some other tool out there to help in the creation of PyQt programs. If there aren't others, then I would suggest using the free Qt Designer and puic tools rather than ever spending any money with TheKompany. (Here is a tutorial by Jonathan Gardner showing how to do just that). TheKompany is going to have to bend over backwards to show they've mended their ways before I would ever consider buying anything from them again.
Have an opinion? Readers have already posted 15 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Bruce Eckel adds a new entry to his weblog, subscribe to his RSS feed.
Bruce Eckel (www.BruceEckel.com) provides development assistance in Python with user interfaces in Flex. He is the author of Thinking in Java (Prentice-Hall, 1998, 2nd Edition, 2000, 3rd Edition, 2003, 4th Edition, 2005), the Hands-On Java Seminar CD ROM (available on the Web site), Thinking in C++ (PH 1995; 2nd edition 2000, Volume 2 with Chuck Allison, 2003), C++ Inside & Out (Osborne/McGraw-Hill 1993), among others. He's given hundreds of presentations throughout the world, published over 150 articles in numerous magazines, was a founding member of the ANSI/ISO C++ committee and speaks regularly at conferences. |
Sponsored Links
|