0

For an app that i'm developing i need to detect when the screen is flipped. I thought of something like on_pause() or on_start() that resides in the main application class, but I found nothing about it.

Any suggestions?

thanks


updates:

As suggets @jligeza i tried to add on_rotate as follow:

from kivy.core.window import Window
class guiApp(App):
    def on_start(self):
        ## Bind android flip-screen
        def _on_flip_screen(ee):
            print "flipping"
        Window.bind(on_rotate=_on_flip_screen)

but this do nothing (no print showed when screen rotate).

I also tried it with on_flipbut with this event the app crash at start.

No good solution for this kind of problem?

1 Answers1

0

You can bind a function to on_rotate event of the Window class.

from kivy.core.window import Window

def on_window_rotate(obj, degrees):
    print 'rotated degrees:', degrees

Window.bind(on_rotate=on_window_rotate)
jligeza
  • 4,544
  • 6
  • 23
  • 31
  • Thank jligeza. I notice that in the window class there is an on_flip() event. There is any difference between this and on_rotate? –  Apr 30 '16 at 16:39
  • @Tungsteno It's something related to OpenGL, I'm not sure what exactly it does. – jligeza Apr 30 '16 at 16:45
  • I just tested both, but it seems that do not work. on_flip crash the app. :( –  Apr 30 '16 at 16:55
  • I putted it on the on_start method of my main app class. Is it correct? –  Apr 30 '16 at 17:14
  • @Tungsteno If it doesn't work then maybe try binding to Window height or width. – jligeza Apr 30 '16 at 17:21
  • @Tungsteno Another option (which will surely work) is calling a java class to get the orientation: http://stackoverflow.com/questions/3663665/how-can-i-get-the-current-screen-orientation – jligeza Apr 30 '16 at 17:25
  • I prefer to stay in python environment. –  Apr 30 '16 at 17:34
  • That java class call is probably the right way to do it, and I don't think it's wrapped in a python api yet (e.g. in [plyer](https://github.com/kivy/plyer)). You'd call it from python with pyjnius, not actually write any java. Feel free to propose a PR to plyer's orientation facade that would add this functionality. – inclement Apr 30 '16 at 18:38