PyMaemo/HildonDesktop
(New page: == Python bindings for libhildondesktop == These bindings allow to create the so called Hildon Home applets (or widgets, in Maemo 5). It consists of two binary packages: * python-hildond...) |
(→Python bindings for libhildondesktop) |
||
Line 4: | Line 4: | ||
* python-hildondesktop: the actual Python bindings. Can be used to write standalone widgets, or ones that can be added by the user using the "Add widget" option in Maemo 5. | * python-hildondesktop: the actual Python bindings. Can be used to write standalone widgets, or ones that can be added by the user using the "Add widget" option in Maemo 5. | ||
- | * hildon-desktop-python-loader: this is a Hildon Desktop loader for | + | * hildon-desktop-python-loader: this is a Hildon Desktop loader for Python plugins. |
=== Example === | === Example === |
Revision as of 01:35, 26 May 2009
Python bindings for libhildondesktop
These bindings allow to create the so called Hildon Home applets (or widgets, in Maemo 5). It consists of two binary packages:
- python-hildondesktop: the actual Python bindings. Can be used to write standalone widgets, or ones that can be added by the user using the "Add widget" option in Maemo 5.
- hildon-desktop-python-loader: this is a Hildon Desktop loader for Python plugins.
Example
The code below was based on the C example that can be found on the maemo-examples package sources [1].
import gobject import gtk import hildondesktop class HelloWorldButton(gtk.Button): def __init__(self, padding): gtk.Button.__init__(self) icon_theme = gtk.icon_theme_get_default() icon = icon_theme.load_icon("hello", 40, 0) if icon is None: icon = icon_theme.load_icon("qgn_list_gene_default_app", 40, 0) icon_image = gtk.Image() icon_image.set_from_pixbuf(icon) icon_image.set_padding(padding, padding) self.add(icon_image) self.show_all() class HelloWorldDialog(gtk.Dialog): def __init__(self): gtk.Dialog.__init__(self, "Hello World", None, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR, ("Close", gtk.RESPONSE_OK)) self.vbox.add(gtk.Label("Hello World!")) self.show_all() def hello_world_dialog_show(button): dialog = HelloWorldDialog() dialog.run() dialog.destroy() class HelloHomePlugin(hildondesktop.HomePluginItem): __gtype_name__ = 'HelloHomePlugin' def __init__(self): hildondesktop.HomePluginItem.__init__(self) button = HelloWorldButton(10) button.connect("clicked", hello_world_dialog_show) button.show_all() self.add(button) def hd_plugin_get_object(): return gobject.new(HelloHomePlugin, plugin_id="hello_world_home") if __name__ == "__main__": obj = hd_plugin_get_object() obj.show_all() gtk.main()
To test it, save it as /usr/lib/hildon-desktop/hello_world_home.py inside your FREMANTLE_X86 target. Next, save the following text as /usr/share/applications/hildon-home/hello_world_home.desktop:
[Desktop Entry] Name=Hello, World! (Python) Comment=Example Home Python plugin Type=python X-Path=hello_world_home.py
Make sure the hildon desktop and hildon-home are running. For that, you can use the following commands:
export DISPLAY=:2 # if you are using scratchbox + Xephyr af-sb-init.sh start run-standalone.sh maemo-summoner /usr/bin/hildon-home.launch &
Now you need to add the newly installed home widget to the desktop. For that you can either manually add it to the ~/.config/hildon-desktop/home.plugins file, or follow these instructions to add it using the Hildon Desktop interface:
- Click anywhere on the Maemo desktop background
- You should see a "engine" icon on the top right. Click on it.
- It will be shown a menu bar containing "Desktop menu" and "Done". Click on "Desktop menu"
- You should now see a menu with 4 buttons. Click on the "Add widget" button.
- A menu containing the list of installed widgets will appear. Select the one we installed (called "Hello, World! (Python)")
- Finally, click on "Done"
You should then see the following: