Welcome to Teemu’s Blog

Picture of me.

Hi, my name is Teemu Harju. I'm a 27-year-old engineer from Espoo, Finland and this is site is my contribution to the world wide web. I'll write here about all kinds of stuff that interests me. Python coding is my passion. I'm also interested in different kinds of web technologies.

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.

Simple Python example

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.

Python:
  1. #!/var/lib/install/usr/bin/python2.4
  2.  
  3. import gtk
  4. import hildon
  5.  
  6. class UITest:
  7.  
  8.   def __init__(self):
  9.     self.app = hildon.App()
  10.     self.appview = hildon.AppView("Appview Title")
  11.     self.label = gtk.Label("My first Python App...")
  12.  
  13.     self.app.set_title("App Title")
  14.     self.app.set_two_part_title(True)
  15.     self.app.set_appview(self.appview)
  16.  
  17.     self.appview.connect("destroy", self.destroy)
  18.  
  19.     gtk.Container.add(self.appview, self.label)
  20.  
  21.     self.label.show()
  22.     self.app.show()
  23.  
  24.   def destroy(self, widget, data=None):
  25.     gtk.main_quit()
  26.  
  27.   def main(self):
  28.     gtk.main()
  29.  
  30. if __name__ == "__main__":
  31.   uitest = UITest()
  32.   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. ;)

63 Responses to “Coding for Nokia 770 using Python - Part 1”

  1. JasonR Says:

    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

  2. Teemu Says:

    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.

  3. JasonR Says:

    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

  4. Rudá Moura Says:

    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á

  5. Michael Bendio Says:

    I’m really glad to see Python on the 770. Thanks so much for the tutorial. More, please!

  6. Rachid Says:

    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

  7. Jim Says:

    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…

  8. JasonR Says:

    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

  9. chw Says:

    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

  10. rachid Says:

    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

  11. Jon Says:

    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.

  12. Teemu Says:

    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!”

  13. Tom W Wolf Says:

    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

  14. Teemu Says:

    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?

  15. Teemu’s Blog » Blog Archive » Thoughts about software development and Nokia 770 Says:

    […] 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. […]

  16. Webninja » Blog Archive » Nokia 770, Development, and How Cool is Python? Says:

    […] I wish I’d seen this blog before I started fighting with this, would have saved me hours of work. […]

  17. morical Says:

    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!

  18. Teemu Says:

    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.

  19. Gustavo Sverzut Barbieri Says:

    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.

  20. Ulli Kraemer Says:

    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

  21. Kasper Souren Says:

    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.

  22. Teemu Says:

    Thanks for your comment Kasper. I didn’t remember to mention this at my tutorial. I’ll mention this on the blog as well.

  23. Teemu Says:

    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.

  24. Teemu’s Blog » Blog Archive » Coding for Nokia 770 using Python - Misc Notes Says:

    […] 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. […]

  25. Guaka’s blog » Blog Archive » MaemoDict, wik2dict Says:

    […] 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… […]

  26. Ian Says:

    Has anyone got this working on the i386 rootstrap rather than arm ?? python for me works great on ubuntu and scratchbox …

  27. Ian Says:

    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

  28. Teemu Says:

    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.

  29. Sudoku Says:

    Great blog.I seem to be spending my time one Sudoku too much so this is a relief lol.

  30. Dr. L. Humbert Says:

    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

  31. Wordpress » Blog Archive » Healthcare Input: mission impossible? Possible solutions Says:

    […] 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). […]

  32. Peter Says:

    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 ?

  33. Teemu Says:

    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?

  34. Peter Says:

    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.

  35. Teemu Says:

    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.

  36. Peter Says:

    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.

  37. Teemu Says:

    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. :)

  38. Peter Says:

    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

  39. plush Says:

    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?

  40. Teemu Says:

    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.

  41. dan Says:

    great site.

  42. TMOCR Says:

    just let me know, ok?

  43. Juge Says:

    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

  44. paper shredders Says:

    Well, I haven’t yet got Python running on it, but I couldn’t resist trying to add this comment from my 770!

  45. Mike Says:

    i had no idea.

  46. cooper Says:

    the owls are not what they seem

  47. italia Says:

    mmm.. nice design, I must say..

  48. Alisya Says:

    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.

  49. Angeline Julie Says:

    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

  50. Luis Says:

    What happened to part 2?
    Seems to have gone missing.

  51. Daniel Says:

    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 :)

  52. name Says:

    i downloaded and installed.
    there is no
    /var/lib/install/usr/bin/python2.4

  53. Teemu Says:

    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

  54. Kevin Says:

    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!

  55. Chris Says:

    Hey, where can I get Python ?
    Thanks!!

  56. Pwhndvve Says:

    Rimsky went look closer buy cytotec then announced daughters.

  57. sam Says:

    hi

    can you point me to some info on how to code on the n810 itself . such as how do i create a python script file on device and run it

    cheers

  58. Beaupeslap Says:

    omg.. good work, dude

  59. Barabum Says:

    Чего и следовало ожидать, хозяин сайта нетипично накропал.

  60. Anastasiaprostia Says:

    Hey :)

    Amazing weight loss stories here,
    And here you can buy Anatrim
    http://www.zmeii.com/?toxaawgjgw

    I’ve always had trouble with my weight ever since I was young. Of course I tried all the “best” fat loss products, nothing helped very much. It wasn’t til I tried Anatrim that I saw the pounds seriously start to melt away! Nothing helped me lose weight faster. I literally saw 15 pounds melt away within the first few weeks! There’s nothing more exciting than watching pounds disappear, especially when you’ve tried all sorts of different methods and products before. I’ve since read up on Anatrim and am amazed at the number of people who have benefited from its amazing results. I’m halfway to my goal, Anatrim will get me the rest of the way ;)

  61. Halo Says:

    ronald reagon
    [URL=http://fofyjajuhawafa.xhost.ro/ronald-reagon/]ronald reagon[/URL]

  62. endotdelo Says:

    I could agree in 100%.
    He’s the best part if this.

    cheers,
    ______________
    endotdelo
    oprah winfrey acai berry
    http://blogcastrepository.com/members/mikeyacai.aspx

  63. Hanis @ flower deliveries Says:

    I’ve been researching the web for my research on this subject. I’m so glad what you shared bestows a new proportion to the information I’m accumulating. I truly appreciate the way which you look at this subject, it offer me a unique means of looking at it now. Thanks for the share.

Leave a Reply