@leos, you cant close your view before another view is presented on the screen. I don't want to say to much about that as it may have changed or I am a little wrong.
But below I put an example that hopefully helps you. I have used Custom views instead of pyui files from the designer so it's easier to explain. But it should work equally with loaded views from pyui files.
But I think what I have done is a pretty normal case. Notice after the second view is presented I have put v.wait_modal(). This makes the view act like a dialog. I have put print statements around the opening and closing so you can see that your code for that view is basically suspended until the new view is closed.
Views also have a hidden attr, you could also use that if you didn't want to see the first view.
Anyway, I hope the below helps.
import ui
def make_btn(title, action=None):
btn = ui.Button(frame=(20, 20, 80, 32),
border_width=.5,
bg_color='white',
corner_radius=6,
action=action
)
btn.title = title
return btn
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.make_view()
def make_view(self):
btn = make_btn('Close', self.close_frm)
self.add_subview(btn)
btn1 = make_btn('Open', self.show_new_form)
btn1.x = btn.width + 50
self.add_subview(btn1)
def close_frm(self, sender):
self.close()
def show_new_form(self, sender):
v = MyClass2(frame=self.frame, bg_color='purple')
v.present(style='sheet')
print('The view has been opened')
v.wait_modal() # your code will wait here, until the view closes
print('The view has been closed')
class MyClass2(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.make_view()
def make_view(self):
btn = make_btn('Close', self.close_frm)
self.add_subview(btn)
def close_frm(self, sender):
self.close()
if __name__ == '__main__':
f = (0, 0, 300, 400)
v = MyClass(frame = f, bg_color='white')
v.present(style='sheet')