From ae41918bec51705938f7937727ea9447f0e739c2 Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 10:05:43 +0200 Subject: [PATCH 1/6] docs(examples): convert base example using the TrameApp base class https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3076434109 --- 00_setup/app.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/00_setup/app.py b/00_setup/app.py index e670ab0..5f21638 100644 --- a/00_setup/app.py +++ b/00_setup/app.py @@ -1,22 +1,29 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout # ----------------------------------------------------------------------------- # Get a server to work with # ----------------------------------------------------------------------------- -server = get_server() +class App(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() # ----------------------------------------------------------------------------- # GUI # ----------------------------------------------------------------------------- - -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = App() + app.server.start() + if __name__ == "__main__": - server.start() + main() \ No newline at end of file From a3bdcdfcc807fa5e07a3bba6c82ed08a8bc1dd60 Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 10:35:27 +0200 Subject: [PATCH 2/6] docs(examples): update examples to use TrameApp Ref: https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3079280811 Ref: https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3079282217 Ref: https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3079283548 Ref: https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3079287309 --- 01_vtk/app_cone.py | 19 +++++++++++++------ 01_vtk/app_flow.py | 34 ++++++++++++++++++++-------------- 01_vtk/solution_cone.py | 35 +++++++++++++++++++++-------------- 01_vtk/solution_flow.py | 33 ++++++++++++++++++++------------- 01_vtk/solution_ray_cast.py | 36 +++++++++++++++++++++--------------- 5 files changed, 95 insertions(+), 62 deletions(-) diff --git a/01_vtk/app_cone.py b/01_vtk/app_cone.py index e670ab0..5c7a232 100644 --- a/01_vtk/app_cone.py +++ b/01_vtk/app_cone.py @@ -1,22 +1,29 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout # ----------------------------------------------------------------------------- # Get a server to work with # ----------------------------------------------------------------------------- -server = get_server() +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() # ----------------------------------------------------------------------------- # GUI # ----------------------------------------------------------------------------- - -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() \ No newline at end of file diff --git a/01_vtk/app_flow.py b/01_vtk/app_flow.py index 87f92ad..f07d7db 100644 --- a/01_vtk/app_flow.py +++ b/01_vtk/app_flow.py @@ -1,6 +1,6 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,23 +44,29 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppFlow(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") - - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkLocalView(renderWindow) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app_flow = AppFlow() + app_flow.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/01_vtk/solution_cone.py b/01_vtk/solution_cone.py index 8c2ae2f..b5035e8 100644 --- a/01_vtk/solution_cone.py +++ b/01_vtk/solution_cone.py @@ -1,6 +1,6 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,24 +44,31 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - html_view = vtk.VtkLocalView(renderWindow) - ctrl.on_server_ready.add(html_view.update) + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + html_view = vtk.VtkLocalView(renderWindow) + self.ctrl.on_server_ready.add(html_view.update) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/01_vtk/solution_flow.py b/01_vtk/solution_flow.py index 8dcf2f8..fc54a51 100644 --- a/01_vtk/solution_flow.py +++ b/01_vtk/solution_flow.py @@ -1,7 +1,7 @@ import os -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkLookupTable @@ -127,23 +127,30 @@ # GUI # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppFlow(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkLocalView(renderWindow) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app_flow = AppFlow() + app_flow.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/01_vtk/solution_ray_cast.py b/01_vtk/solution_ray_cast.py index e3b1cab..19f6efd 100644 --- a/01_vtk/solution_ray_cast.py +++ b/01_vtk/solution_ray_cast.py @@ -2,9 +2,9 @@ # Web imports import os -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 # ----------------------------------------------------------------------------- # Example: SimpleRayCast @@ -97,24 +97,30 @@ # Web Application setup # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class RayCastApp(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") - - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkRemoteView(renWin) - # view = vtk.VtkLocalView(renWin) + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkRemoteView(renWin) + # view = vtk.VtkLocalView(renWin) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app_ray_cast = RayCastApp() + app_ray_cast.server.start() + if __name__ == "__main__": - server.start() + main() From 99c57ae478d7418aeb84420a071d445bded92d9d Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 10:37:48 +0200 Subject: [PATCH 3/6] docs(examples): put const global on the module rather than in the class Ref: https://github.com/Kitware/trame-tutorial/pull/7#discussion_r3176109468 --- 05_paraview/SimpleCone.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/05_paraview/SimpleCone.py b/05_paraview/SimpleCone.py index be2b086..9a2d470 100644 --- a/05_paraview/SimpleCone.py +++ b/05_paraview/SimpleCone.py @@ -6,6 +6,8 @@ from paraview import simple +DEFAULT_RESOLUTION = 6 + # ----------------------------------------------------------------------------- # trame setup # ----------------------------------------------------------------------------- @@ -14,8 +16,6 @@ class ConeApp(TrameApp): def __init__(self, server=None): super().__init__(server) - self.DEFAULT_RESOLUTION = 6 - self._init_paraview() self._build_ui() @@ -36,7 +36,7 @@ def update_cone(self, resolution, **_kwargs): def update_reset_resolution(self): - self.state.resolution = self.DEFAULT_RESOLUTION + self.state.resolution = DEFAULT_RESOLUTION # ----------------------------------------------------------------------------- @@ -53,7 +53,7 @@ def _build_ui(self): with self.ui.toolbar: v3.VSpacer() v3.VSlider( - v_model=("resolution", self.DEFAULT_RESOLUTION), + v_model=("resolution", DEFAULT_RESOLUTION), min=3, max=60, step=1, From fb4773eefa70ce931672a89b72e2f8f53ce397bb Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 10:54:39 +0200 Subject: [PATCH 4/6] docs(examples): update the example to use the TrameApp class --- 02_layouts/app_cone.py | 34 +++++++++++-------- 02_layouts/solution_FullScreenPage.py | 33 ++++++++++++------- 02_layouts/solution_SinglePage.py | 35 ++++++++++++-------- 02_layouts/solution_SinglePageWithDrawer.py | 36 +++++++++++++-------- 4 files changed, 86 insertions(+), 52 deletions(-) diff --git a/02_layouts/app_cone.py b/02_layouts/app_cone.py index 87f92ad..b5035e8 100644 --- a/02_layouts/app_cone.py +++ b/02_layouts/app_cone.py @@ -1,6 +1,6 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,23 +44,31 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + html_view = vtk.VtkLocalView(renderWindow) + self.ctrl.on_server_ready.add(html_view.update) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/02_layouts/solution_FullScreenPage.py b/02_layouts/solution_FullScreenPage.py index 355be2c..aa12ca5 100644 --- a/02_layouts/solution_FullScreenPage.py +++ b/02_layouts/solution_FullScreenPage.py @@ -1,6 +1,6 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import VAppLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,20 +44,29 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() + + def _build_ui(self): + with VAppLayout(self.server) as self.ui: + with self.ui.root: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkLocalView(renderWindow) + self.ctrl.on_server_ready.add(view.update) -with VAppLayout(server) as layout: - with layout.root: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/02_layouts/solution_SinglePage.py b/02_layouts/solution_SinglePage.py index d297a33..cd8c9f3 100644 --- a/02_layouts/solution_SinglePage.py +++ b/02_layouts/solution_SinglePage.py @@ -1,6 +1,6 @@ -from trame.app import get_server +from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout -from trame.widgets import vtk, vuetify3 +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,22 +44,31 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") + + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkLocalView(renderWindow) + self.ctrl.on_server_ready.add(view.update) - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() diff --git a/02_layouts/solution_SinglePageWithDrawer.py b/02_layouts/solution_SinglePageWithDrawer.py index d06b753..cd8c9f3 100644 --- a/02_layouts/solution_SinglePageWithDrawer.py +++ b/02_layouts/solution_SinglePageWithDrawer.py @@ -1,6 +1,6 @@ -from trame.app import get_server -from trame.ui.vuetify3 import SinglePageWithDrawerLayout -from trame.widgets import vtk, vuetify3 +from trame.app import TrameApp +from trame.ui.vuetify3 import SinglePageLayout +from trame.widgets import vtk, vuetify3 as v3 from vtkmodules.vtkFiltersSources import vtkConeSource from vtkmodules.vtkRenderingCore import ( @@ -44,23 +44,31 @@ # Trame # ----------------------------------------------------------------------------- -server = get_server() -ctrl = server.controller +class AppCone(TrameApp): + def __init__(self, server=None): + super().__init__(server) + self._build_ui() -with SinglePageWithDrawerLayout(server) as layout: - layout.title.set_text("Hello trame") + def _build_ui(self): + with SinglePageLayout(self.server) as self.ui: + self.ui.title.set_text("Hello trame") - with layout.content: - with vuetify3.VContainer( - fluid=True, - classes="pa-0 fill-height", - ): - view = vtk.VtkLocalView(renderWindow) + with self.ui.content: + with v3.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + view = vtk.VtkLocalView(renderWindow) + self.ctrl.on_server_ready.add(view.update) # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- +def main(): + app = AppCone() + app.server.start() + if __name__ == "__main__": - server.start() + main() From 3a3c29de01ea041098066b8469f2bd1bb1f438ad Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 11:10:24 +0200 Subject: [PATCH 5/6] docs(examples): make the user import trame-components --- 04_application/app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/04_application/app.py b/04_application/app.py index fc59b01..78454d5 100644 --- a/04_application/app.py +++ b/04_application/app.py @@ -3,8 +3,7 @@ from trame.app import TrameApp from trame.ui.vuetify3 import SinglePageLayout from trame.widgets import vuetify3 as v3 -from trame.widgets import vtk, trame -from trame.decorators import change +from trame.widgets import vtk from vtkmodules.vtkRenderingCore import ( vtkActor, From 12d3b6d92f270c133935ddfbad73b3c67cb04700 Mon Sep 17 00:00:00 2001 From: Ulysse DURAND Date: Tue, 5 May 2026 14:41:04 +0200 Subject: [PATCH 6/6] docs(examples): change **kwargs with **_kwargs because they are unused Ref: https://github.com/Kitware/trame-tutorial/commit/adfd845dfe0ba8689ef44327a9904ef031fd9c35#r182468245 --- 04_application/solution.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/04_application/solution.py b/04_application/solution.py index 71e79cc..f27c1c0 100644 --- a/04_application/solution.py +++ b/04_application/solution.py @@ -279,59 +279,59 @@ def visibility_change(self, event): @change("mesh_representation") - def update_mesh_representation(self, mesh_representation, **kwargs): + def update_mesh_representation(self, mesh_representation, **_kwargs): update_representation(mesh_actor, mesh_representation) self.ctrl.view_update() @change("contour_representation") - def update_contour_representation(self, contour_representation, **kwargs): + def update_contour_representation(self, contour_representation, **_kwargs): update_representation(contour_actor, contour_representation) self.ctrl.view_update() @change("mesh_color_array_idx") - def update_mesh_color_by_name(self, mesh_color_array_idx, **kwargs): + def update_mesh_color_by_name(self, mesh_color_array_idx, **_kwargs): array = dataset_arrays[mesh_color_array_idx] color_by_array(mesh_actor, array) self.ctrl.view_update() @change("contour_color_array_idx") - def update_contour_color_by_name(self, contour_color_array_idx, **kwargs): + def update_contour_color_by_name(self, contour_color_array_idx, **_kwargs): array = dataset_arrays[contour_color_array_idx] color_by_array(contour_actor, array) self.ctrl.view_update() @change("mesh_color_preset") - def update_mesh_color_preset(self, mesh_color_preset, **kwargs): + def update_mesh_color_preset(self, mesh_color_preset, **_kwargs): use_preset(mesh_actor, mesh_color_preset) self.ctrl.view_update() @change("contour_color_preset") - def update_contour_color_preset(self, contour_color_preset, **kwargs): + def update_contour_color_preset(self, contour_color_preset, **_kwargs): use_preset(contour_actor, contour_color_preset) self.ctrl.view_update() # Opacity Callbacks @change("mesh_opacity") - def update_mesh_opacity(self, mesh_opacity, **kwargs): + def update_mesh_opacity(self, mesh_opacity, **_kwargs): mesh_actor.GetProperty().SetOpacity(mesh_opacity) self.ctrl.view_update() @change("contour_opacity") - def update_contour_opacity(self, contour_opacity, **kwargs): + def update_contour_opacity(self, contour_opacity, **_kwargs): contour_actor.GetProperty().SetOpacity(contour_opacity) self.ctrl.view_update() # Contour Callbacks @change("contour_by_array_idx") - def update_contour_by(self, contour_by_array_idx, **kwargs): + def update_contour_by(self, contour_by_array_idx, **_kwargs): array = dataset_arrays[contour_by_array_idx] contour_min, contour_max = array.get("range") contour_step = 0.01 * (contour_max - contour_min) @@ -350,7 +350,7 @@ def update_contour_by(self, contour_by_array_idx, **kwargs): @change("contour_value") - def update_contour_value(self, contour_value, **kwargs): + def update_contour_value(self, contour_value, **_kwargs): contour.SetValue(0, float(contour_value)) self.ctrl.view_update()