UI, user interphase, python
Forum Archive
Referencing two different UIs
How do i reference 2 different UIs in the same python file so as to have 1 UI and another as a pop upInsert Code Here
def go(sender):
search=sender.superview['Title']#from timelineUI.pyui
page=browser.superview['webview1']#from browser.pyui
page.load_url('https://en.m.wikipedia.org/wiki/'+search.text)
ui.load_view('browser').present('sheet')
ui.load_view('TimelineUI').present('sheet')
@davidenrique9
def go(sender):
search=sender.superview['Title']#from timelineUI.pyui
page=browser.superview['webview1']#from browser.pyui
page.load_url('https://en.m.wikipedia.org/wiki/'+search.text)
sender.superview.add_subview(ui.load_view('browser'))
ui.load_view('TimelineUI').present('sheet')
Although I do suggest looking through some of code posted here on the forums - use a forum search.
Or - better yet Read ui.View Documentation
[edit] realized I sounded like jerk there. more info below
Here is a larger example below:
subview = None
def load_subview(superview, view_to_load):
subview = view_to_load
superview.add_subview(view_to_load)
# optional if your titlebar is showing
superview.right_button_items = [
ui.ButtonItem(title='Done', action=unload_subview)
]
def unload_subview(sender):
if subview:
subview.superview.remove_subview(subview)
# optional - remove the "Done" button
superview.right_button_items = None
def go(sender):
search=sender.superview['Title']#from timelineUI.pyui
page=browser.superview['webview1']#from browser.pyui
page.load_url('https://en.m.wikipedia.org/wiki/'+search.text)
load_view(ui.load_subview('browser'))
ui.load_view('TimelineUI').present('sheet')
I've not tested this as I mocked it up quickly.
When you wish to present alternate views you do so by using add_subview()
If the secondary view takes up the full screen, it will hide the previous view, if not - say if it is smaller or the "flex" attribute is not being set it will take up as much of the screen as it is instructed to.
i setup a title bar button item which should appear with your secondary view and disappear when closed, as well as showed the use case for remove_subview.
If you do not track the subviews, you will have a more difficult time managing it.
As said I've not tested the code and wrote it in a bit of a haste, but if you have trouble ill be happy to help.
Best of luck
@davidenrique9 , below is another example. Just depends on what you are trying to do.
import ui
class MyClassPopup(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.make_view()
def make_view(self):
btn = ui.Button(title='OK', border_width=.5, bg_color='white',
action=self.my_btn, corner_radius=6)
btn.width = 100
self.add_subview(btn)
def my_btn(self, sender):
print('Button Hit')
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.right_button_items = [ui.ButtonItem('Popup', action=self.popup)]
self.make_view()
def make_view(self):
pass
def popup(self, sender):
pop_up = MyClassPopup(frame=(0, 0, 200, 300), name='My PopOver')
pop_up.present('popover')
# if you use wait_modal, your code will not fall through to the
# print('exited'). Sometimes it matter other times i wont, depending
# on what you are doing. Try commenting out wait_modal to see the diff
pop_up.wait_modal()
print('exited')
if __name__ == '__main__':
f = (0, 0, 300, 400)
v = MyClass(frame=f)
v.present(style='sheet', animated=False)
Thank you all. Problem solved