PyMaemo/Portrait mode

(use <source> and <code>)
Line 12: Line 12:
Usage: Save the code as "portrait.py" or find some nice place in the module structure of you project, then use something like the following, and you're done:
Usage: Save the code as "portrait.py" or find some nice place in the module structure of you project, then use something like the following, and you're done:
 +
<source lang="python">
 +
from portrait import FremantleAutoRotation
-
from portrait import FremantleAutoRotation
+
main_window = ... # your main hildon.StackableWindow
-
+
app_name = 'NameOfYourApp' # the name of your app
-
main_window = ... # your main hildon.StackableWindow
+
app_version = '1.0' # the version number of your app
-
app_name = 'NameOfYourApp' # the name of your app
+
initial_mode = FremantleRotation.AUTOMATIC
-
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)
+
 +
rotation_object = FremantleRotation(app_name, main_window, app_version, initial_mode)
 +
</source>
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:
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:
-
 
+
<source lang="python">
-
rotation_object.set_mode(FremantleRotation.AUTOMATIC)
+
rotation_object.set_mode(FremantleRotation.AUTOMATIC)
-
rotation_object.set_mode(FremantleRotation.NEVER)
+
rotation_object.set_mode(FremantleRotation.NEVER)
-
rotation_object.set_mode(FremantleRotation.ALWAYS)
+
rotation_object.set_mode(FremantleRotation.ALWAYS)
-
 
+
</source>
-
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:
+
You can create a <code>hildon.PickerButton</code> and a <code>hildon.TouchSelector</code> for your preferences dialog to set the mode. As an example, consult the source code of gPodder's preferences dialog:
http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/preferences.py
http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/preferences.py
[[Category:Python]]
[[Category:Python]]

Revision as of 11:57, 22 June 2010

Python auto-rotation (Portrait mode) on Maemo 5

This text is just copy-pasted from the thread at talk.maemo.org.

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:

http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/portrait.py

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 "portrait.py" 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:

rotation_object.set_mode(FremantleRotation.AUTOMATIC)
rotation_object.set_mode(FremantleRotation.NEVER)
rotation_object.set_mode(FremantleRotation.ALWAYS)

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:

http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/preferences.py