As I mentioned earlier, I got a Nokia 770.
I decided I would try my hand at doing some development on this thing, ostensibly as a potential solution for a client. The question was, what was I going to use as a programming language? The 770’s OS is Linux, which certainly doesn’t lack in language options. They even provide a full SDK and development environment for the 770 at maemo.org. A quick browse through the documentation showed me that the UI for the 770 is basically Gtk+ and parts of Gnome plus a Nokia created extension to Gtk called Hildon. Well, the language of choice for gtk and gnome is C, but I don’t really like writing C unless I really need the performance. Fortunately there are a ton of language bindings for gtk, somebody was bound to have ported one for a language I like to the 770. Sure enough, the Nokia Institute of Technology in Brazil not only ported Python to the 770, they even ported the gtk modules and created bindings for the Hildon extensions. They call the whole package PyMaemo.
I really like python. I’ve actually been using it quite a bit lately for some projects for clients. I’m not a great python programmer yet, I still have to look things up fairly often. Not like PHP, where I could probably name every function and its arguments from memory. Anyways, I installed PyMaemo onto my 770 and did your basic “Does HelloWorld work?” kind of testing on it and then got down to business.
First, I created a simple pygtk app along the lines of:
import gtk
app = gtk.Window(gtk.WINDOW_TOPLEVEL)
app.set_title("My App")
app.add(gtk.Label("Testing..."))
app.show_all()
gtk.main()
That seemed to work fine, though the app looked a little funny. It didn’t seem to fit the screen quite right.
So, I figured I would head back to the PyMaemo site and check the docs on the Hildon bindings. There aren’t any. None. They didn’t document it at all. So, I checked out the maemo.org site for Hildon docs. They have docs, but only for C. I could figure out what most of the python methods were called based on the function names in the C API, but not all of them. Thank goodness for python’s self-documenting nature. Even when a class/method doesn’t have a doc string, you can still at least get the method names using dir(). If you haven’t seen this it’s pretty cool. The theory goes like this: Everything in python is an object, and obviously an object must know what properties and methods it has, so if I create an instance of an object, I should be able to find out what properties and methods that instance has. So, when I couldn’t figure out why I didn’t have a hildon.app_new like it said in the C api, I simply did:
import hildon dir(hildon)
…and looked through the output for a likely looking method (it turned out I just needed hildon.App()).
So, after going through some docs, and digging through some dir() output, I converted my app to Hildon like so:
import gtk
import hildon
app = hildon.App()
app.set_title("Hildon App")
app.set_two_part_title(True)
view = hildon.AppView("Main")
view.add(gtk.Label("Testing..."))
app.set_appview(view)
app.show_all()
gtk.main()
The concept here is that the 770 doesn’t really have room for multiple windows in a single app, so instead you create an app and multiple views that can be switched between. It’s actually a very comfortable concept to work inside. I create different views for every type of display I need in my application and then just swap them out as needed.
So, this time the app looked just like any other native app on the 770…except for the lack of an application icon. I’m not sure how to deal with that yet, but I’m sure enough digging through dir() output will turn up what I’m looking for.
I wish I’d seen this blog before I started fighting with this, would have saved me hours of work.
Edit:
Hooray for Teemu’s blog. Now I know how to make the application icon show up!
Comments 1
nice article
in few words it reveals a lot of things, in a very simple and straightforward manner: this never-heard dir() feature of python, a simple introduction to gtk and hildon: in few minutes the reader gets involved and feels he should not fear this stuff. I hope my 770 will arrive soon from Opera headquarters…
Posted 07 Feb 2006 at 07:16 ¶Post a Comment