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.
Position Relative to screen center
-
The easiest would be to use the auto-resizing inspector in the UI editor (or
flex
attribute when you do this from code). For centering a view vertically and horizontally in its parent, it should beLRTB
(flexible left, right, top and bottom margins). For a view that stretches horizontally, and is vertically centered, it should beWTB
. You can experiment with this in the UI editor (there's an animated preview to help you get an idea of the effect of different settings). -
Okay, it is flexing when I rotate the ipad, but what do I set the popover_location parameter of the UI.present() function to, to center the UI in the center if the screen when I run the workflow.
It would seem that there is a constant for the screen's center, without having to use another UI element as the parent. This way, if someone is using a different screen size, it will take the dimensions of the screen and divide both the height and width by two, and then center at those coordinates.
To center my button in a parent view I had to do:
button.center = (window.width/2,window.height/2)
But the window itself, I want to center in the screen, No matter what screen size or orientation.
Edit
I found ui.get_screen_size(). How do I get the length component separate from the height component?
-
You can't really do that with a popover because it's currently not possible to get the current orientation. You might want to consider using a sheet instead...
-
Could I resize the dimensions of a sheet?
Also, I tried this:
popover_location=(ui.get_screen_size()[0]/2,ui.get_screen_size()[1]/2)
And it almost works. I used it along with flex too.
The portrait orientation is off, but, well take a look
-
Hmmm! I just saw that the screen size function would locate the arrow of the popover at the center! not the center of the popover. That is why it is off.
-
While there is nit an easy way to get orientation, if the keyboard frame is displayed, you can use
ui.get_keyboard_frame
to determine the current orientations width. -
Take that back...
ui.WebView().eval_js('window.orientation')
Does give you orientation. -
Okay. Thanks. I put this one on hold. I may pick it up later. Thanks!
-
I have picked this back up:
<pre>
import ui
import workflowscreen_size = ui.get_screen_size()
screenX = screen_size[0]
screenY = screen_size[1]window = ui.load_view()
window.flex = "WL"
window.height = 200
window.width = screenX
window.present("popover",False,(screenX,(screenY/2)))view = window['view2']
view.text = workflow.get_input()
</pre>Now I have to add the orientation
-
See:
hereThis includes a 1 pixel webview, which is used to get orientation, see e.g. line 61 and following for the possible values