-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(discussion): provide example for #440
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import asyncio | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.widgets import trame | ||
from trame.decorators import TrameApp, controller | ||
|
||
|
||
def toggle_node(node, node_id): | ||
if node.get("id") == node_id: | ||
new_visible = (node.get("visible") + 1) % 2 | ||
return {**node, "visible": new_visible} | ||
return node | ||
|
||
|
||
@TrameApp() | ||
class App: | ||
def __init__(self, server=None): | ||
self.server = get_server(server, client_type="vue3") | ||
self.ui = self._build_ui() | ||
|
||
@property | ||
def state(self): | ||
return self.server.state | ||
|
||
def toggle_visibility(self, node_id): | ||
with self.state: | ||
self.state.pipeline = [toggle_node(n, node_id) for n in self.state.pipeline] | ||
|
||
@controller.add_task("on_server_ready") | ||
async def auto_toggle(self, **kwargs): | ||
while True: | ||
for node_id in ["1", "2"]: | ||
await asyncio.sleep(0.1) | ||
self.toggle_visibility(node_id) | ||
|
||
def _build_ui(self): | ||
with DivLayout(self.server) as layout: | ||
trame.GitTree( | ||
sources=( | ||
"pipeline", | ||
[ | ||
{"id": "1", "parent": "0", "visible": 1, "name": "Mesh"}, | ||
{"id": "2", "parent": "1", "visible": 1, "name": "Contour"}, | ||
], | ||
), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app = App() | ||
app.server.start() |