Access and modify pipeline's widget visibility status #440
Replies: 3 comments 2 replies
-
It seems that you just need to update the pipeline state. It is like any other state variable so I'm not sure what example you actually need. |
Beta Was this translation helpful? Give feedback.
-
Hi Jourdain Here is my definition of the pipeline and a function that should change the visibility of the mesh element and update the state, created just as example: def switch_visibility():
mesh_actor.SetVisibility(0)
for node in state.pipeline:
if node["id"] == "1":
node["visible"] = 0
state.dirty("pipeline")
ctrl.view_update()
def pipeline_widget():
trame.GitTree(
sources=(
"pipeline",
[
{"id": "1", "parent": "0", "visible": 1, "name": "Mesh"},
{"id": "2", "parent": "1", "visible": 1, "name": "Contour"},
],
),
actives_change=(actives_change, "[$event]"),
visibility_change=(visibility_change, "[$event]"),
) In order to see the updated status on the pipeline i need to refresh the page. |
Beta Was this translation helpful? Give feedback.
-
The following code is working for me 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.5)
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() |
Beta Was this translation helpful? Give feedback.
-
Good day,
I am working on a project where I need to interact programmatically with the state of pipeline widgets. Specifically, I'd like to check their current status and use this information for conditional statements, as well as to be able to modify these states.
For example, as seen in the attached image, I am looking to activate the widget's state when the 'Apply' button for creating streamlines is pressed. Essentially, I want the widget to reflect that it has been activated or is 'in use' once the 'Apply' button is engaged.
Is there an existing method or property that allows accessing and modifying the widget states within the pipeline? Any guidance or code examples would be greatly appreciated.
Thank you for your assistance.
Beta Was this translation helpful? Give feedback.
All reactions