maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   HOWTO: Python auto-rotation (Portrait mode) on Maemo 5 (https://talk.maemo.org/showthread.php?t=31940)

thp 2009-09-21 22:54

HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Hello!

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=bl...tl/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:

Code:

from portrait import FremantleAutoRotation
FremantleAutoRotation()

Just make sure your windows are real hildon.StackableWindow, and everything should work out of the box.

linuxeventually 2009-09-21 23:06

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Screenshots please :p

pycage 2009-09-22 06:03

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Good to hear that autorotation finally made it into python-hildon. No more need for setting XAtoms on the GdkWindow. :)
I like the idea of iterating through the whole window stack on rotation signal. This makes it really easy.

qole 2009-09-22 06:23

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Heh, 3 months after N900 sales start, Nokia will think that nobody cares about rotation anymore. But the truth will be that everyone will be using community apps that do the same thing and that have auto-rotation built-in... :)

thp 2009-09-22 10:40

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Quote:

Originally Posted by pycage (Post 331243)
I like the idea of iterating through the whole window stack on rotation signal. This makes it really easy.

I've been thinking about LD_PRELOAD and some funky gtk_main overloading to achieve auto-rotation for binaries using the same technique of getting the window stack and setting flags on all windows. It's just an idea, and some rough code, but that might be something that will enable more auto-rotation in the future...

timsamoff 2009-09-22 15:58

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Quote:

Originally Posted by qole (Post 331249)
Heh, 3 months after N900 sales start, Nokia will think that nobody cares about rotation anymore. But the truth will be that everyone will be using community apps that do the same thing and that have auto-rotation built-in... :)

This is very possible. When I showed Peter Schneider ConBoy and how it rotated, he was floored. :D

Tim

Jack6428 2009-09-22 16:30

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Quote:

Originally Posted by timsamoff (Post 331579)
This is very possible. When I showed Peter Schneider ConBoy and how it rotated, he was floored. :D

Tim

Peter is a great guy...i watched all the N900 videos that came out and he was the best promoter lol..give him regards if you see him again...

thp 2009-09-24 12:54

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
I have updated the code to support forced-portrait and forced-landscape mode in addition to the auto-rotation mode (auto-rotation is still the default). You can now also pass your main window to the constructor which will be slightly more efficient than querying the HildonWindowStack for rotation (it still works without passing the main window if for any reason you cannot get a reference to it..). Usage:

Code:

main_window = .... # set this to your main window

rotation = FremantleRotation(main_window)
# we're in auto-rotation mode now

rotation.set_mode(FremantleRotation.ALWAYS)
# we're now forcing portrait mode

rotation.set_mode(FremantleRotation.NEVER)
# we're now forcing landscape mode

rotation.set_mode(FremantleRotation.AUTOMATIC)
# and automatic mode again

# you can also get the mode
mode = rotation.get_mode()
if mode == FremantleRotation.AUTOMATIC:
    # do something here
elif mode == FremantleRotation.ALWAYS:
    # something else here
elif mode == FremantleRotation.NEVER:
    # you get the idea...

You can use this to add a "Orientation" setting to your preferences dialog and let the user decide what works best for him/her. The code is at the same link as the original post (you can also simply git clone the gPodder source repository and find the code in src/gpodder/gtkui/frmntl/portrait.py).

christexaport 2009-09-24 22:57

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
I'm trying to draw support for THIS BRAINSTORM IDEA about Nokia supporting Automatic Screen Rotation in the entire UI of Maemo 5/N900. Please give it a look and give me a hand. I thought since this thread mentioned rotation, maybe someone might be interested.

YoDude 2009-09-24 23:11

Re: HOWTO: Python auto-rotation (Portrait mode) on Maemo 5
 
Quote:

Originally Posted by christexaport (Post 333233)
I'm trying to draw support for THIS BRAINSTORM IDEA about Nokia supporting Automatic Screen Rotation in the entire UI of Maemo 5/N900. Please give it a look and give me a hand. I thought since this thread mentioned rotation, maybe someone might be interested.

This thread didn't just mention rotation it is an actual "HowTo" posted by thp on 09-21-09 06:54 PM 3 days before your posted Brainstorm on 2009-09-24 21:42 UTC


What's up with that? I'm confused. :confused:


All times are GMT. The time now is 05:08.

vBulletin® Version 3.8.8