Learn KDE Programming with PyQt

Sebastian Kügler has written a new PyQt tutorial. Python is the perfect language to start learning programming with and this tutorial takes you through making a basic Qt based program. He also shows how pyuic from PyKDE Extensions makes it possible to use Qt Designer with Python. Some wise words to new programmers from the tutorial, "use the examples and try to change things, play around with them, this is the best way to get comfortable".

Dot Categories: 

Comments

by Yuko (not verified)

I like PyQT but there is no well integrated in KDevelop.

You have to transform .ui files from Qt Designer to pyqt , to make this you have to use pyuic to make this pyqt file and then edit in KDevelop.

You edit this file and add python code for buttons for example.

The problem is when you change the ui file , to add other button for example , you have to compile this file to a pyqt file and write back all the buttons code that you make in python.

I think if in KDevelop you can make the .ui file , the code of the buttons in python in other file and then if you press compile / execute file , KDevelop can join all code in one file . If the .ui file change don't change all code and you don't have to write back all python code.

by Boudewijn Rempt (not verified)

No! You do not, ever, edit the files generated by pyuic, uic, juic or any other .ui compiler. Include or import the file and subclass the widget you've created, or use it directly, but don't change.ui file by hand.

And if you want an ide specifically tailored to PyQt try Eric3 (or BlackAdder, but that's commercial and not much better than Eric3).

by Simon Edwards (not verified)

Just to expland a little bit on what Boudewijn said. You use pyuic to create your class from your .ui, then you create a subclass of that widget. In the subclass you can add all of the extra behavior, methods, event handlers etc that you need. You application should then just use the subclass. The widget class from pyuic can now be regenerated as much as you like without wiping out your handmade code.

As for invoking pyuic by hand, have a look at http://www.simonzone.com/software/pykdeextensions/ . This provides extra support for KDE applications. Things like handling installation, i18n, and bunch of other odds and ends. The interesting thing is that it also lets you directly import .ui files into python code without having to manually run pyuic everytime that your .ui file changes. You can just change and save your .ui file in Designer, then start your application up again.

--
Simon

by Yuko (not verified)

>>No! You do not, ever, edit the files generated by pyuic, uic, juic or any other .ui compiler. Include or import the file >>and subclass the widget you've created,or use it directly, but don't change.ui file by hand.

How to do this?

by Boudewijn Rempt (not verified)
by Marcio (not verified)

look at the example "gui coding sucks" in the tutorial.

by Pascal Klein (not verified)

For someone like me who has just started to diveintopython.org, this is really very much appreciated. I have often marvelled at some of the powers that Qt offers and since I am starting to have another look at Python, this is definitely something that appeals to me and could allow me to make something useful from the skills I learn.

Thanks for this. Kudos. :)

~Pascal

by mikeyd (not verified)

Gentoo won't install it with anything approaching a modern version of kdelibs installed.

by Roberto Alsina (not verified)

Try the PyKDE from kdebindings, I think that one's supposed to work.

I suspect you get a slightly older PyKDE that works with a newer KDE, if that makes any sense ;-)

by mikeyd (not verified)

That only seems to include the dcop bindings, not the parts that let you make a full application (with widgets etc.)

by Richard Dale (not verified)

Look under kdebindings/python

by Carlo (not verified)

There's no kdebindings package anymore and I was a bit lazy fixing the mess with kdebindings including sip, pyqt and pykde.

http://packages.gentoo.org/search/?sstring=pykde

by Pingveno (not verified)

dev-python/pykde
dev-python/PyQt

by Paul Boddie (not verified)

I had no real luck with the kdebindings version of PyKDE (at least for KDE 3.4). However, recent PyKDE snapshots do work, although some additional patches may be required. I recommend looking at the Ubuntu source packages (which you can find using the package browser at http://packages.ubuntu.com) since some of the necessary patches are included in those archives; look out for python2.4-kde and python2.4-qt along with various sip packages.

by hds (not verified)

i compiled PyKDE from riverbank:
http://www.river-bank.demon.co.uk/download/PyKDE2/PyKDE-snapshot20051013...

works fine with KDE 3.4 and 3.5 on gentoo.

by Daniel Ross (not verified)

There's a masked, but not blocked, version at kde-base/pykde.

by Tiziano (not verified)

LinuxBase has released the first draft of desktop modules
http://www.linuxbase.org/spec/book/Desktop/Desktop.html

by Olaf Jan Schmidt (not verified)

Hi Tiziano!

I can assure you that Qt4 will be a part of 3.0.

The LSB Steering Comittee is currently in the process of changing the license criteria to allow for this, and the discussion how to exactly phrase the new criteria has not been finalized yet. For this reason, Qt4 was missing in LSB 3.0 beta. But the stated intention of LSB Desktop workgroup is to include Qt4 alongside, and there are no objections to this.

The final version of LSB 3.0 will be released in January 2006, and by then all of the LSB websites will hopefully be updated and corrected.

Olaf Jan Schmidt, KDE e.V. representative in the LSB workgroups

by Christian Loose (not verified)

Good to see that there soon will be a solution for the license criteria problem. Although I still think that Alan Cox's proposal (http://mail.freestandards.org/pipermail/lsb-desktop/2005-September/00013...) would be even better. Just IMHO.

by Vlad C. (not verified)

Why not aggregate (or link to) these great tutorials and tools in a location where potential new KDE developers are likely to first look (ie. on the KDE developer website):

http://developer.kde.org/language-bindings/python/

by MandrakeUser (not verified)

Excellent idea. Only problem is how to mantain these link lists (keep them up to date). The other problem is choosing what to put. Sometimes you go to a wiki and get a list of 25 tools to do, say, IM in Linux. But you end up wasting a lot of time, because just two or three of the linked tools are relevant.

What I typically do is google for things. And let the page rank do the job or sorting things out to me. It works, except for very new documents/info ...

I've added a link to the page.

by Vlad C. (not verified)

Great, thanks!

by John Tuymo (not verified)

Could someone please provide a complete working example (a hello world) for the KPanelApplet class, I would really like to be able to make my own python-powered panel applets for KDE.

by Long Pa (not verified)

Ummm... For a dog who is too old to be taught new tricks, is PerlQt a dead animal? I think the last ChangeLog for PerlQt is 2-3 years old. Sorry if I raise any hackles by mentioning such a beast in this thread. Candidly - but not caninely :) Paddy Healy

by Morty (not verified)

I have no clue of it's state but the latest download looks like PerlQt-3.009-b2.tar.gz dated Jul 10, 2005. Not exactly recent, but less than years old:-)
And http://lists.kde.org/?l=kde-bindings&m=112071056609643&w=2

Try the mailinglist for more better information.

by ac (not verified)

How would you go about creating a KDE app that can be controlled simultaneously from the GUI (i.e., the Qt event loop) and an interactive python interpreter? I've seen that IPython allows something similar (see http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner), but there it seems like the main program must be written in Python, or at least started from within a IPython session. Does anyone have any ideas about this?

by jyaan bresy (not verified)

ipython allows you to run existing python code from within the interpreter. it's one of the "magic" functions that come with ipython. this is the usage:

%run appname.py

just launch your application, then continue. note you can use the magic funcs for changing directories also. otherwise you need to type the full path, of course. full help/doc is available through the iterpreter.

and yes i know this post is ancient history, but who knows -- it may end up useful.