Reply
Thread Tools
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#1
Hi
I am a semi senior php programmer.
I am trying to learn how to create GUI based apps for the N900.
There is a lot of information, I can not find any clear step by step tutorial.
Can someone please explain in a few words what are these "things" ?

Python = OO programming language
Cairo = Graphic library
PyCairo = Is a "layer" between Cairo and Python? When should I use it?
GTK = Do I need it if I use cairo? I should use it instead? It is other thing and I need both?
PyGtk = same as PyCairo?

Any guidance is welcome
 
Nathraiben's Avatar
Posts: 267 | Thanked: 408 times | Joined on May 2010 @ Austria
#2
If you're especially looking to develop for Maemo on the N900 (and maybe some day for MeeGo), go for PyQt instead.

Qt is the GUI library (though that term might be misleading, since Qt does a lot more than just handle the GUI part of your applications) that will be best supported on both OS, so you might want to look into that one instead of other GUI solutions.

Qt is natively C++, but there's the aforementioned PyQt bindings that combine the strengths of Qt and the comfort of Python.

Python - despite the obvious syntax differences - should feel pretty natural for a PHP coder, so I'd say the Python + PyQt combination should suit your needs pretty well.

(Quick sidenote: Python + PyQt has some well-made classes for accessing websites, complete with full auth and cookies - so server-client based applications with a PHP server in the background are quite easy to make.)

There's not much work involved with getting your workspace up and running, either. If you're on Linux, must grab the Eric Python IDE and you'll have everything you need right at your fingertips, since it already includes god-sent tools like Qt Designer and Qt Linguist.

For a short intro to Python + PyQt, here's a nice little starter tutorial made by mikec.

I'm totally new to the mobile app development stage myself, but if there's anything you want to know I'll try to help.

Oh, and welcome to the Maemo development world...
 

The Following 5 Users Say Thank You to Nathraiben For This Useful Post:
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#3
First of all, thank you very much for your detailed response.
I must confes that I have been reading about Qt and GTK and I have decided for GTK, canīt remember why right know because I did it a few month ago. But if Qt is the best option for Maemo and MeeGo, may be I should start with Qt.
I have downloaded the "roadrunner" app, which uses cairo and gtk and managed to add some features, I think I will have to recode the whole app, which will be go practice for me.
Iīll be back!
Thanks
 
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#4
One more thing:
What if I decide to develop for other phone OSs like Android for example? Will I better with Qt, GTK, neither or both?
 
Nathraiben's Avatar
Posts: 267 | Thanked: 408 times | Joined on May 2010 @ Austria
#5
Hm, good question. I think Android has more emphasis on Java altogether, though. Never had an Android device, so I can't even tell how hard/easy/impossible it would be to simply port the necessary libraries over to Android.
 
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#6
Ok, I have everything up and running.
My fisrt Qt app worked like charm. But I donīt know why, because this:
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())

Is completely new and there is no explanation on the tutorial:
http://talk.maemo.org/showpost.php?p...8&postcount=59

Any link or guidance?
Thanks!
 
Nathraiben's Avatar
Posts: 267 | Thanked: 408 times | Joined on May 2010 @ Austria
#7
I'll try to go over that coding and explain what each line does (though, remember, I only started two weeks ago, too - so I might have gotten some of that wrong ).

Code:
class MyForm(QtGui.QMainWindow):
The first line you didn't quote, but it's actually quite essential, since it starts the definition for the class MyForm (which is a subclass of QtGui.QMainWindow).

All of the GUI elements are created by simply subclassing one of the Qt classes. All the events will be put in here later.

Code:
        def __init__(self, parent=None):
This is the definition of the constructor method. Like with all the methods in Python, if you want this method to have access to other methods and global attributes of the class, you'll have to set "self" as the first parameter (when calling the method, you don't have to provide anything for this parameter - just start with the one that comes after self, in this case parent).

Code:
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
calls the default Widget (=parent class of QMainWindow) constructor.
Code:
                self.ui = Ui_MainWindow()
This creates an instance of the GUI that was created with QT Designer and then:
Code:
                self.ui.setupUi(self)
assigns it as the layout for the main window.


That's actually the end of the class definition (you - and the interpreter - can tell by taking a look at the indentation).

So everything after this is "floating" code, not part of any function or class.

Code:
if __name__ == "__main__":
        #This function means this was run directly, not called from another python file.
        app = QtGui.QApplication(sys.argv)
I'm not quite sure I understand this, but this is where your applications starts. Kind of like the main function in other languages.

Code:
        myapp = MyForm()
Instantiate the subclass defined above, so it creates the main window.
Code:
        myapp.show()
Displays the main window.
Code:
        sys.exit(app.exec_())
This makes sure a return code is sent once the application is exited. This will not immediately kick in, but only when Qt has told the application to shut down (by it because you called quit or simply by closing the last visible window).

Last edited by Nathraiben; 2010-07-02 at 18:15. Reason: Code != Quote :p
 

The Following User Says Thank You to Nathraiben For This Useful Post:
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#8
Thank you very much. Excelent explanation! Where have you learn all this? I want to read it too!
 
Nathraiben's Avatar
Posts: 267 | Thanked: 408 times | Joined on May 2010 @ Austria
#9
Always glad to be of help...

Err... well... uhm... I have to admit, most of it I got by trial&error and analysing code snippets I found on Google.

(Also, I have found that some of my Java knowledge comes in handy from time to time, too.)

Haven't found any real starter tutorials other than the one linked above, but I spend a good deal of time skimming through the PyQt class reference to get a feeling of what classes are there and which ones might be of use to me. It's not complete yet, and quite a lot of methods are more or less undocumented, but it's still a great source of information.

Other than that - like I said, I just more or less camp Google whenever I hit a wall with trial&error. Python and PyQt are pretty popular by now, so chances are every question you have has already been ask in one or more forums/mailing list.
 
Posts: 217 | Thanked: 20 times | Joined on Jan 2010
#10
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 16:37.