Coding for Nokia 770 using Python - Part 1
I thought that I start a series of posts giving some tips on how to get started to code applications for Nokia 770 using Python. I have some experience on coding Pyhon for Series 60 and now I’ve started to play with the Python for Maemo. My intention was to give some examples and hints how to easily develop software for Nokia 770. I’m still in the phase of learning how to use GTK/Hildon to implement user interfaces, so feel free to comment if I’m doing something totally wrong or if you have questions.
In this first part I thought that I’d give instructions how to set up an easy configuration so you can easily code Python on Nokia 770 using your PC and also very easily run your applications on the actual device. I’ll also give an example of a very simple Python application that you can see below. It’s not much, but it is a good start.

Ok, first you will naturally need to install Python for Maemo on your Nokia 770. Download it from here and install it normally using the Application Installer. After installing the package, you will be able to run Python scripts on your device. If you have Xterm installed, you can run /var/lib/install/usr/bin/python2.4 to start the Python console and start coding.
This most probably is not the most convinient way to code. Basically you can install Python for your computer and develop applications there. Anyhow, for testing the user interface you will need to use either the Maemo development environment or the actual device. Development environment runs only on Linux so if you don’t have that, I have a simple solution for you. For this to work you will need to enable the R&D mode on the device and become root. Unfortunately you need Linux to for this, but you can use for example Knoppix Bootable CD Linux so you don’t need to actually install it. Just burn the Knoppix image to CD and boot you PC using that.
For easy development you can install SSH server on your Nokia 770, so that you can connect to it using your PC. For making the SSH connection you can use for example Putty. You need to also set the password that is used when logging in. This can be sone in root mode by typing “passwd user” in Xterm.
Install also Nano text editor on your Nokia 770. You can also use Vim, but I prefer Nano (It is somehow easier to use). Once you got these installed, open the WLAN connection on your Nokia 770. Check what is your IP. For that you can use Xterm (you need to be root) and run ifconfig. You can also use the IP Home plugin to see your IP address. Then connect to your Nokia 770 using this IP address with Putty. Username is “user” and password is the one that you have set earlier.
Ok, now we are ready to start coding. Go to the home diredtory “cd /home/usr”.Then start the nano editor and create a python file by typing “/var/lib/install/bin/nano uitest.py”. Then write the following code to the file.
- #!/var/lib/install/usr/bin/python2.4
- import gtk
- import hildon
- class UITest:
- def __init__(self):
- self.app = hildon.App()
- self.appview = hildon.AppView("Appview Title")
- self.label = gtk.Label("My first Python App...")
- self.app.set_title("App Title")
- self.app.set_two_part_title(True)
- self.app.set_appview(self.appview)
- self.appview.connect("destroy", self.destroy)
- gtk.Container.add(self.appview, self.label)
- self.label.show()
- self.app.show()
- def destroy(self, widget, data=None):
- gtk.main_quit()
- def main(self):
- gtk.main()
- if __name__ == "__main__":
- uitest = UITest()
- uitest.main()
This code creates a similar application that is shown in the image on the top of the page. You can run it easily from your PC by typing “run-standalone.sh ./uitest.py”. The application should now launch successfully on your device. This is quite convenient, since you can edit the code using your PC and then run the application on the device and you don’t have to transfer any files between PC and Nokia 770.
In the future posts I’ll try to explain more about what the code actually does. Meanwhile I can suggest that you check the PyGtk site tutorial. Based on that you can do lots of cool things like add buttons etc. Also if you haven’t yet checked the Python language reference, now is the time.
Ok… this was all this time. All questions and comments are very welcome. I hope you enjoy coding Python. ![]()
January 27th, 2006 at 5:45 pm
Note: to anyone not familiar with python who may try the script. Indenting counts. Instead of having and end of block marker, it assumes if the next line is indented less, it’s in a different block. and if it’s indented more, it’s in a sub block. This hung me up for a good 20 minutes this morning.
Teemu, nice article, gonna give PyGtk a look.
Also When posting codeblocks, is there a more cut and paste friendly format you can use? I had to edit out the number lines, and along the way I F*d up the indenting (see above). It might help us python newbies out there.
-Jason
January 27th, 2006 at 5:55 pm
Hi Jason!
Thanks for your comments. I’ll include a downloadable source code files from now on as well. Anyhow, it’s always a good practice to write down the code yourself.
And yes, this indenting stuff is something that I should have mentioned. Python code has to always be correctly indented. It is sort of the first place where people get stuck when coding with Python for the first time. It is hard to figure it out from the error messages.
Nice to hear that I’ve got people trying Python coding. I hope you find it usefull and see how easy and fast it actually is to create quite nice applications, since you don’t have to care about compiling and other stuff.
January 27th, 2006 at 7:38 pm
I got it installed on scratchbox as well, and fixed some omisions on the pymaemo page. (They were missing two imports).
Is the hildon py class documented anywhere?
Are you going to wiki this anywhere?
Thanks again…. It looks like I know what I’ll be playing with this weekend.
-jason
January 27th, 2006 at 7:52 pm
Hello Teemu! I’m glad to see your post about PyMaemo. We are still working to make Python for Maemo more friendly to the platform and to developers in a very near future.
- Rudá
January 27th, 2006 at 8:29 pm
I’m really glad to see Python on the 770. Thanks so much for the tutorial. More, please!
January 28th, 2006 at 1:16 am
Hi Teemu!
Python for Maemo! Yeah! I love it… i played around little bit and had much fun.
I have a question. Are you working also on PIL (python image library)? Because so many projects depends on PIL (like Comix, GNOME Sudoku..etc)
best regards
rachid
January 28th, 2006 at 9:56 am
I’d like to see a pygame example that does something in full screen mode. Once we have that, we can start developing lots of games for the 770…
January 28th, 2006 at 5:30 pm
As for pygame check out http://pygame.org/
I ran several apps from http://pygame.org/ and they run although VERY slowly, but there is source avaialble, and it should give you a good starting point.
-Jason
January 28th, 2006 at 11:00 pm
hallo
-do you think, is it possible for a “programmer-beginner” to start with python on a nokia 770 - because this little device can stay with me on my workplace - and there i have enough time ?
thanks chw
January 29th, 2006 at 9:22 pm
hi chw,
sure why not. On my opinion, python is the best language for learning programming.
But you should use an external keyboard…
regards
rachid
January 30th, 2006 at 9:51 am
I am just getting started with this, so hopefully this isnt too dumb of a question. I got python and openssh loaded on my Nokia, as well as xterm and vim, and everything works from that regard. However when I ssh into my nokia from my laptop, running linux, it is terribly slow. Too slow to code in vim productively. Is this just due to the low memory of the nokia device? Or is there some settings which i may need to tweak? Thanks.
January 30th, 2006 at 12:53 pm
Thanks to all for your comments so far. I spent the weekend moving to a new apartment, where I don’t have an Internet connection yet. So I’m able to write only from my work currently. So replies might come bit late during this week. Anyhow, keep on commenting…
First of all, about Hildon API documentation for Python. I haven’t been able to find any. I’ve used the Hildon documentation at the maemo.org that can be found from here. The function and class names should be same with Python. Does anyone know about Python Hildon API?
I haven’t been planning to Wiki my tutorial anywhere. This is supposed to be sort of a diary about what I’ve been doing with Python. What I can see from these comments is that Pymaemo Wiki might need some sort of tutorial part.
About PIL… I haven’t been working with that yet. Might look into it at some point. But don’t count me on that. Btw… does anyone know if it is beeing ported?
Also pygame example is something to look into. So much to do and so little time.
I have to agree on that Python is a very good language to start to learn programming. That is sort of one reason why I started to blog about this. Seems like lots of people want to code for Nokia 770, but I’d say that to start with C-programming might be too hard at the beginning. And what comes to using an external keyboard, just install SSH server to your Nokia 770 and you can code using your PC, just like I showed in my tutorial.
Happy Python coding to everyone… and remeber this from the Python tutorial. “By the way, the language is named after the BBC show Monty Python’s Flying Circus and has nothing to do with nasty reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!”
January 31st, 2006 at 1:43 am
very informative. However I am having a separate but related problem. I am trying to port some of the other python libraries over to the 770, and the first problem i run into is the lack of a distutils module. Any clues on how to resolve?
thank you
tom w wolf
January 31st, 2006 at 3:24 pm
Hi Tom,
Sorry… I can’t help you with that. I don’t have that much experience in developing modules for Python. Does anyone else have a solution for this?
February 3rd, 2006 at 1:00 pm
[…] One reason why I started to blog about coding for Nokia 770 with Python was exactly this. People want some specific applications and with Python it is relatively easy to develop something and it is relatively easy to learn. Still, it requires quite a lot of time and effort to develop actually usefull software so that is something that the people who use the free software should understand. Someone has sacrificed their personal time to develop the software. […]
February 4th, 2006 at 12:40 pm
[…] I wish I’d seen this blog before I started fighting with this, would have saved me hours of work. […]
February 4th, 2006 at 10:21 pm
Hi.
This sounds very interesting and I’d like to use python for maemo for our new research project. I keep having problems trying to install pymaemo for my Ubuntu linux inside scratchbox… fakeroot doesn’t seem to work correctly and i’ve ran out of options. Did you have any problems in installing of pymaemo? I mean for normal linux OS, not 770 itself. It’s great to see other people trying this out too!
February 6th, 2006 at 11:54 am
Hi morical,
I remember that I installed the ARM version for SDK instead of the i386 version and it worked fine, if I remember right. I’ve been coding mostly with the actual device. For me the “fakeroot dpkg” worked just fine.
February 9th, 2006 at 9:53 am
Hello,
I still don’t have the device to test it, but I some people did test the final version of my tutorial (http://www.gustavobarbieri.com.br/jogos/jogo/, final is a08) and it runs fine if you limit FPS to 20-24 and also convert every image to 16bits (770 video depth).
Always remember these rules:
- Updating the whole screen (as I do in my tutorial) hurts, a lot! Avoid that and use dirty rectangles instead!
- Avoid alpha blend, try to use colorkey (like GIF, you select a color to be transparent).
- Avoid depth transformation: 770 is 16bit, so don’t use 24bit or others!
Anyway, INdT guys are doing some work to speed up SDL and consequently PyGame.
February 12th, 2006 at 4:55 pm
Hello,
Does anyone know how to use the “HildonFileSelection” widget with pyhildon?
“HildonFileChooserDialog” works fine :-), but i need to use a file-filter.
A “dir(hildon)” gives a list of widgets - unfortunately without “HildonFileSelection”. Is this not implemented yet?
thanks
February 14th, 2006 at 12:41 am
Note for people getting “permission denied” errors: Do a chmod +x *.py
Didn’t work for code residing on the memory card though. I think it’s because of the FAT system, which doesn’t like the x flag.
February 14th, 2006 at 12:34 pm
Thanks for your comment Kasper. I didn’t remember to mention this at my tutorial. I’ll mention this on the blog as well.
February 14th, 2006 at 12:36 pm
To Ulli, sorry I haven’t tried the “HildonFileSelection” widget yet. I might look into that some time. If you find a solution to your problem, please share it with us. I’m sure someone will eventually face the same problem. Also if someone else knows about it, post a comment here.
February 14th, 2006 at 12:54 pm
[…] Ok, first of all thanks to Kasper Souren for pointing out that if you are having “permission denied” problems, or otherwise problems running the downloaded scripts, you sould do a “chmod +x *.py” in the folder where you have the script in. […]
February 15th, 2006 at 10:59 pm
[…] The last two days I haven’t been visiting tourist attractions in Buenos Aires. I’ve been hacking and twiddling with my Nokia 770. And it’s just great. After I did the upgrade a while ago, the little machine was a lot more responsive already. Then I installed the Python development environment and started playing more. I played around with Teemu’s Python examples. As it appears, it’s not too hard to get a DICT server running on it, and now I´m working on MaemoDict. I also picked up wik2dict again, to make it work for MediaWiki’s XML database dumps, and I’ll add something that allows you to pick just a bunch of categories, instead of, for example, all of the nearly one million articles of the whole English Wikipedia. More, though unstructured, information about this stuff on my wiki. Well, normally I don’t visit tourist attractions anyway… […]
February 22nd, 2006 at 12:49 am
Has anyone got this working on the i386 rootstrap rather than arm ?? python for me works great on ubuntu and scratchbox …
February 22nd, 2006 at 1:16 am
as does the code !!…please ignore the message above it was a typo error…i have to run it with [sbox-SDK_PC: ~] > python2.4 uitest.py as the standalone still bums out
February 22nd, 2006 at 10:53 am
run-standalone doesn’t seem to work with SDK since the python2.4 binary is installed in a different directory in SDK than on the actual device. Maybe the reason is that if it is installed using “dpkg -i”, it is not installed in “/var/lib/install/” directory. Then the very first line in the code points to a wrong place. But “python2.4 uitest.py” should work fine when running the app in SDK.
March 4th, 2006 at 4:46 pm
Great blog.I seem to be spending my time one Sudoku too much so this is a relief lol.
March 9th, 2006 at 3:34 pm
TNX for the information. Last weekend I tried to run some of the examples, which are included in the source of the
diploma thesis from Ingo Linkweiler:
http://ingo-linkweiler.de/diplom/sum.zip
It’s heavily based on PyGame and to show you one of the examples, which nearly »run out of the box«, I’ve made some screenshots.
One of these (including source) is made available at:
the blog
If you want to take a look at more examples, you may
take a look.
TNX
Ludger
March 18th, 2006 at 11:53 pm
[…] There’s a kind of mid-term solution, which is to drop back into client server mode and write your apps in Python. They’re going to be fat client apps, albeit gorditos instead of the gordos we used to write, with all the attendant problems of version control and mysterious undiagnosable problems vaguely described but sharply complained about by the end users. But with this approach you do get a lot of control you wouldn’t otherwise have (unless, of course, you are Ajax-literate). […]
May 10th, 2006 at 2:57 pm
Hi,
Great tutorial.
But I still need some help
I never used python before and I just got my nokia, so I’m pretty new at this.
I didn’t install the Maemo development environment
I installed pymaemo on the device
That is where it hurts
I installed xterm and the uitest.py works fine (after trying very hard)
so python is installed and working.
but I can’t use any import for python like cgi or pygame.
It can’t be found
But I can’t install the packages in the pymaemo 1.1. arm file
It says the file is already there ??
I have not put the nokia into R&D mode,
it did not seem nescesarry
I would like to know where to ask questions about pymaemo,
I would share my experiments gladly
Can anybody help with these things, please ?
May 10th, 2006 at 4:13 pm
Hi Peter,
I can help you. All the required stuff should be in the pymaemo runtime package. You don’t need to install anything else and you don’t need to use the R&D mode to install it. Just the standard application installer.
Could you post here the part of your code that is giving you problems or the error messages that you get?
May 10th, 2006 at 7:10 pm
Thx Teemu
I would like to run some PIM like things on the nokia.
But the best thing would be working with a webserver (and browser)
I found the FaqWiz.py from Guido van Rossum,
and that would be nice to have around on the nokia
I have made a lite wiki-like thing, based on a simple webserver.py with a very small template engine
But I can not get the needed modules imported
when I try this (in python interpreter)
>>>import cgi
it says:
importerror no module called cgi
same thing with baseHTTPserver
also when I execute webserver.py it reports an import error
So I think they aren’t in the distro
How can I get them installed on the nokia ?
and is there a list of modules included in the runtime-distro ?
Imagine nokia-owners sitting on the same wlan looking at eachothers website
B.T.W. import pygame works
I mainly use PHP and never used python before,
so bare with me.
May 10th, 2006 at 9:42 pm
Hi again Peter,
I checked your problem and you’re right. Those modules you mentioned are not included in the pymaemo release. The included standard modules are at /var/lib/install/usr/lib/python24.zip. You can copy it to your pc and extract it to see what’s in there.
If you need additional modules you can just take the python release from python.org and copy .py files of the modules you need and put them in /var/lib/install/usr/lib/python2.4/ directory. Just remember that you need to have also all dependecies.
Let me know if this helped.
May 11th, 2006 at 3:02 pm
Thanks Teemu
Yes, it helped.
I found that the only things needed where cgi.py and baseHTTPserver.py.
But alas, I could not copy them to the python directory.
You need root to do that, and I’ve tried to do a sudo but the password (rootme) was rejected.
I’ve found the HowtoBecomeRoot thing, but nothing about sudo (only)
So I had to put it in my home directory.
I’ve made a .profile file to append the python pad to the system.
Now I can start the server with “python2.4 ./wserver.py” in xterm.
And yes, it runs very nicely.
But I can only run one xterm at the time (is that normal ?)
So I would like to have a shell script to start python,
and put a menu item (and maybe an icon) in extra to start this script.
Can you help with that ?
I couldn’t get the cgi POST feature working so there is only display and no editing yet.
I’ll keep you informed.
May 11th, 2006 at 4:38 pm
Getting root is quite easy if you have access to a linux machine or you can use a bootable maemo live CD on your windows machine. You only need to enable the r&d mode once.
In Linux just plug in the USB without having the power on and type “flasher –enable-rd-mode –reboot” in the command line. Then it says that it did not find a suitable device and its waiting. Then turn the power on and you have r&d mode enabled. Then the “sudo gainroot” works on your device.
About the xterm on 770. You can start multiple terminals by using the tabs inside the xterm. Open the menu and there file->new tab. About starting a script from extras menu you can check this post.
Keep me posted about the progress. Very interesting stuff that you’re working with.
May 26th, 2006 at 3:19 am
Hi Teemu
It has taken a lot of trouble, but it works now.
I’ve first installed the medusa ftp-server.py,
if you change the default inlog procedure it works very well
So after that it’s easy to upload and change the files on your nokia.
I’ve tried to get the cgihttpserver to work,
it didn’t work because the nokia doesn’t allow the program to “fork”.
So if you change the default behaviour to an in process execution of a py file, it works.
At last I got the Faq wizard (a cgi py script demo )working.
It starts in the browser via the cgiserver.
It is great for taking notes etc.
You should be able to start every python cgi program.
I also got the menu addition to start the servers (http and ftp) working, but I can not stop them after that so this not (yet) a good solution.
I hope that my story is usefull for other people.
have fun, Peter
June 6th, 2006 at 1:15 am
Hey, nice article, cool advice from commentors… One question though, more general about the Nokia 770… when I run “ps -A” I notice a LOT of processes are running, even if I don’t have any background programs running. I want to speed up the machine, since it can be kinda laggy and choppy, hopefully by eliminating unnecessary processes. Any advice in this regard?
June 6th, 2006 at 12:19 pm
Hi plush,
The processes you see by running “ps -A” on your terminal are most likely operating system processes and the N770 is quite well optimized so I’d say that there are no unnecessary prosesses. Unless of course some of the extra applications has crashed and left some of it’s own processes hanging there. But then I’d suggest that you do a reboot if you don’t really know what you are doing.
August 30th, 2006 at 11:12 pm
great site.
October 13th, 2006 at 2:47 am
just let me know, ok?
October 13th, 2006 at 10:07 pm
Why does this not work?
~ $ pwd
/home/user
~ $ ls
MyDocs uitest.py
~ $ run-standalone.sh ./uitest.py
/usr/bin/run-standalone.sh: 11: ./uitest.py: not found
~ $ ./uitest.py
-sh: ./uitest.py: not found
December 14th, 2006 at 1:02 pm
Well, I haven’t yet got Python running on it, but I couldn’t resist trying to add this comment from my 770!
January 10th, 2007 at 2:57 am
i had no idea.
January 30th, 2007 at 4:58 pm
the owls are not what they seem
March 12th, 2007 at 2:15 pm
mmm.. nice design, I must say..
May 3rd, 2007 at 11:11 am
I suspect that’s thereason general public want to read blog….Internet visitors generally create blogs to declare themselves or their secret views. Blog grant them same matter on the monitor screen what they specifically needed,so as the above stuffs declared it.
May 26th, 2007 at 7:56 pm
I am glad to post my views and points in this blog, but I must say that webmaster of this blog has done a very great job to make his blog more informative and more discussable but unfortunately everthing is same here that more than 80% in this and other blogs post their comments for making spam!!!, so i will really all this spam links to google band tool, because webmaster makes blogs for making discuss and for sloving each other problems. thanks http://www.gordoniihoodia.net
June 26th, 2007 at 6:33 pm
What happened to part 2?
Seems to have gone missing.
August 2nd, 2007 at 11:08 am
I have to say, that I could not agree with you in 100% regarding Coding for Nokia 770 using Python - Part 1, but it’s just my opinion, which could be wrong
September 20th, 2007 at 4:27 am
i downloaded and installed.
there is no
/var/lib/install/usr/bin/python2.4
September 20th, 2007 at 3:34 pm
Hi,
This tutorial is rather old. The Python version that is used in N770 and N800 nowadays is Python 2.5. So the location of the Python binary is at /usr/bin/python2.5
October 3rd, 2007 at 3:17 pm
Hey Teemu,
You seem to be the man in the know. I installed Python 2.5 on my 770. I had something pop up that I had to reinstall the OS2006. I went to install Python 2.5 and it is saying I’m missing “libffi4>=4.10-1osso1″ and “osso-thumbnail0=0.5-1fix” - - Not sure what I’m doing wrong on this go around. Can you help me out? Thanks!
July 6th, 2008 at 8:32 am
Hey, where can I get Python ?
Thanks!!