-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
I am having a problem with screen rotate under Python for Android.
The example below does not re-layout on device rotation. The contents does rotate, but is not not resized for the new width and height. It does re-layout when I tap the screen after rotation.
It is compiled with "--orientation sensor". I am using p4a master branch dated 5/17/2018.
On device rotation, I'm looking for a way to trigger re-layout from Python. My code can implement the re-layout.
It appears that on_pause() and on_resume() are called when the app enters/returns from the background. Unlike Java on Android they are not called on rotation. Not my expectation, but I can see why it is that way.
It appears that on_rotate() is never called, either from the App class or layout class. What am I missing?
Once I have a trigger I assume I will have to get the new size using Java, because Python's Window.size does not appear to be updated till after re-layout.
Suggestions for handling screen rotation re-layout?
Thanks.
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.properties import StringProperty
from kivy.app import App
Builder.load_string('''
<LifecycleScreen>:
cols: 1
Label:
text: root.label0
Label:
text: root.label1
Button:
text: 'Reset'
on_release: root.my_callback()
''')
class LifecycleScreen(GridLayout):
label0 = StringProperty('Got Call:False,False,False.')
label1 = StringProperty('Original Orientation')
def on_rotate(self):
label1 = StringProperty('Rotated')
def my_callback(self):
self.parent.pause = False
self.parent.resume = False
self.parent.rotate = False
self.label1 = 'Orientation Reset'
class LifecycleApp(App):
def __init__(self,**kwargs):
super (LifecycleApp,self).__init__(**kwargs)
self.screen = None
self.pause = False
self.resume = False
self.rotate = False
def build(self):
self.screen = LifecycleScreen()
return self.screen
def label_text(self):
self.screen.label0 = 'Got Call:{},{},{}.'.format(self.pause,
self.resume,
self.rotate)
def on_pause(self):
self.pause = True
self.label_text()
return True
def on_resume(self):
self.resume = True
self.label_text()
def on_rotate(self):
self.rotate = True
self.label_text()
if __name__ == '__main__':
LifecycleApp().run()