I think I got the below code right. A lot of variations to test. But even if it's not 100% still illustrates one strategy to start writing a custom ui.View that orientation friendly. Hmm, well I think it is. I have only tried on my iPad Pro. But is suppose to be. But as far as I can see you need to go through these steps. I know some of the code could be simplified, but if there is a simpler way to do the same, love to hear about it. Anyway, it's like the testlab, just trying.
'''
Pythonista Forum - @Phuket2
idea for a starter .py that helps with getting ready to build a
custom view that is orientation friendly, and trying to combine
the ui.View.present method
'''
import ui, editor
def calc_view_frame(pres, f):
style = pres.get('style', '')
m_bar = pres.get('hide_title_bar', False)
m_bar_adj = 0
if not m_bar:
m_bar_adj = 64
# sidebar depreciated...will also give a error, mapped to full_screen
style = style if style != 'sidebar' else 'full_screen'
if style is 'sheet':
return f
elif style is 'panel':
w, h = ui.get_screen_size()
return (0, 0, w, h - 96)
elif style is 'popover':
return f
else:
w, h = ui.get_screen_size()
return (0, 0, w, h - m_bar_adj)
def present_me(v, modal=False, theme=None, *args, **kwargs):
from time import sleep
'''
present_me - combine ui.View.present operations
'''
if not theme:
v.present(*args, **kwargs)
else:
# editor is also passing the title_bar_color and title_color
# kwarg, have to remove it from kwargs, otherwise
# we get an error
if kwargs.get('title_bar_color', None):
kwargs.pop('title_bar_color')
if kwargs.get('title_color', None):
kwargs.pop('title_color')
editor.present_themed(v, theme_name=theme, *args, **kwargs)
# if animated is False, we enter a very small delay. if this
# is not done, can get errorous screen sizes reported
animated = kwargs.get('animated', None)
if not animated:
sleep(.001)
if modal:
v.wait_modal()
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print('init - bounds', self.bounds)
def layout(self):
print('layout - bounds', self.bounds)
if __name__ == '__main__':
_use_theme = False
w, h = 600, 800
f = (0, 0, w, h)
pres = \
{
'style': 'sheet',
'hide_title_bar': False,
'animated': True,
'title_bar_color': 'blue',
'title_color': 'orange',
'popover_location': (0,0),
'orientations': None,
}
theme = 'Oceanic'
#theme = ''
modal = False
f = calc_view_frame(pres,f)
mc = MyClass(frame=f, bg_color='white', name = 'present_me')
present_me(mc, modal = True, theme = theme, **pres)
print('finished')