dynamical update of VTreeview #115
-
Hello Trame team!
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This discussion is basically the same problem but for the client side (JS). Your problem is on the server side which can be achieved by calling that function. @state.change("Value")
def update_value(Value, **kwargs):
if state.treeview_items is None:
state.treeview_items = itms
state.treeview_items.append({"id": newid(), "name": 'Calendar : app ' + str(int(Value)) , "children":[] })
state.dirty("treeview_items") # <----- Need to let the state know that "treeview_items" has changed internally |
Beta Was this translation helpful? Give feedback.
-
For me that code is working from trame.app import get_server
from trame.ui.vuetify import SinglePageWithDrawerLayout
from trame.widgets import vtk, vuetify, html
# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------
server = get_server()
state, ctrl = server.state, server.controller
# -----------------------------------------------------------------------------
# Tree View
# -----------------------------------------------------------------------------
import itertools
newid = itertools.count().__next__
itms = (
"treeview_items",
[
{
"id": newid(),
"name": "app",
"children": [
{"id": newid(), "name": "Calendar : app", "children": []},
],
}
],
)
# -----------------------------------------------------------------------------
# GUI callbacks
# -----------------------------------------------------------------------------
@state.change("Value")
def update_value(Value, **kwargs):
state.treeview_items.append(
{"id": newid(), "name": "Calendar : app " + str(int(Value)), "children": []}
)
state.dirty("treeview_items")
# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------
with SinglePageWithDrawerLayout(server) as layout:
layout.title.set_text("Tree View")
with layout.toolbar:
# toolbar components
vuetify.VSpacer()
vuetify.VDivider(vertical=True, classes="mx-2")
with layout.drawer as drawer:
# drawer components
drawer.width = 325
vuetify.VDivider(classes="mb-2")
vuetify.VSlider(
v_model=("Value", 1.0),
min=0,
max=100,
step=1,
label="Value",
classes="mt-1",
hide_details=True,
dense=True,
)
vuetify.VTreeview(
items=itms,
)
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start() |
Beta Was this translation helpful? Give feedback.
For me that code is working