1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout, VAppLayout
from trame.widgets import vuetify3
class MultiWindow:
def __init__(self, server=None, table_size=10):
self.server = get_server(server, client_type="vue3")
# Create local variable for JS side
self.state.update(dict(window_hello=None, window_world=None))
self.state.client_only("window_hello", "window_world")
# Force ui creation
self.ui = self.ui_main
self.popup_hello = self.ui_hello
self.popup_world = self.ui_world
@property
def state(self):
return self.server.state
@property
def ctrl(self):
return self.server.controller
@property
def ui_main(self):
with SinglePageLayout(self.server, full_height=True) as layout:
with layout.toolbar.clear():
vuetify3.VToolbarTitle("Multi Window example")
vuetify3.VSpacer()
vuetify3.VBtn(
"Open Hello",
disabled=("window_hello",),
click="""
window_hello = window.open(
'/?ui=hello',
target='_blank',
'popup,width=200,height=200,left=10,top=10'
)
""",
)
vuetify3.VBtn(
"Close Hello", click="window_hello.close(); window_hello = null;"
)
vuetify3.VBtn(
"Open World",
disabled=("window_world",),
click="""
window_world = window.open(
'/?ui=world',
target='_blank',
'popup,width=200,height=200,left=100,top=100'
)
""",
)
vuetify3.VBtn(
"Close World", click="window_world.close(); window_world = null;"
)
with layout.content:
with vuetify3.VContainer():
with vuetify3.VCard():
vuetify3.VCardTitle("Main Page")
@property
def ui_hello(self):
with VAppLayout(self.server, template_name="hello", full_height=True):
with vuetify3.VContainer():
with vuetify3.VCard():
vuetify3.VCardTitle("Hello Page")
@property
def ui_world(self):
with VAppLayout(self.server, template_name="world", full_height=True):
with vuetify3.VContainer():
with vuetify3.VCard():
vuetify3.VCardTitle("World Page")
def main():
app = MultiWindow()
app.server.start()
if __name__ == "__main__":
main()
|