In the new ui module, is there a way to get screen width?
Or, to change popover location to a different corner? For instance, by default popover goes to top right... How would I go about moving it to the bottom right, and have it stay there across orientation changes?
Forum Archive
Get current screen or orientation width?
Can't you just get the width by using root_view.width?
If I could find such a root_view, then yes. Superview() on a view returns nothing. I couldn't find anything in the ui module that looked like screen width
It's not really possible, I'm afraid. You can't change the location of a popover after it's been presented, and there's no good way to determine the current device orientation (and ui.get_screen_size is orientation-independent, so that won't help).
Sheesh, not sure how I missed ui.get_screen_size ... that's what I was looking for. Thanks!
Actually, get_keyboard_frame changes with orientation, so can be used to determine orientation. I was trying to put a pop up near they console entry, so that'll work perfect.
For what it's worth:
ui.WebView().eval_js('window.orientation')
Returns the orientation (0,90,180, 270), so is an easy way to get orientation!
What am I doing wrong?
import ui
print('\nRotate your device to see the various orientations.')
old_orientation = None
while True:
new_orientation = ui.WebView().eval_js('window.orientation')
if old_orientation != new_orientation:
print('Screen orientation is {}.'.format(new_orientation))
old_orientation = new_orientation
@ccc I think you need...
import ui
print('\nRotate your device to see the various orientations.')
v=ui.WebView()
v.hidden = True
v.present('panel')
old_orientation = None
while True:
new_orientation = v.eval_js('window.orientation')
if old_orientation != new_orientation:
print('Screen orientation is {}.'.format(new_orientation))
old_orientation = new_orientation
Note: it gives -90 not 270 (I'll update the code I posted for JonB in the Unsupported File Type thread)