The Artima Developer Community
Sponsored Link

Weblogs Forum
PyQt and BlackAdder

15 replies on 2 pages. Most recent reply: Apr 25, 2006 4:49 AM by Baiju M

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 15 replies on 2 pages [ 1 2 | » ]
Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

PyQt and BlackAdder (View in Weblogs)
Posted: Apr 13, 2006 12:40 AM
Reply to this message Reply
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.


Alexander D.

Posts: 1
Nickname: jinks
Registered: Apr, 2006

PyGTK Posted: Apr 13, 2006 2:49 AM
Reply to this message Reply
I don't know PyQT but personally i always disliked QT because of the rather ugly GUI (if you don't use KDE Skins) and the (former?) non-free windows part.

I did some small cross-platform GUI Apps with PyGTK (http://www.pygtk.org/) and glade (which both run fine under Linux and Windows) and I am really happy with the way these two work out...

You can design your GUI with glade and the result sits in an XML file which just must be included via pygtk and gtk.glade. Of course from this moment on you are subject to the GTK callback system which many people dislike just more than I dislike QT ;-)

A short examples how to use GTK from within python:

def __init__(self):
# create widget tree ...
self.App = gtk.glade.XML('pygoogle/pygoogle.glade')
dic = {}
for key in dir(self.__class__):
dic[key] = getattr(self, key)
self.App.signal_autoconnect(dic)
self.App.get_widget('entry1').set_text('python')


This initializes the GUI, gets all the widgets from the XML file and sets a Textfield to use it for a google-API request which will then display its results inside a gtkhtml pane. (That part is obviously missing). Simple, isn't it?

Boudewijn Rempt

Posts: 2
Nickname: boud
Registered: Apr, 2006

Re: PyQt and BlackAdder Posted: Apr 13, 2006 5:09 AM
Reply to this message Reply
The author of the PyQt bindings is Phil Thompson, not Jonathan Gardner. Currently your best bet for working with PyQt is the Eric ide: http://www.die-offenbachs.de/detlev/eric3.html. I like Eric3 much better than Blackadder myself.

The story of my book is a bit sad: the publisher failed to get the book into Amazon, so it sold badly, and it looks like there won't be an updated edition for Qt4. Which is a pity, because Qt4 -- and hence PyQt4 -- is GPL under Windows, OSX and Unix/X11 and really cool.

I've dropped out of the Python world a bit after I became maintainer of Krita, the KOffice paint application but I've still got a soft spot for the language, and especially for PyQt. Together with Qt Designer and Eric3 it's easily the most productive environment I've ever worked in.

Boudewijn Rempt

Paul Drummond

Posts: 1
Nickname: pdrummond
Registered: Apr, 2006

Re: PyQt and BlackAdder Posted: Apr 13, 2006 7:46 AM
Reply to this message Reply
PyQt is an excellent tool but unfortunately Black Adder isn't and hasn't been since its first release.

Although Qt3 is an excellent toolkit, Qt4 makes substantial improvements, not least the ability to use signals and slots between threads. PyQt currently only supports Qt3 but PyQt4 is in development and when that comes out it will take over the world ;)

Michael Levin

Posts: 3
Nickname: mikelevin
Registered: Apr, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 10:54 AM
Reply to this message Reply
There's an article entitled "Build a CD Ripper with Python -
Programming can be fun again", by Shawn Gordon; Oleksandr Yakovlyev in Linuxworld you can find here: http://linux.sys-con.com/read/44913.htm. I hesitated to work through it because of the proprietary components of the article, but it looks helpful.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 11:13 AM
Reply to this message Reply
> The author of the PyQt bindings is Phil Thompson, not
> Jonathan Gardner. Currently your best bet for working
> g with PyQt is the Eric ide:
> http://www.die-offenbachs.de/detlev/eric3.html. I like
> Eric3 much better than Blackadder myself.

That's very useful information, especially from someone who as obviously spent so much time with PyQt; I'll go investigate Eric now... thanks!

