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.
How to switch UI menus?
-
I have two UI's, where I wish to make it so that when a button on the first UI is pressed, the other one opens. However when the button is pressed, it says "view is already running". Can I not have both active at once? If not how do I remove the first UI so I can activate the second one?
-
Due to some bugs in how views get closed in pythonista, you cannot easily re-present a view that was already presented. (There might be some caveats, I forget)
So I'm guessing that you can display view B, but when trying to show view A again, you get the failure.
One approach is to use a NavigationView, which will give you the sliding animation. Another approach is to have both views as subviews to a root view, and either add/remove from the root, or hide/unhide, or send_to_front, etc.
-
If you are talking about a main view and a pop up menu, you can present the second view as a sheet (instead of fullscreen).
-
Perhaps also play with modal, try this
import ui v1 = ui.View() v1.background_color = 'yellow' v1.name = 'v1' b1 = ui.Button() b1.title = 'view v2' b1.frame = (10,10,100,20) v1.add_subview(b1) v1.present() v2 = ui.View() v2.background_color = 'cyan' v2.name = 'v2' b2 = ui.Button() b2.title = 'close v2' b2.frame = (10,10,100,20) def b2_action(sender): v2.close() b2.action = b2_action v2.add_subview(b2) def b1_action(sender): v2.present() v2.wait_modal() b1.action = b1_action
-
I wanted to post this when you recently posted this but if you still need it, here you go. You can even do more views as long as you old_view.close() then old_view.wait_modal() then new_view.present()
import ui import dialogs v1 = ui.View() v1.bg_color = "#eee" v1.name = "v1" v2 = ui.View() v2.bg_color = "#444" v2.name = "v2" item_list = [] entries = 28 for i in range(entries): item_list.append("Item " + str(i + 1)) def button_item_action(sender): if sender is v1Btn: v1.close() v1.wait_modal() v2.present('fullscreen') else: v2.close() v2.wait_modal() v1.present('fullscreen') def list_action(sender): s = dialogs.list_dialog("Select an Item", item_list) if s is not None: lblList.text = s temp_a, temp_b = ui.get_window_size() w = min(temp_a, temp_b) h = max(temp_a, temp_b) m = 0.05 * w v1List = ui.Button() v1List.tint_color = "#222" v1List.image = ui.Image('iob:navicon_32') v1List.frame = (m, m, 0.1 * w, 0.1 * w) v1List.action = list_action v1List.border_width = 1 lblList = ui.Label() lblList.bg_color = "#fff" lblList.x = v1List.x + v1List.width + m lblList.y = m lblList.width = w - lblList.x - m lblList.height = v1List.height lblList.border_width = 1 lblList.alignment = ui.ALIGN_CENTER v1Btn = ui.ButtonItem(title="Open v2") v2Btn = ui.ButtonItem(title="Open v1") v2Btn.action = v1Btn.action = button_item_action v1.add_subview(v1List) v1.add_subview(lblList) v1.right_button_items = (v1Btn,) v2.right_button_items = (v2Btn,) v1.present('fullscreen') lblList.autoresizing = "W"
-