advertisement

Print

Boudewijn and Cameron Argue for Qt
Pages: 1, 2, 3

Thomas: Hmmm. Well, maybe ... Suppose I do decide to go cross-platform; shouldn't I use Tkinter?

The IDEL treeview

The IDLE treeview.

Boudewijn: You could. It's quite good ... But maybe just a little old-fashioned. It's simply missing several of the features I know you'll expect. If you want to use a treeview, you have to construct one yourself. Look at the IDLE (IDLE is the Tkinter development environment written in and bundled with the standard Python distribution) treeview, for example -- they're still working the bugs out of that one, and it's currently at about 500 lines of code.



I will say this, though: Whatever toolkit you choose, buy Grayson's Python and Tkinter Programming. It's a delight to read, and handles all aspects of GUI design.

Thomas: I've looked a bit at the market for Linux, and Gnome sounds good. So shouldn't I develop two version of my apps, one for Windows and one for Gnome?

Boudewijn: You might like Gnome -- but will your users? Not everyone is drawn to the dark side of interface design. What I mean is that the Gnome people designed for looks and theme-ability before they tried to achieve stability and functionality. Standard Gnome looks cool, but not very businesslike.

Cameron: I like the Gnome guys: They're imaginative and energetic. They're just not done, though. Qt is far more mature. GTK (Gnome's toolkit) copies Qt's signals and slots mechanism, but really doesn't do it as well.

Thomas: What's this stuff about the license? I just read that I've got to pay an enormous amount of money for the Windows version of PyQt! That's not open source!

Boudewijn: That's not entirely correct. To generate a PyQt application for Windows, you do need to buy a developers license of the main Qt library for Windows. That'll set you back $1550 USD.

PyQt itself is free. In fact, if you want to distribute a compiled version of PyQt for Windows with a Qt run-time dll, there's nothing to stop you. Be the first to sell a commercial Python/Qt development environment for Windows!

As for open source, you're half-right. You can't use Qt for free on Windows, but the Unix/X11 license is certified Open Source TM.

Thomas: Why are we even talking about PyQt? Qt itself is starting to interest me, but PyQt is only version 0.12. That's deep alpha -- as steady as strawberry jelly!

Cameron: Phil (Thompson, the originator and maintainer of PyQt) counts differently than most of us. For him, version 0.10 followed 0.9. Anyway, beyond that, he's careful with the software he puts out. You can trust PyQt. It's stable.

Boudewijn: It's very, very stable. There are bugs, of course, but they are quickly fixed. In over a year of PyQt development, I've had one serious problem that took a while to fix -- and I could still work around that one.

Thomas: KDE doesn't run on Windows, though, right? What's the point of using Qt then?

Cameron: This takes some explanation. "KDE" means about four different things. The acronym is for "desktop environment," which is what Unix people used to call a "window manager," plus more. KDE is also an application development framework and an office application suite. KDE stuff is all built with Qt -- as the KDEers explain their decision, "It's the best toolkit for Unix."

Boudewijn: It is a bit complicated. Qt itself is available both for Windows and for Unix/X11. So's PyQt. Apps written in PyQt run unmodified on both platforms, too. However, if you want nice KDE extensions, like extra-de-luxe widgets, components, or integration with the KDE desktop, you have to use a second set of bindings: PyKDE. PyKDE depends on PyQt.

Cameron: ... which is fine, of course. PyKDE needs the full KDE API (application programming interface), though, so PyKDE only works where you have KDE, which means only for Unix with X11.

Boudewijn: What's nice is that it's quite easy to write an app that integrates with KDE when it's available, but degrades gracefully to pure Qt if KDE isn't present. I can show you how.

#!/usr/bin/env python
import sys, os

from qt import *

try
  from kdecore import *
  from kdeui   import *
  Application=KApplication
  Mainwin=KTMainWindow
except ImportError:
  Application=QApplication
  MainWin=QMainWindow

class MainWindow(MainWin)
  def __init__(self, *args):
    apply(MainWin.__init__,(self,)+ args)
    ....

def main(argv):

  app=Application(sys.argv, "kpybrowser")
  appwin=MainWindow()
  appwin.show()

  return app.exec_loop()

if __name__=="__main__":
  main(sys.argv)

Pages: 1, 2, 3

Next Pagearrow