> The story of my book is a bit sad: the publisher failed to
> get the book into Amazon, so it sold badly, and it looks
> like there won't be an updated edition for Qt4. Which is a
> pity, because Qt4 -- and hence PyQt4 -- is GPL under
> Windows, OSX and Unix/X11 and really cool.

You should look at your contract. If they fail to update it there may be a reversion of rights clause, in which you get the rights back to the book. Then you could update it yourself and use a print-on-demand service to publish the book.

As I mentioned, the Qt license was a bit uncertain, so GPLing it should help.

Not all GUI kits run under all platforms -- OSX seems to be left out of one or two of them -- and the fact that Qt includes Linux, Windows and Mac is a selling point for me.

> I've dropped out of the Python world a bit after I became
> maintainer of Krita, the KOffice paint application but
> I've still got a soft spot for the language, and
> especially for PyQt. Together with Qt Designer and Eric3
> it's easily the most productive environment I've ever
> worked in.

Well, thanks for writing the book and I do hope you can find a way to update it.

> Boudewijn Rempt

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 11:15 AM
Reply to this message Reply
> Although Qt3 is an excellent toolkit, Qt4 makes
> substantial improvements, not least the ability to use
> signals and slots between threads. PyQt currently only
> supports Qt3 but PyQt4 is in development and when that
> comes out it will take over the world ;)

I didn't know about Qt4, but it's good to know there's active development happening. Concurrency is becoming more important, especially as multicore machines become more common.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 11:19 AM
Reply to this message Reply
I'll second what another poster said and suggest you take a look at Glade and PyGTK. It's at least windows/linux crossplatform, very easy to use, and down the road you won't have to contend with Trolltech over licensing costs if you decide to do something not GPL-compatible.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 1:21 PM
Reply to this message Reply
Well, it's the "at least windows/linux crossplatform" part that holds me back. Once I start thinking that the Mac users aren't important, I'm going to get into trouble.

And there appears to be a Qt3 GPL system available; at least that's what I've installed for use with Eric. And Qt4, as one poster said, will be all GPL.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: PyQt and BlackAdder Posted: Apr 13, 2006 8:22 PM
Reply to this message Reply
> Currently your best bet for working
> g with PyQt is the Eric ide:
> http://www.die-offenbachs.de/detlev/eric3.html. I like
> Eric3 much better than Blackadder myself.

