View Full Version : PyQt framework now on Diablo
Nyrath
09-26-2008, 10:50 AM
TrollTech's Qt application framework (http://trolltech.com/products/qt/) is by far the easiest and most powerful GUI framework available. It has loads of extra goodies, like GUID classes and data persistence objects. I use it at my day job for our major projects.
TrollTech was recently purchased by Nokia.
The free open-source version of Qt was ported to Maemo
http://qt4.garage.maemo.org/. It is a set of libraries for C++
However, that wasn't what I was waiting for. There are a set of Python bindings for Qt, called PyQt (http://www.riverbankcomputing.co.uk/news). This gives one all the power of Qt within the ease of programming in Python (http://www.diotavelli.net/PyQtWiki). PyQt is quite popular (http://www.diotavelli.net/PyQtWiki/SomeExistingApplications).
Yesterday, spartanNTX (http://www.internettablettalk.com/forums/showpost.php?p=227349&postcount=5) brought the good news. PyQt has been ported to Maemo for the Diablo OS.
http://pyqt.garage.maemo.org/
Yup, that's good news all right !
It would be interesting to see a comparison of launch times + memory usage *on the tablets* for a test app done both in PyGTK and PyQt in the closest possible way...
gowen
09-26-2008, 04:23 PM
Here is an app I found that you can use to test your installation.
The maemo Qt/pyQt port looks really well done. I downloaded an old favourite of mine, Treeline, which is a fairly complex app.
It ran without problems, and automatically hildonized (menu, full-screen etc.).
Start-up time doesn't look very different from pyGtk though.
nilchak
09-27-2008, 12:12 PM
The maemo Qt/pyQt port looks really well done. I downloaded an old favourite of mine, Treeline, which is a fairly complex app.
It ran without problems, and automatically hildonized (menu, full-screen etc.).
Start-up time doesn't look very different from pyGtk though.
This is the a very encourageing news of late (apart from the freemantle based speculations thread). I should start getting the old QT apps on the N810 - this really opens up a lot of apps that can be used on the Nokia IT's.
Have been waiting for PyQT for al long time.
Nyrath
10-01-2008, 10:01 AM
Here is an app I found that you can use to test your installation.
Sonofagun. It actually worked!
I copied it over to the NIT's internal storage with a USB cable, used emelFM2 to copy it to /home/user, then used XTerm to do a chmod +x Qdir.py, then a ./Qdir.py
It gave me some GTK warning, but the program actually ran. Nice GUI display of the directory.
It did take some time to start up, though. Par for the course I guess.
Nyrath
10-01-2008, 05:07 PM
I'm really impressed now! I took my app, converted all the CR/LF in the *.py files into LF, copied them with the data and image files over to the Nokia, did a cmod +x *.py, and ran the main file with python. Blasted thing worked perfectly. I'll have screen shots later.
The layout of the screen is a little smashed since it was set up for a monitor larger than 800x480, but that will be trivial to fix.
This is great!
Let me get this straight:
Can I develop and test a Python Qt app on Windows, Linux or Mac using the QT UI Designer and then re-target/run it on an IT without having to use Scratchbox?
And it just works and is auto-Hildonized as long as I am careful about window sizes?
Don.
Nyrath
10-01-2008, 11:36 PM
Yes. That's exactly what I'm saying.
I developed my app on Windows, using Python with PyQt. I used EasyEclipse for Python to write and test it, but I could have just as easily used Notepad and the Windows Command Prompt. My app included various image in PNG format. It ran wonderfully on Windows.
On my Nokia 810 with Diablo (you must have Diablo, PyQt for Maemo won't work on anything earlier), I installed Python for Maemo, Qt for Maemo, and the three PyQt modules I used in my app (QtCore, QtGui, and QtXml).
I used a Windows utility called CRLF.exe to convert all the *.py files so they had LF at the line ends, instead of CR/LF. Other than this, I did not change any of the *.py files one bit.
Then I copied over all my *.py files and image files, maintaining the folder structure. I didn't know the standard Linux conventions, so I put them all in a new folder in /home/user/. I copied them by connecting my Nokia 810 to my Windows machine using a USB cable, copying to the external memory card. I then used emelFM2 on the Nokia to copy the files from the external memory card to /home/user/.
I then ran XTerm. I used the cd command to enter the folder with my *.py files. I then used the command chmod +x *.py to set the execution permission on all the python files.
Finally, in XTerm, I entered the command python MyMain.py where MyMain.py is the python file with your "main()" function. If I had been smart enough to put a "she-bang" line at the start of the file, I could have run it with ./MyMain.py
After about 20 seconds, my app started up. Just like magic. All without requiring the Scratchbox.
Nyrath
10-01-2008, 11:54 PM
Here are some images.
http://www.flickr.com/photos/nyrath/2906625942/in/set-72157606410052769/
In each pair, the first one is on Windows, the second is on the Nokia 810. Use the control on the right to move to the next image in the set.
I'm going to have to re-arrange the controls, they are a bit squashed on the Nokia.
Mind you, it has been (theorically) possible to do the exact same thing for quite a while, using PyGTK and Glade or Gazpacho on the desktop, and the standard python2.5 runtime on the tablet (which includes PyGTK). Only it didn't really work so well.
It's nice to see that Qt better fulfills that promise. I'll give it a go when I'm tired of my plain but natively cross-platform python web apps :-)
Nyrath
10-02-2008, 10:01 AM
What I like about Qt and PyQt is that it is so much more than just a GUI framework.
It's got a powerful set of XML parsing classes, a file system that automatically takes care of the difference in file path formats between Windows, Macintosh and Linux, cryptographic hash classes, and support for SQL databases.
There is also a "settings" class that allows your app to remember settings between executions. Behind the scenes it uses the registry in the Windows environment, XML files on Macintosh, and ini files on Linux.
Mind you, it has been (theorically) possible to do the exact same thing for quite a while, using PyGTK and Glade or Gazpacho on the desktop, and the standard python2.5 runtime on the tablet (which includes PyGTK). Only it didn't really work so well.
Does PyGTK/Glade or PyGTK/Gazpacho do automatic Hildonization? Maybe that is what you meant by it didn't work so well.
Anyway, that is what caught my attention with PyQT/QT Designer, plus no Scratchbox.
Does PyGTK/Glade or PyGTK/Gazpacho do automatic Hildonization? Maybe that is what you meant by it didn't work so well.
I'm not sure, it's been a while, and I gave up quickly enough. But I seem to remember that you needed to specifically call the Python Hildon API for some things, which sort of defeated the portability idea.
Nyrath
10-02-2008, 12:50 PM
I will say I was totally flabbergasted when I copied my PyQt source files over to the N810, raw, and it "just worked." I expected to spend a couple of weeks adapting the code to the Maemo platform.
I have some problems with some of the controls being squished, but I have a feeling it is due to my misusing the "sizePolicy" property of the controls. I don't think is it PyQt's fault, it's mine.
I'm not sure, it's been a while, and I gave up quickly enough. But I seem to remember that you needed to specifically call the Python Hildon API for some things, which sort of defeated the portability idea.
That was my experience too, but the details are fuzzy now. It was also a pain to find all of the components to do this on Windows. I did get Eagle to work, but the results were so ugly that I gave up on that too - probably too quickly but it became clear that I would have to dive into the Eagle code if I wanted it to look at all pleasant. The easiest approach so far has been the one you used - a local server and using the web-browser for a window manager.
I am going to give PyQt a go - fingers crossed!
I suspect that there are quite a few folks who would like to roll their own IT programs on Windows but find the whole mass of stuff that you have to learn first much too intimidating.
Nyrath
10-02-2008, 03:22 PM
Install Qt, PyMaemo, and PyQt. Then see if Gowan's test program works:
http://www.internettablettalk.com/forums/showpost.php?p=227790&postcount=3
If it does, you are good to go.
If you have questions about programming in Qt, this is a good forum:
http://www.qtcentre.org/forum/
That was my experience too, but the details are fuzzy now. It was also a pain to find all of the components to do this on Windows. I did get Eagle to work, but the results were so ugly that I gave up on that too - probably too quickly but it became clear that I would have to dive into the Eagle code if I wanted it to look at all pleasant. The easiest approach so far has been the one you used - a local server and using the web-browser for a window manager.
I am going to give PyQt a go - fingers crossed!
I suspect that there are quite a few folks who would like to roll their own IT programs on Windows but find the whole mass of stuff that you have to learn first much too intimidating.
That was precisely the main point of my talk in Berlin - which led to web apps. If Qt on maemo does approach the same level of painlessness, then that changes a lot of things for a lot of people.
Nice move by Nokia -- but it does raise the question of why the same was never done for GTK ? :-)
Nyrath
10-02-2008, 04:35 PM
Nice move by Nokia -- but it does raise the question of why the same was never done for GTK ? :-)
I could be wrong, but I'm pretty sure that PyQt was ported over by a third party hobbyist, not Nokia. I'm a little less sure about the Qt port, but I'm somewhat sure that was not by Nokia as well.
I was aware of that, but as it happened at the same time Nokia bought Trolltech, I assumed there was a connection. After all, python/pyGTK is technically third-party too (through INdT), but it happened because Nokia wanted it to...
branitar
11-19-2008, 08:20 AM
I just started developing with Python and PyGTK (and GTK as a whole) a week ago. I've been working with Qt some years ago and dont remember having so many problems with certain aspects, so i think i will switch to PyQt. And the purchase of Trolltech/QtSoftware seems to hint at the possibility that OS2009 (if there will be one) will get some serious Qt-loving....
@Nyrath:
The flickr-pics only show the application in windowed mode. Do you know if there's support for the hardware keys and fullscreen integrated?
branitar
11-20-2008, 03:47 PM
Ok, now I've got a serious problem. Whats wrong with the following code?
import sys
from PyQt4 import QtCore, QtGui
class SlmListView( QtGui.QWidget ):
def __init( self, parent = None, core = None ):
QtGui.QWidget.__init__( self, parent )
self.myLayout = QtGui.QVBoxLayout()
self.setLayout( self.myLayout )
def populate( self ):
for i in [1, 2, 3]:
self.myLayout.addWidget( QtGui.QPushButton( str( i ) ) )
class SlmMainView( QtGui.QMainWindow ):
def __init__( self, parent = None ):
QtGui.QWidget.__init__( self, parent )
self.slmListView = SlmListView()
self.slmListView.populate()
self.setCentralWidget( self.slmListView )
if __name__ == "__main__":
app = QtGui.QApplication( sys.argv )
slmMainView = SlmMainView()
slmMainView.show()
sys.exit( app.exec_() )
When executing it i always get the following message:
C:\develop\Python>python app.py
Traceback (most recent call last):
File "app.py", line 26, in <module>
slmMainView = SlmMainView()
File "app.py", line 20, in __init__
self.slmListView.populate()
File "app.py", line 12, in populate
self.myLayout.addWidget( QtGui.QPushButton( str( i ) ) )
AttributeError: myLayout
Help? :(
Nyrath
11-21-2008, 05:57 PM
Let me do a quick check. I should be able to figure out your problem when I get back to my main computer.
Nyrath
11-21-2008, 08:47 PM
In line five you have the following:
def __init( self, parent = None, core = None ):
You forgot the two trailing underscores after "init". It should be:
def __init__( self, parent = None, core = None ):
When you add them, the program displays a window with three buttons stacked vertically.
The error message was "AttributeError". It says that it could not find the attribute "myLayout" in the SlmListView. What happened was that the __init creator never got called, because it has the wrong name. So the myLayout never got created. So it could not be found.
How did I find the error? I figured there was something wrong with the myLayout. So I put in lines "print myLayout" when it was created and before it was used in populate(). The print in the constructor never happened. That's when I realize the constructor was never being called. And that led me to discover that it was mis-named.
branitar
11-22-2008, 07:32 AM
Wow, thanks, you're a genius! I had nearly given up on it. Forgetting stuff like underscores, dots, commas etc) is typical for me *g* Thank you!
Nyrath
11-22-2008, 08:25 PM
Glad I could help.
I'm currently developping a panohead driving application in PyGTK, and start to have serious troubles (I got some seg. fault on some OS, not on others...). That's a long time I plan to switch to PyQt, as I also use it in my every-day job.
The question is: is it planned to have a PyQt version for OS2007? Some users of my app. are running it on 770s, and I don't want them to be excluded from futur devs...
MountainX
07-02-2009, 12:33 AM
I downloaded an old favourite of mine, Treeline...
It ran without problems
Great news for me because I want to run Treeline too. Being a newbie to the n810, I would love to see a step-by-step guide to getting Treeline to run. (I do not have PyQt or any related packages installed yet.)
cheatex
08-26-2009, 01:55 PM
I try PyQt for Diablo and get segmentation fault :(
Should PyQt works in scratchbox?
attila77
08-26-2009, 02:21 PM
PyQt most certainly works on Diablo. Can you post some code that demostrates the crash ? Most of the time segfaults happen when objects get destructed 'behind' PyQt's back and then you try to reference them.
cheatex
08-26-2009, 02:24 PM
PyQt most certainly works on Diablo. Can you post some code that demostrates the crash ? Most of the time segfaults happen when objects get destructed 'behind' PyQt's back and then you try to reference them.
#!/usr/bin/env python2.5
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
if __name__=="__main__":
app = QApplication(sys.argv)
label = QLabel('Hello!')
label.show()
sys.exit(app.exec_())
attila77
08-26-2009, 02:45 PM
Just tried it out on my device, works as expected, no segfault. What versions do you have ? I tried with PyQt 4.4.3-maemo10 and Qt 4.5.0-1maemo2.
cheatex
08-26-2009, 03:01 PM
I use Maemo SDK 4.1.2. PyQt 4.4.3-maemo10 and Qt 4.5.0-1maemo1 packages.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.