PyMaemo/Portrait mode

(New page: == Python auto-rotation (Portrait mode) on Maemo 5 == ''This text is just copy-pasted from the [http://talk.maemo.org/showthread.php?t=31940 thread at talk.maemo.org].'' ''Says thp:'' N...)
m (fremantle link)
 
(3 intermediate revisions not shown)
Line 5: Line 5:
''Says thp:''
''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:
+
Now that python-hildon has got support for portrait mode, I've added portrait mode support and auto-rotation to gPodder for [[Open development/Maemo roadmap/Fremantle|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
http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/portrait.py
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.NEVER)
 +
rotation_object.set_mode(FremantleRotation.ALWAYS)
 +
</source>
 +
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:
-
rotation_object.set_mode(FremantleRotation.AUTOMATIC)
+
http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/preferences.py
-
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:
+
[[Category:Python]]
-
 
+
-
http://repo.or.cz/w/gpodder.git?a=blob;f=src/gpodder/gtkui/frmntl/preferences.py
+

Latest revision as of 12:42, 8 September 2010

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