Forum Archive

Change the View (without NavigationBar)

NRWTV2

Heyy!!
I got two pyui Files: intro.pyui and mail.pyui, if i start the code only intro.pyui is shown on the screen, now i added a button called "Open Mail", now i want to hide "intro.pyui" and open "mail.pyui".

But how?
Thx

Phuket2

@NRWTV2 , I tried several things to remove the first view. I didn't work it out.
But here is something. Maybe it still works for you.

```

coding: utf-8

import ui

def button_action(sender):
sender.superview.hidden = True
sender.v2.present('sheet', animated = False)

f = (0,0,500,500)
v1 = ui.View(frame = f, bg_color = 'white')
btn = ui.Button(frame = (10,10,150,32), title = 'hit me')
btn.border_width = .5
btn.corner_radius = 3
btn.action = button_action
v1.add_subview(btn)

v2 = ui.View(frame = f)
v2.bg_color = 'pink'

btn.v2 = v2 # not a attr of ui.Button, is being dynamically created
v1.present('sheet')```

Webmaster4o

Add the second as a subview to the first, and it'll be on top of everything.

Phuket2

@Webmaster4o , but to remove the first view presented

Webmaster4o

Have one view. Present it. Add pyui file A as a subview. Then remove pyui file A, and add B.

Phuket2

@Webmaster4o , ok. But have you tried it? I tried with ui.Views. Not easy to get rid of that pesky first view

Webmaster4o

@Phuket2 a minimal example:

import ui

container = ui.View()
a=ui.load_view('intro.pyui')
b=ui.load_view('mail.pyui')

def switch_to_mail():
    container.remove_subview(a)
    container.add_subview(b)

container.add_subview(a)
container.present(hide_title_bar=1)
ui.delay(switch_to_mail,1)
NRWTV2

@Webmaster4o
Thanks, i will try it later!

Phuket2

@Webmaster4o , oh ok. See what you mean now

jbap

Try this:

def openMail(sender):
    global View
    View.close()
    View.wait_modal() #VERY IMPORTANT, waits for view to close completely
    View = ui.loadview('mail.pyui')
    View.present('sheet')



View = ui.loadview('intro.pyui')
mail_button = ui.ButtonItem(action=openMail, title = 'Open Mail')
View.right_button_items =[mail_button]
View.present('sheet')
Webmaster4o

@jbap It's better to switch them inside a container. That means that there is always a window, it is never dismissed. With your solution, the user waits for the UI to close and reopen.