Editing PyMaemo/HildonDesktop
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | = Python bindings for libhildondesktop = | + | == Python bindings for libhildondesktop == |
These bindings allow to create the so called Hildon Home and Status Menu applets (or widgets, in Maemo 5). It consists of two binary packages: | These bindings allow to create the so called Hildon Home and Status Menu applets (or widgets, in Maemo 5). It consists of two binary packages: | ||
Line 6: | Line 6: | ||
* hildon-desktop-python-loader: this is a Hildon Desktop loader for Python plugins. | * hildon-desktop-python-loader: this is a Hildon Desktop loader for Python plugins. | ||
- | == Migrating old Widgets to Maemo 5 == | + | === Migrating old Widgets to Maemo 5 === |
The libhildondesktop version in Maemo 5 contains some API changes that also reflect on the Python bindings. Namely, you should pay attention to the following differences when migrating Home/Status Widgets from older Maemo releases to Fremantle: | The libhildondesktop version in Maemo 5 contains some API changes that also reflect on the Python bindings. Namely, you should pay attention to the following differences when migrating Home/Status Widgets from older Maemo releases to Fremantle: | ||
Line 19: | Line 19: | ||
* Remove the "hd_plugin_get_object" function and instead add a "hd_plugin_type" variable that points to the plugin main class. | * Remove the "hd_plugin_get_object" function and instead add a "hd_plugin_type" variable that points to the plugin main class. | ||
- | == Example - Home widgets (Fremantle only) == | + | === Example - Home widgets (Fremantle only) === |
+ | |||
+ | The code below was based on the C example that can be found on the maemo-examples package sources [https://garage.maemo.org/svn/maemoexamples/branches/fremantle-sdk-testing/maemo-examples/hello-world-home.c]. | ||
<pre> | <pre> | ||
import gtk | import gtk | ||
import hildondesktop | 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): | class HelloWorldDialog(gtk.Dialog): | ||
Line 41: | Line 56: | ||
def __init__(self): | def __init__(self): | ||
hildondesktop.HomePluginItem.__init__(self) | hildondesktop.HomePluginItem.__init__(self) | ||
- | button = | + | button = HelloWorldButton(10) |
button.connect("clicked", hello_world_dialog_show) | button.connect("clicked", hello_world_dialog_show) | ||
button.show_all() | button.show_all() | ||
Line 66: | Line 81: | ||
</pre> | </pre> | ||
- | Save the example code shown above as /usr/lib/hildon-desktop/hello_world_home.py inside your FREMANTLE_X86 target. | + | Save the example code shown above as <b>/usr/lib/hildon-desktop/hello_world_home.py</b> inside your FREMANTLE_X86 target. Next, save the following text as <b>/usr/share/applications/hildon-home/hello_world_home.desktop</b>: |
- | + | ||
- | Next, save the following text as /usr/share/applications/hildon-home/hello_world_home.desktop: | + | |
<pre> | <pre> | ||
Line 78: | Line 91: | ||
</pre> | </pre> | ||
- | + | Make sure the hildon desktop and hildon-home are running. For that, you can use the following commands: | |
+ | |||
+ | <pre> | ||
+ | [sbox]> export DISPLAY=:2 # if you are using scratchbox + Xephyr | ||
+ | [sbox]> af-sb-init.sh start | ||
+ | [sbox]> run-standalone.sh maemo-summoner /usr/bin/hildon-home.launch & | ||
+ | </pre> | ||
- | Now you need to add the newly installed home widget to the desktop. | + | Now you need to add the newly installed home widget to the desktop. For that you can either manually add it to the <b>~/.config/hildon-desktop/home.plugins</b> file, or follow these instructions to add it using the Hildon Desktop interface: |
# Click anywhere on the Maemo desktop background. | # Click anywhere on the Maemo desktop background. | ||
Line 97: | Line 116: | ||
[[Image:Hello_world_home_python2.png]] | [[Image:Hello_world_home_python2.png]] | ||
- | == Example - Status menu widgets (Fremantle only) == | + | === Example - Status menu widgets (Fremantle only) === |
The code below was based on the C example that can be found on the Maemo 5 Developer Guide [http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Application_Development/Writing_Desktop_Widgets#Status_Menu_widgets]. | The code below was based on the C example that can be found on the Maemo 5 Developer Guide [http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Application_Development/Writing_Desktop_Widgets#Status_Menu_widgets]. | ||
<pre> | <pre> | ||
+ | import gobject | ||
import gtk | import gtk | ||
import hildondesktop | import hildondesktop | ||
class ExampleStatusPlugin(hildondesktop.StatusMenuItem): | class ExampleStatusPlugin(hildondesktop.StatusMenuItem): | ||
+ | __gtype_name__ = 'ExampleStatusPlugin' | ||
+ | |||
def __init__(self): | def __init__(self): | ||
hildondesktop.StatusMenuItem.__init__(self) | hildondesktop.StatusMenuItem.__init__(self) | ||
- | + | ||
+ | STATUS_AREA_EXAMPLE_ICON_SIZE = 22 | ||
icon_theme = gtk.icon_theme_get_default() | icon_theme = gtk.icon_theme_get_default() | ||
- | pixbuf = icon_theme.load_icon("general_email", | + | pixbuf = icon_theme.load_icon("general_email", STATUS_AREA_EXAMPLE_ICON_SIZE, gtk.ICON_LOOKUP_NO_SVG) |
self.set_status_area_icon(pixbuf) | self.set_status_area_icon(pixbuf) | ||
- | + | ||
label = gtk.Label("Example message") | label = gtk.Label("Example message") | ||
self.add(label) | self.add(label) | ||
self.show_all() | self.show_all() | ||
- | + | def hd_plugin_get_object(): | |
+ | return gobject.new(ExampleStatusPlugin, plugin_id="example_status_plugin") | ||
+ | |||
+ | if __name__ == "__main__": | ||
+ | obj = hd_plugin_get_object() | ||
+ | obj.show_all() | ||
+ | gtk.main() | ||
</pre> | </pre> | ||
Line 131: | Line 160: | ||
</pre> | </pre> | ||
- | + | Make sure the hildon desktop and hildon-status-menu are running. For that, you can use the following commands: | |
- | The example status menu widget should appear as soon as | + | <pre> |
+ | [sbox]> export DISPLAY=:2 # if you are using scratchbox + Xephyr | ||
+ | [sbox]> af-sb-init.sh start | ||
+ | [sbox]> run-standalone.sh maemo-summoner /usr/bin/hildon-status-menu.launch & | ||
+ | </pre> | ||
+ | |||
+ | The example status menu widget should appear as soon as hildon-status-menu process is started, as the plugin used in this example is of the permanent category. See [http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/Application_Development/Writing_Desktop_Widgets#Status_Menu_widgets] for more information of status menu widgets categories. | ||
This is a screenshot taken on Xephyr showing how the widget will look like: | This is a screenshot taken on Xephyr showing how the widget will look like: | ||
Line 142: | Line 177: | ||
[[Image:Status-menu-2.png]] | [[Image:Status-menu-2.png]] | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- |
Learn more about Contributing to the wiki.