Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Any iOS device
-
Would some Pythonista scholar provide a simple example of any type of "view" coded such it will stretch nicely to any iOS screen? iPad, iPhone 4, 5, 6+...... Also, in landscape modes....
I just want to understand the concept.....
-
import ui mainview = ui.View() mainview.present() subview = ui.View(frame=mainview.bounds) mainview.add_subview(subview) subview.border_width = 5 subview.border_color = 'pink' subview.background_color = 'green' subview.flex = 'WH'
Edit: Alternative suggested by @JonB below is useful because it formats the entire ui before presenting it to the user:
import ui w, h = ui.get_screen_size() mainview = ui.View(frame=(0, 0, w, h)) subview = ui.View(frame=mainview.bounds) mainview.add_subview(subview) subview.border_width = 5 subview.border_color = 'pink' subview.background_color = 'green' subview.flex = 'WH' mainview.present()
Orientation 'portrait-upside-down' seems to not work in Pythonista v1.6 Beta!
-
The basic trick as ccc showed is to have your root/main view presented before you add any other subviews. That way, it gets sized to the fullScreen. Alternatively, set the frame size, add components, and set the flex properties, and then present.
The tricky bit is getting everything flexing the way you want. Most likely, you will need to implement `layout(self)' inside a custom View, which would allow you to move components around depending on the new size. There are currently not many layout managers that make this easier (I started a flow layout, and a vbox/hBox layout here , but the inability to specify a preferred, minimum, and maximum frame size for a component makes good layout managers nearly impossible.
This gives me an idea for an action menu script which takes the currently loaded View, and shows you what the currently loaded view would look like on different size devices.
Can anyone with an iphone 5, iphone 6, iphone 6+, and/or iPad Air or retina tell me what you get for the following script, running in both landscape and portrait? The main question is whether the title bar is 64 px tall on all devices.
import ui, time presentmodes=[('full_screen',True),('full_screen',False),('panel',True),('panel',False)] for m in presentmodes: v=ui.View() w=ui.WebView() v.add_subview(w) v.present(m[0],hide_title_bar=m[1]) orientation=w.eval_js('window.orientation') print m, orientation, v.frame time.sleep(1.0) v.close() time.sleep(1.0) time.sleep(1.0) print 'complete'
-
JonB,
iPhone 6+
Portrait:
Landscape:
-
Interesting -- so in landscape, the menu bar is only half as high on iphone?
-
iPad Air 2 Landscape:
<code>('full_screen', True) 90 (0.0, 0.0, 1024.0, 768.0)</code>
<code>('full_screen', False) 90 (0.0, 64.0, 1024.0, 704.0)</code>
<code>('panel', True) 90 (0.0, 0.0, 1024.0, 704.0)</code>
<code>('panel', False) 90 (0.0, 0.0, 1024.0, 704.0)</code>
<code>complete</code>
iPad Air 2 Portrait:
<code>('full_screen', True) 0 (0.0, 0.0, 768.0, 1024.0)</code>
<code>('full_screen', False) 0 (0.0, 64.0, 768.0, 960.0)</code>
<code>('panel', True) 0 (0.0, 0.0, 768.0, 960.0)</code>
<code>('panel', False) 0 (0.0, 0.0, 768.0, 960.0)</code>
<code>complete</code>
-
iPad 4 retina Landscape:
('full_screen', True) 90 (0.0, 0.0, 1024.0, 768.0) ('full_screen', False) 90 (0.0, 64.0, 1024.0, 704.0) ('panel', True) 90 (0.0, 0.0, 1024.0, 704.0) ('panel', False) 90 (0.0, 0.0, 1024.0, 704.0) complete
iPad 4 retina Portrait:
('full_screen', True) 0 (0.0, 0.0, 768.0, 1024.0) ('full_screen', False) 0 (0.0, 64.0, 768.0, 960.0) ('panel', True) 0 (0.0, 0.0, 768.0, 960.0) ('panel', False) 0 (0.0, 0.0, 768.0, 960.0) complete
-
@donnieh: The forums now support images?! There's always been a markdown image insertion button, but recently it stopped working. Wait, let me try:
-
It worked!
-
Pretty picture.
-
First image that came up on Google Images with the search term "image" ;-)