Well, I've spent the good portion of a day installing and reinstalling this to try to get it to work. I'm running Python 2.4.3 and installing Eric 3.8.2. The only support package that I could get to work was PyQTGPL10 (the other one said that it needed Scintilla, which required compiling with MSC which I don't have and seemed kind of crazy anyway).

So if I install PyQTGPL10, then Eric installs and the program comes up and seems to be running properly. But when I create a simple form (and even though I try to do this by adding a new form to the project, the form I create never seems to get added and I have to add it into the project by hand), then tell it to either compile the form, or compile all forms, the program just hangs. When I shut it down it leaves a pythonw process in the background sucking up all the CPU cycles. It does this every time, and I found at least one other report on the internet about this. (and pyuic is in the path).

Am I doing something wrong, or is this not ready for prime time? Or does it simply not run under windows?

Basem Narmok

Posts: 2
Nickname: narm
Registered: Aug, 2005

Re: PyQt and BlackAdder Posted: Apr 14, 2006 8:15 AM
Reply to this message Reply
About 18 projects are joining forces in what they call "Python multiple IDEs Collaboration", eric3 is one of the projects:

http://pyxides.stani.be/

But I don't know what did they achieve till now.

Alexander Dymo

Posts: 2
Nickname: dymo
Registered: Apr, 2006

Re: PyQt and BlackAdder Posted: Apr 14, 2006 7:16 PM
Reply to this message Reply
You may find KDevelop 3.3 or 3.4 IDE useful for PyQt development.
It has same QtDesigner/Python integration as QtDesigner/Ruby as described at http://www.kdevelop.org/doc/technotes/rubyrad.html.
In case it doesn't work for you, I'd be glad to answer questions and fix bugs.

Harry Fuecks

Posts: 875
Nickname: hfuecks
Registered: Sep, 2004

Re: PyQt and BlackAdder Posted: Apr 15, 2006 6:12 PM
Reply to this message Reply
Perhaps there's some reason I've missed but can't understand why anyone would want to consider anything but wxpython - perhaps if you're developing for Linux only, PyGTK makes is more powerful, but can't see any other reason otherwise.

wxpython just grew a book - about 1/3 though reading it and so far it's excellent - http://www.manning.com/rappin/

Otherwise it's worth trying out activegrids IDE ( http://www.activegrid.com/try/opensource.php ) to see the extent of what's possible with wxpython

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

PyQt and Eric3 Posted: Apr 17, 2006 10:28 PM
Reply to this message Reply
I got a reply from Detlev Offenbach about the Eric3 problems I was having:

"This seems to be a problem of qt-win-free. It doesn't happen when using the official version from Trolltech."

This despite the fact that on the Eric3 page:
http://www.die-offenbachs.de/detlev/eric3.html
It says:
"Alternatively, you may use the free packages built with qt-win-free available at http://pythonqt.vanrietpaap.nl/."

So I went to the TrollTech web site and tried to download Qt for Windows. This is a 30-day evaluation, then you have to buy something -- that's for development, and I haven't looked into what it would take to distribute it.

But when I got to the download page, it asked me if I was using Visual Studio 2005, Visual Studio .NET, or Visual C++ 6, none of which I have, so I don't know which one to choose, or if it even matters. The Eric3 web page doesn't seem to give any hints.

I had a separate problem during installation which produced the following output:

"An internal error occured. Please report all the output of the program,
including the following traceback, to eric-bugs@die-offenbachs.de .

Traceback (most recent call last):
File "install.py", line 621, in ?
main(sys.argv)
File "install.py", line 524, in main
from qtext import QextScintilla
RuntimeError: the sip module supports API v1.0 to v1.0 but the qtext module requires API v0.2"

So I followed the instructions and reported it. Detlev replied:

"This is not an eric3 error. Your installation of sip and PyQt do not match. Please get correct versions and try it again."

So it says it's an internal error and to report it, and he says it isn't an error, and I should somehow figure out what or where I've got some other piece of software mis-installed, for which I have little or no clue.

Apparently, based on one of the previous commenters, Qt 4 and PyQt 4 are being written as GPL code (in fact, it seemed like something might be available this month). At that point, perhaps Eric3 (4?) can bundle everything necessary to do a complete install into one package. Right now it's like trying to install early versions of Linux: too many questions and not enough answers.

Fortunately, the consulting client seems to have decided that regular web pages (perhaps with Ajax) will provide a good-enough user interface. So when all the "4" versions of Qt appear, I can have another look and hope that I can successfully install Eric.

ad hd

Posts: 1
Nickname: adhd
Registered: Apr, 2006

Re: PyQt and BlackAdder Posted: Apr 18, 2006 7:29 AM
Reply to this message Reply
> The author of the PyQt bindings is Phil Thompson, not
> Jonathan Gardner. Currently your best bet for working
> g with PyQt is the Eric ide:
> http://www.die-offenbachs.de/detlev/eric3.html. I like
> Eric3 much better than Blackadder myself.
>
> The story of my book is a bit sad: the publisher failed to
> get the book into Amazon, so it sold badly, and it looks
> like there won't be an updated edition for Qt4. Which is a
> pity, because Qt4 -- and hence PyQt4 -- is GPL under
> Windows, OSX and Unix/X11 and really cool.
>
> I've dropped out of the Python world a bit after I became
> maintainer of Krita, the KOffice paint application but
> I've still got a soft spot for the language, and
> especially for PyQt. Together with Qt Designer and Eric3
> it's easily the most productive environment I've ever
> worked in.
>
> Boudewijn Rempt

It's my great honour to sit here and read these words. Your book leads me to this wonderful world of PyQT. All I wanna say is, A wonderful book, an amzing man. Thanks

Flat View: This topic has 15 replies on 2 pages [ 1  2 | » ]
Topic: PyQt and BlackAdder Previous Topic   Next Topic Topic: How Unit Testing and Refactoring Work Together


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us