ui-module: Change view‘s size
Trüff last edited by
I am currently having some problems with the ui-module in Pythonista.
The following code is a representation of the situation I am dealing with in my program:
import ui def sw1_changed(sender): if sender.value == True: # switch has been turned on v.height = 400 else: # switch has been turned off v.height = 200 v = ui.View() v.name = "View" v.width = 200 v.height = 200 v.bg_color = 1.0 v.border_width = 3 v.border_color = (1.0, 0.0, 0.0) sw1 = ui.Switch() sw1.name = "Switch" sw1.action = sw1_changed sw1.center = (v.width/2, v.height/2) v.add_subview(sw1) v.present('sheet')
I created a
ui.Viewobject that contains a
ui.Switchobject as a subview. When the switch is pressed the size of the its parent view is supposed to change. If the switch is turned on, it‘s height should increase from 400 to 200 and when it‘s turned off, it should turn back to it‘s original height of 200.
(Running the code yourself could be helpful to understand what I mean.)
The resizing behaviour of the View does not work out as I want it to. The program does change the View‘s height in some way which is shown by the red border surrounding View. The bottom of the border disappears when the switch is turned on which (I think) means that it expands it‘s space where subviews could be placed onto. However the added space is not visible on the screen.
My question is: How can I get the View to change it‘s height so that it covers a bigger part on the screen?
I‘ve already tried out some stuff with the
View.centeras well as the
typeargument of the
View.presentmethod but none of it fixed my problem.
I would be really happy if someone could help me out with my problem. Thanks for every answer in advance. 😁
cvp last edited by
@Trüff It is impossible to change the size of a presented view...
JonB last edited by
The trick in this case is that, while you cannot resize a view presented using
present, you could have another blank view be the one you present, and then the view you are resizing is a subview.
@polymerchm implemented this in a clean way, for use in settings menus, where he creates a semi-transparent view that dims whatever is on screen (could be another view), and creates a Fullscreen "shield" view. Inside that shield, you can have a subview that draws any other view wherever you want on the screen, and now can be resized like any other view.:
This concept can be extended to detect touches on the shield, to dismiss it when user taps outside the settings view.
Another option is to use my overlay class, which is designed for draggable window overlays.
Even if you don't use the actual draggable overlays, this shows how you can grab the pythonista app window root and add subviews the the main pythonista app window, that can live wherever you want and can be resized, however you have to take a little care in order to not crash things.
Trüff last edited by
Aaaahhhh. Okay. I understand. So then I‘d give the presented view a transparent background and remove its title bar.
Thank you. That really helped me.