Rapid Application Development using PyQt and Eric3

Tired of long, carefully crafted tutorials trying to show you the quickest way to write a program? Here I take another approach. I just went and did a program and the tutorial while checking the clock. So here you have all three in one:

the app, the tutorial, and the timeline
. :-)

Dot Categories: 

Comments

by Rayiner Hashem (not verified)

That's was pretty damn impressive! Very well-written too. There is a very big potential for Python on KDE. In particular, there is a large domain of applications out there that would be written in Python without problems. You probably wouldn't want to do KHTML in it, because of speed concerns, but what about configuration tools, like RedHat does?

That said, KDE bindings really need to be in the kdelibs distribution. I'm sure lots of people would like to write PyKDE apps, but don't want to burden users with having to install PyKDE itself.

by Ian Reinhart Geiser (not verified)

it will never happen, pyKDE is not part of KDE and is reliant on pyQt outside of KDE. maby if the maintainers worked within KDE it would be better, but that seems that they wouldnt like to do so.

luckly with things like KJSEmbed and awesome ruby support kdebindings will be all users need.

cheers
-ian reinhart geiser

by Phil Thompson (not verified)

As I have said before in this forum, there is no problem with including a copy of PyQt in KDE in exactly the same way as it includes qt-copy. It just needs somebody to actually do it.

Phil

by Wido Depping (not verified)

If more developers would use PyQt or PyKDE, we would see more mature, stable and feature rich applications on linux. And the speed of these programs won't be a big concern. The drawing is done by Qt and if you have performance intensive functions you can still code them in c/c++ and use them from python. But most applications on a desktop don't need that much computing power.

I've heard that the KDE-Debian project will have some administration tools that are based on PyKDE and I think this is a very good decision. :))

by Roberto Alsina (not verified)

Really, installing PyQt qnd/or PyKDE in Debian or Red Hat is very easy.

Both are just an apt-get away :-) (although right now if you jump to latest PyQt you lose PyKDE, but that has a simple solution, don't update yet ;-)

by Rayiner Hashem (not verified)

If (when) Python gets a Parrot port, we'll be able to use Python for pretty much every GUI app, without any performance hit!

by An on (not verified)

/we'll be able to use Python for pretty much every GUI app, without any performance hit!/

Performance hit is minimal in GUI apps anyway. The only hit Py* GUI apps get, really, is the startup time on slow machines.

by Roberto (not verified)

Yes, it takes about 5 seconds to start a pyqt app in my box, while a regular qt app takes 1 or 2.

It´s specially noticeable for the first such app.

by Simon Edwards (not verified)

In my experiance, the impact on startup times is small. Perhaps a second or two extra while all of the libs (Qt+KDE) take 5-10x longer.

It's not worth worrying about. Worry about the KDE libs startup and linking instead. :-)

--
Simon

by David Boddie (not verified)

I like the tabbed views onto the text and final output! The design works a lot better than the "browser above, editor below" design I went for:

http://www.boddie.org.uk/david/Projects/Python/KDE/Images/embedwiki-3.png

I don't know exactly why you say that you "...probably wouldn't want to do KHTML in it, because of speed concerns..." as all the rendering work is done by the library. I interpreted the above as advice against rewriting KHTML in Python, although I wouldn't be surprised if a pure-Python renderer could compete quite well on small documents.

Unfortunately, it's true that installing PyKDE is more effort than most people are prepared to put themselves through. Package maintainers do try hard to provide packages for certain distributions, but some appear to have fallen behind:

http://sourceforge.net/project/showfiles.php?group_id=61057

by Roberto (not verified)

What I *really* wanted was to have the tabs on the right side :-)

Maybe I will switch to a widget stack with a toggle on the toolbar, or something like that, though.

by Datschge (not verified)

Uhm, tabs on the right side like "kdeappname --reverse"? Ok, that's probably too much on the right side. ;P

by Roberto (not verified)

No, more like on the right edge instead of on the top :-)

by Stephan Sokolow (not verified)

