PyMaemo/Portrait mode

m (PyMaemo/PortraitMode moved to PyMaemo/Portrait mode: Naming convention - no CamelCase)
Line 31: Line 31:;f=src/gpodder/gtkui/frmntl/;f=src/gpodder/gtkui/frmntl/

Revision as of 15:51, 11 February 2010

Python auto-rotation (Portrait mode) on Maemo 5

This text is just copy-pasted from the thread at

Says thp:

Now that python-hildon has got support for portrait mode, I've added portrait mode support and auto-rotation to gPodder for Maemo 5, and in order to make my life easier, I've come up with a nice object that you can throw into your own code and that will take care of auto-rotation:;f=src/gpodder/gtkui/frmntl/

The only thing you (might) need to do is to connect your windows to the configure-event signal and check the ratio of the width and height to determine if you need to relayout your window. For some windows (i.e. a window with just a treeview) you don't need to do anything. :-)

Usage: Save the code as "" or find some nice place in the module structure of you project, then use something like the following, and you're done:

from portrait import FremantleAutoRotation

main_window = ... # your main hildon.StackableWindow
app_name = 'NameOfYourApp' # the name of your app
app_version = '1.0' # the version number of your app
initial_mode = FremantleRotation.AUTOMATIC

rotation_object = FremantleRotation(app_name, main_window, app_version, initial_mode)

The rotation object then takes care of enabling and disabling the accelerometer as it is needed. You can provide a preferences UI for your app (see gPodder for an example) and then set the mode of the rotation object like this:


You can create a hildon.PickerButton and a hildon.TouchSelector for your preferences dialog to set the mode. As an example, consult the source code of gPodder's preferences dialog:;f=src/gpodder/gtkui/frmntl/