-
ObjectifI explore the feasibility to migrate a gui from qt to trame. I have some plugins that define their own version of components /widgets. These components are mounted at runtime, depending on user actions. I managed to reproduce this architecture with trame. Nevertheless as soon as the custom components declare state variables that are not already defined :
Question
Front imagesno refresh with unknown namenevertheless correct template in ws responseSource# -----------------------------------------------------------------------------
# trame
# -----------------------------------------------------------------------------
from trame.app import get_server
from trame.widgets import html
CLIENT_TYPE = "vue3"
if CLIENT_TYPE =="vue2":
from trame.widgets import vuetify2 as vuetify
from trame.ui.vuetify2 import SinglePageLayout
else:
from trame.widgets import vuetify3 as vuetify
from trame.ui.vuetify3 import SinglePageLayout
server = get_server()
server.client_type = CLIENT_TYPE
state, ui = server.state, server.ui # ui is an instance of VirtualNodeManager
state.demanded_name = "init"
state.my_comp_val_init = 0 # <------------------ COMMENT 1 a known variable (name = init) makes the program work
def my_component(name):
"""Emulate a component that is discovered at runtime"""
vname = f"my_comp_val_{name}"
state[vname] = 0
html.Div(name)
vuetify.VBtn("{{"+vname+"}}",click=vname+"++")
def udpate_content(**kwargs):
with ui.customizable_slot as cc:
cc.clear()
name = state.demanded_name
my_component(name) # <------------------ COMMENT 3 as soons as name != init the front does not refresh. It corresponds to undeclared variable
vname = f"my_comp_val_{name}"
state.dirty(vname) # <------------------ COMMENT 2 a call to dirty does not help
# -----------------------------------------------------------------------------
# GUI (Layout)
# -----------------------------------------------------------------------------
# virtualnodes added to layout
with SinglePageLayout(server) as layout:
with layout.content as content:
content.clear()
vuetify.VTextField(v_model="demanded_name")
vuetify.VBtn("update content",click=udpate_content)
with html.Div():
ui.customizable_slot(layout)
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start(open_browser=False) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
So you need to explicitly flush the new state variables before the template (also part of the state) gets flushed. The solution is here and below for convenience. # -----------------------------------------------------------------------------
# trame
# -----------------------------------------------------------------------------
from trame.app import get_server
from trame.widgets import html
CLIENT_TYPE = "vue3"
if CLIENT_TYPE == "vue2":
from trame.widgets import vuetify2 as vuetify
from trame.ui.vuetify2 import SinglePageLayout
else:
from trame.widgets import vuetify3 as vuetify
from trame.ui.vuetify3 import SinglePageLayout
server = get_server()
server.client_type = CLIENT_TYPE
state, ui = server.state, server.ui # ui is an instance of VirtualNodeManager
def my_component(name):
"""Emulate a component that is discovered at runtime"""
vname = f"my_comp_val_{name}"
with state: # Force to update state before template
state.setdefault(vname, 0)
html.Div(name)
vuetify.VBtn("{{" + vname + "}}", click=f"{vname}++")
def udpate_content():
with ui.customizable_slot.clear():
my_component(state.demanded_name)
# -----------------------------------------------------------------------------
# GUI (Layout)
# -----------------------------------------------------------------------------
# virtualnodes added to layout
with SinglePageLayout(server) as layout:
with layout.content as content:
content.clear()
vuetify.VTextField(v_model=("demanded_name", "init"))
vuetify.VBtn("update content", click=udpate_content)
with html.Div():
ui.customizable_slot(layout)
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start(open_browser=False) |
Beta Was this translation helpful? Give feedback.


Just set it to None on the server. It won't remove it but it won't take much space on the server/client (just the key).