For the record, a quick glance at my Gentoo Portage repo seems to indicate that in the time since all this was posted (almost exactly 2 years), PyKDE has become part of KDE proper.

dev-python/pykde stops at version 3.12_pre20051013 and kde-base/pykde exists in versions 3.4.3 and 3.5.0

by standsolid (not verified)

I'm going to say it. The one thing I ache for is a RAD environment (meaning mindless drawing of pushbuttons, double clicking aid button and writing code for what it does). It would be so cool if we had a VB replacement so that I can write some stupid gui app in minutes... especially in python. (/me drools)

...maybe someday...

(please don't suggest qt designer -- I use it and I know it's fantastic, but it's not so easy as point-and-click development)

by Roberto Alsina (not verified)

Except for clicking on widgets to edit their methods (which Designer can't do AFAIK), everything here was drag&drop&click.

Can you give me a little example of what you find easier? Like "on VB.Net I can click here and this happens, while using Eric3+Designer I need to do all these other longer awful things".

by standsolid (not verified)

Well, I stayed away from the whole .NET thing (escaped Windows before then, and refuse to upgrade my VB6 install on vmware)

In VB, I can do an extremely simple project in a few steps

1. In VB -> Start a new project (windows dialog)
2. Select the button widget to draw a button in the middle
3. Double click said widget to get code for the form
4. A sub is created automagically and i type in 'MessageBox("w00t")'
5. File->Compile
and done.

In python/designer (i don't have eric3 installed, but it seems eric would be overkill in this instance) I have limited experience using python, so bear with me here. correct me if I am mistaken, please

1. In QT designer -> start a new dialog
2. Select the button widget to draw a button in the middle
3. Save form1.ui
4. Open up a shell and run pyuic form1.ui -o form1_ui.py
5. Make a new Makefile / python code file (like form1_code.py)
6. write skeleton python app with messagebox popup when form1's pushbutton1 is pressed (or even open eric3 to do the last two steps?)
7. run make
and done

It's not just the increased number of steps, it's the fact that it's really not that intuitive coming from a VB standpoint. For most apps, I'll use C++ and designer and I love every minute of it. If i want to make a quick and dirty little app (like adding a gui frontend to a script), It would be so cool to have point-and-click development.

It's not an awful thing to do it the Designer/Eric3 way, I would just really like a single interface to it all.

once again, /me drools

//standsolid//

by Roberto Alsina (not verified)

Well, you're using an IDE for VB. Ever tried writing a VB app using a text editor and the CLI? ;-)

So, let's use eric3.

1. Create new project
2. Create the main script (this is always the same thing, really, just C&P)
3. Create a new dialog (menu in eric3)
4. Open the dialog. (I don;t remember if eric3 opens it when you create it)
5. Drop a button in the middle
6. Connect that button to some slot (however you want to call it)
7. Save the form
8. Create the Window subclass, and implement the slot there
9. Compile all forms (it's in the menu in eric3)

Now, you may say, "hey, that's *more* steps!". And you are right.

However, apps are not built using one form with one button on it that uses
only the click callback, are they? ;-)

Steps 1 and 2 are once per-project: don't even think about them. If they bother you too much, save the project at that stage, and work from there
every time.

Step 4 is only an extra step once per window. A reasonable app may have about 10 windows. So, it's ten extra clicks over the lifetime of the development. Not really much ;-)

So, it's 6 steps using eric3, vs 5 steps using VB. Not too bad.

Also, the reason why step 4 is so easy on VB is because you are just editing something that happens when you click the button.

If you wanted that same thing to happen, for example, every 10 minutes, or when the user clicks on a menu, *in adddition to when you click on the button*, then you need to create a method somewhere, and put a call there. On Qt, you just connect more stuff to the slot. In the long run, Qt is simpler there.

Also, once the slots are created, they are available on a dropdown box on eric3, just like in VB.

Finally, I don't know if VB has some equivalent to Qt's actions, qhich let you put the same thing in a menu or a toolbar or whatever with extremely little code.

Really, I think that particular list of steps is heavily biased towards writing apps with a button that say "w00t" ;-)

by standsolid (not verified)

For me, it's not so much the steps you have to take to get there, But ease of use getting to the last step. If it took me 20 steps in VB and it was point-and-click, IT would be easier to me. by the way -- having a call every ten minutes would be super easy in VB (new timer -- you could even drag one to your dialog), but I know that's not the point :).

What i guess I REALLY want is Designer to be tightly integrated into a source code editor like eric3 or kdevelop. that would be really awesome

//standsolid//

by standsolid (not verified)

and by the way, i really liked your tutorial too, thanks!

I never looked into eric3 before this.

//standsolid//

by Roberto Alsina (not verified)

Yeah, eric3 is not nearly as popular as it should be :-(

by Marco Bubke (not verified)

Yes, I use it all the time. It's so much easier to program Qt with python than C++. C++ is faster in runtime but python is so much more flexible. I hope for SIP 4 with new-class support.

I don't say C++ is a piece of shit. I enjoy to read book like Modern C++ Design(very good book if you read The C++ Programing Language). But I don't like static typed language for dynamik stuff. You do all the time trick with to circle the type system.

by Boudewijn Rempt (not verified)

I'm very fond of PyQt myself -- I hope to get the second royalty check for the book I wrote on PyQt any day now -- and now I am working in C++ we (my fingers and me) ache every day for the comfort it gave. If you're writing an ordinary GUI application, then PyQt (and PyKDE) will give you all the speed you need, and your application will be done faster than you'd have thought possible.

Still, when I tried to do a real paint application in Python, one that went beyond reusing QPainter/QPaintDevice, I couldn't even do a prototype that was nearly fast enough, not even by pulling in things like PIL or Numeric. Conceivably, using bindings to ImageMagick might have done it, but instead I decided it was time for my next programming language, and started on C++.

Image my surprise when I realized that a class isn't an object in C++ :-).

by ac cosa (not verified)

Interesting. I wrote almost the same app but used wxPython (running windows at work). It took about 3 hours to do the interface (by hand). I love python;) I had some python classes I had previously written that act as a simple search engine.
I find it very useful to take notes in, especially for things I do once in a while, but have to look up or google every time.

by Reader (not verified)

Hmmm it seems that the PyQt toolkit can be really useful and relatively easy to work with. However does anyone know any book or any extensive online tutorial about Eric/Designer/Python that can be also used as a python introduction? (hmmm, am I asking too much?)

by Rayiner Hashem (not verified)

If you want an intro to Python, the best place to start is the official tutorial:

http://www.python.org/doc/current/tut/

Its very clear, very well written, and shouldn't take more than a day or so to complete. Good luck!

by Marco Bubke (not verified)

Look at http://www.awaretek.com/plf.html, http://www.opendocs.org/pyqt/ and http://diveintopython.org/. Maybe you have questions. There is comp.lang.python.

by Boudewijn Rempt (not verified)

I wrote a book on PyQt, and the publisher really, really wanted it to also have an introduction on Python, which I really, really didn't want to do, so don't rely on those chapters. However, for anyone who has ever programmed in any programming language, it should be easy enough to pick up Python on the go as you start from the first hello world button program in Chapter 6. I know a couple of people who did...

Oh, and if you like the book on http://www.opendocs.org/pyqt/ -- please consider also buying it... If enough people actually buy the book (I know there's a university where it's a set text, but they tell the students to use the web version, which doesn't have all the illustrations, don't know why), I might get a chance to do an update, one that also includes information on Eric.

Not that Eric needs much in the way of manuals or things: the thing just works and is completely transparent to anyone who has ever used an IDE.

by devotchka (not verified)

It is unfortunate that in order to try out the tutorial, users need to have root access to install most of the software. Eric3, PyQt, and SIP (which PyQt requires) all require root privileges to install. This seems like a ludicrous requirement and I am unable to give the tutorial a look.

by Ian Reinhart Geiser (not verified)

now that is BS with a capital B ;)

they require no more privilages than any other KDE program. I have developed full applications in PyQt including plugins and embedding with no such requirement.

It's hardly "BS." The documentation for all the products say they will only install under root. Jim Bublitz even admits this is the case:

http://mats.imk.fraunhofer.de/pipermail/pykde/2002-August/003449.html

Roberto says below that it is possible to install all three as non-privileged users, but it requires that I compile Python under $HOME--a non-trivial task. I hope I don't have to devote a weekend getting this to work.

by Boudewijn Rempt (not verified)

Compiling Python is just as trivial as compiling PyQt -- configuring and compiling stuff isn't hard anymore, these days.

Well, installing Qt and KDevelop also require root access!

Anyway, you *can* get all those installed into a user account. It´s not the suggested method, but you could build your own python interpreter in your homedir, then use that instead of the system´s.

That should work at least for eric3 and PyQt, I am not 100% sure about sip.

Installing apps of any kind generally requires root on *NIXes.

by Richard Van Den Boom (not verified)

I confirm that programming an application with Python and PyQT is remarkably simple. I'm a very inexperienced programer (mainly fortran in molecular physics) but I've been able to write a very limited animation utility with its GUI in less than a month, Python and PyQT learning time included.
This is really impressive work and it makes programming a GUI application nearly available to anybody.
Since you seem to know these tools well, I would like to ask a programing question : I'm looking for a way to display some custom widgets vertically (always the same type, a frame with some text fields that represent a single movie sequence, though of course there will be several different instances) with scrollbar appearing if the display is too small and with a possibility to add/delete/move the widgets. It's basically to create a movie timeline, like in a video application, except there will be only one with no sound right now.
I don't like QListView because it's text only, a sequence cannot be a custom widget. I tried QTable but cannot manage to set the Widget in a Cell, though it should be supported, as far as I could read. I tried a simple QFrame and a QVBoxLayout, but I don't have scrollbars appearing if too many sequences are added to the main layout.
There is probably a very simple way of doing what I want but it escaped me right now.... :-(

Best regards,

by Chakie (not verified)

QListViewItem:s can be made to contain QPixmaps. I use that feature heavily in my PyQt based apps for managing digicamera pictures. See the setPixmap() method of QListViewItem. QListView has other annoyances, but this is not one of them. :)

by Richard Van Den Boom (not verified)

It's not just an image I try to set, but a whole frame with different QLineEdit objects. I don't think it can be created as a QPixmap, does it?
But thanks anyway. Actually, I've finally found what I need with QScrollView. It's so simple I'm actually ashamed of having posted a question here. :-D
I'd like to point out, though, to come back on the topic, that my problems are more related to my very limited knowledge fo Qt than to PyQT.
PyQT works really impressively well and is actually fast enough for most graphical applications.

by Chakie (not verified)

Ah, I read your original message a bit too fast. :) Indeed, it's quite fun to sometimes just browse the wealth of Qt classes and see what's available. Often you find something that you haven't needed before but which suddenly fits very well into some project you are working on.

by Mark Zealey (not verified)

I've been trying to write some stuff using this method (before this article was written), basically its a program to make an index of my lecture notes, but for recall and so on I'd like to embed a KPart of the gs viewer so I can view my notes (all scanned in in PDF format)... Can't seem to make it work, even if I change all my classes to be the equivelent K classes.

Anyone tried anything like this before and could give some pointers?

by David Boddie (not verified)

I've experienced some issues with embedding KParts before, so I experimented a little with PyKDE-3.8.0 and found that I could embed the KGhostView part, but it wouldn't show the document.

It's quite strange that some KParts work and others fail. For example, the text ones tend to work, but only one of the image viewers will get embedded and show a picture. It's something worth looking into, certainly.

by Roberto Alsina (not verified)

The link to download the notty souces was broken, but it´s now fixed.

by tomten (not verified)

"In order to use eric3 under Win... operating systems you need a commercial or educational license of Qt 3.x from Trolltech and the corresponding license of PyQt (which includes QScintilla) from Riverbank."

by Roberto Alsina (not verified)

Just be happy that they license it to you for free, moron.