diff --git a/01_vtk/solution_cone.py b/01_vtk/solution_cone.py index b5035e8..3a445c9 100644 --- a/01_vtk/solution_cone.py +++ b/01_vtk/solution_cone.py @@ -59,8 +59,6 @@ def _build_ui(self): classes="pa-0 fill-height", ): html_view = vtk.VtkLocalView(renderWindow) - self.ctrl.on_server_ready.add(html_view.update) - # ----------------------------------------------------------------------------- # Main diff --git a/02_layouts/app_cone.py b/02_layouts/app_cone.py index b5035e8..47c4a1b 100644 --- a/02_layouts/app_cone.py +++ b/02_layouts/app_cone.py @@ -44,7 +44,7 @@ # Trame # ----------------------------------------------------------------------------- -class AppCone(TrameApp): +class ConeApp(TrameApp): def __init__(self, server=None): super().__init__(server) self._build_ui() @@ -67,7 +67,7 @@ def _build_ui(self): # ----------------------------------------------------------------------------- def main(): - app = AppCone() + app = ConeApp() app.server.start() if __name__ == "__main__": diff --git a/02_layouts/solution_FullScreenPage.py b/02_layouts/solution_FullScreenPage.py index aa12ca5..e721942 100644 --- a/02_layouts/solution_FullScreenPage.py +++ b/02_layouts/solution_FullScreenPage.py @@ -44,7 +44,7 @@ # Trame # ----------------------------------------------------------------------------- -class AppCone(TrameApp): +class FullScreenApp(TrameApp): def __init__(self, server=None): super().__init__(server) self._build_ui() @@ -65,7 +65,7 @@ def _build_ui(self): # ----------------------------------------------------------------------------- def main(): - app = AppCone() + app = FullScreenApp() app.server.start() if __name__ == "__main__": diff --git a/02_layouts/solution_SinglePage.py b/02_layouts/solution_SinglePage.py index cd8c9f3..65238c5 100644 --- a/02_layouts/solution_SinglePage.py +++ b/02_layouts/solution_SinglePage.py @@ -44,7 +44,7 @@ # Trame # ----------------------------------------------------------------------------- -class AppCone(TrameApp): +class SinglePageApp(TrameApp): def __init__(self, server=None): super().__init__(server) self._build_ui() @@ -67,7 +67,7 @@ def _build_ui(self): # ----------------------------------------------------------------------------- def main(): - app = AppCone() + app = SinglePageApp() app.server.start() if __name__ == "__main__": diff --git a/02_layouts/solution_SinglePageWithDrawer.py b/02_layouts/solution_SinglePageWithDrawer.py index cd8c9f3..1cc2dcb 100644 --- a/02_layouts/solution_SinglePageWithDrawer.py +++ b/02_layouts/solution_SinglePageWithDrawer.py @@ -44,7 +44,7 @@ # Trame # ----------------------------------------------------------------------------- -class AppCone(TrameApp): +class SinglePageWithDrawerApp(TrameApp): def __init__(self, server=None): super().__init__(server) self._build_ui() @@ -67,7 +67,7 @@ def _build_ui(self): # ----------------------------------------------------------------------------- def main(): - app = AppCone() + app = SinglePageWithDrawerApp() app.server.start() if __name__ == "__main__": diff --git a/03_html/solution_final.py b/03_html/solution_final.py index a301ccf..9cafa28 100644 --- a/03_html/solution_final.py +++ b/03_html/solution_final.py @@ -46,7 +46,7 @@ def vtk_pipeline(self): self.renderer.ResetCamera() @change("resolution") - def update_resolution(self, resolution, **_kwargs): + def update_resolution(self, resolution, **_): self.cone_source.SetResolution(resolution) self.ctrl.view_update() diff --git a/04_application/solution.py b/04_application/solution.py index f27c1c0..bfb28d4 100644 --- a/04_application/solution.py +++ b/04_application/solution.py @@ -235,6 +235,186 @@ def use_preset(actor, preset): lut.Build() +# ----------------------------------------------------------------------------- +# GUI elements +# ----------------------------------------------------------------------------- + + +def ui_card(title, ui_name): + with v3.VCard(v_show=f"active_ui == '{ui_name}'"): + v3.VCardTitle( + title, + classes="grey lighten-1 py-1 grey--text text--darken-3", + style="user-select: none; cursor: pointer", + hide_details=True, + density="compact", + ) + content = v3.VCardText(classes="py-2") + return content + + +def mesh_card(): + with ui_card(title="Mesh", ui_name="mesh"): + v3.VSelect( + # Representation + v_model=("mesh_representation", Representation.Surface), + items=( + "representations", + [ + {"text": "Points", "value": 0}, + {"text": "Wireframe", "value": 1}, + {"text": "Surface", "value": 2}, + {"text": "SurfaceWithEdges", "value": 3}, + ], + ), + item_title="text", + item_value="value", + label="Representation", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + with v3.VRow(classes="pt-2", density="compact"): + with v3.VCol(cols="6"): + v3.VSelect( + # Color By + label="Color by", + v_model=("mesh_color_array_idx", 0), + items=("array_list", dataset_arrays), + item_title="text", + item_value="value", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + with v3.VCol(cols="6"): + v3.VSelect( + # Color Map + label="Colormap", + v_model=("mesh_color_preset", LookupTable.Rainbow), + items=( + "colormaps", + [ + {"text": "Rainbow", "value": 0}, + {"text": "Inv Rainbow", "value": 1}, + {"text": "Greyscale", "value": 2}, + {"text": "Inv Greyscale", "value": 3}, + ], + ), + item_title="text", + item_value="value", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + v3.VSlider( + # Opacity + v_model=("mesh_opacity", 1.0), + min=0, + max=1, + step=0.1, + label="Opacity", + classes="mt-1", + hide_details=True, + density="compact", + ) + + +def contour_card(): + with ui_card(title="Contour", ui_name="contour"): + v3.VSelect( + # Contour By + label="Contour by", + v_model=("contour_by_array_idx", 0), + items=("array_list", dataset_arrays), + item_title="text", + item_value="value", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + v3.VSlider( + # Contour Value + v_model=("contour_value", contour_value), + min=("contour_min", default_min), + max=("contour_max", default_max), + step=("contour_step", 0.01 * (default_max - default_min)), + label="Value", + classes="my-1", + hide_details=True, + density="compact", + ) + v3.VSelect( + # Representation + v_model=("contour_representation", Representation.Surface), + items=( + "representations", + [ + {"text": "Points", "value": 0}, + {"text": "Wireframe", "value": 1}, + {"text": "Surface", "value": 2}, + {"text": "SurfaceWithEdges", "value": 3}, + ], + ), + item_title="text", + item_value="value", + label="Representation", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + with v3.VRow(classes="pt-2", density="compact"): + with v3.VCol(cols="6"): + v3.VSelect( + # Color By + label="Color by", + v_model=("contour_color_array_idx", 0), + items=("array_list", dataset_arrays), + item_title="text", + item_value="value", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + with v3.VCol(cols="6"): + v3.VSelect( + # Color Map + label="Colormap", + v_model=("contour_color_preset", LookupTable.Rainbow), + items=( + "colormaps", + [ + {"text": "Rainbow", "value": 0}, + {"text": "Inv Rainbow", "value": 1}, + {"text": "Greyscale", "value": 2}, + {"text": "Inv Greyscale", "value": 3}, + ], + ), + item_title="text", + item_value="value", + hide_details=True, + density="compact", + outlined=True, + classes="pt-1", + ) + v3.VSlider( + # Opacity + v_model=("contour_opacity", 1.0), + min=0, + max=1, + step=0.1, + label="Opacity", + classes="mt-1", + hide_details=True, + density="compact", + ) + # ----------------------------------------------------------------------------- # Trame setup # ----------------------------------------------------------------------------- @@ -279,59 +459,59 @@ def visibility_change(self, event): @change("mesh_representation") - def update_mesh_representation(self, mesh_representation, **_kwargs): + def update_mesh_representation(self, mesh_representation, **_): 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, **_): 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, **_): 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, **_): 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, **_): 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, **_): 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, **_): 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, **_): 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, **_): array = dataset_arrays[contour_by_array_idx] contour_min, contour_max = array.get("range") contour_step = 0.01 * (contour_max - contour_min) @@ -350,7 +530,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, **_): contour.SetValue(0, float(contour_value)) self.ctrl.view_update() @@ -406,182 +586,6 @@ def pipeline_widget(self): ) - def ui_card(self, title, ui_name): - with v3.VCard(v_show=f"active_ui == '{ui_name}'"): - v3.VCardTitle( - title, - classes="grey lighten-1 py-1 grey--text text--darken-3", - style="user-select: none; cursor: pointer", - hide_details=True, - density="compact", - ) - content = v3.VCardText(classes="py-2") - return content - - - def mesh_card(self): - with self.ui_card(title="Mesh", ui_name="mesh"): - v3.VSelect( - # Representation - v_model=("mesh_representation", Representation.Surface), - items=( - "representations", - [ - {"text": "Points", "value": 0}, - {"text": "Wireframe", "value": 1}, - {"text": "Surface", "value": 2}, - {"text": "SurfaceWithEdges", "value": 3}, - ], - ), - item_title="text", - item_value="value", - label="Representation", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - with v3.VRow(classes="pt-2", density="compact"): - with v3.VCol(cols="6"): - v3.VSelect( - # Color By - label="Color by", - v_model=("mesh_color_array_idx", 0), - items=("array_list", dataset_arrays), - item_title="text", - item_value="value", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - with v3.VCol(cols="6"): - v3.VSelect( - # Color Map - label="Colormap", - v_model=("mesh_color_preset", LookupTable.Rainbow), - items=( - "colormaps", - [ - {"text": "Rainbow", "value": 0}, - {"text": "Inv Rainbow", "value": 1}, - {"text": "Greyscale", "value": 2}, - {"text": "Inv Greyscale", "value": 3}, - ], - ), - item_title="text", - item_value="value", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - v3.VSlider( - # Opacity - v_model=("mesh_opacity", 1.0), - min=0, - max=1, - step=0.1, - label="Opacity", - classes="mt-1", - hide_details=True, - density="compact", - ) - - - def contour_card(self): - with self.ui_card(title="Contour", ui_name="contour"): - v3.VSelect( - # Contour By - label="Contour by", - v_model=("contour_by_array_idx", 0), - items=("array_list", dataset_arrays), - item_title="text", - item_value="value", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - v3.VSlider( - # Contour Value - v_model=("contour_value", contour_value), - min=("contour_min", default_min), - max=("contour_max", default_max), - step=("contour_step", 0.01 * (default_max - default_min)), - label="Value", - classes="my-1", - hide_details=True, - density="compact", - ) - v3.VSelect( - # Representation - v_model=("contour_representation", Representation.Surface), - items=( - "representations", - [ - {"text": "Points", "value": 0}, - {"text": "Wireframe", "value": 1}, - {"text": "Surface", "value": 2}, - {"text": "SurfaceWithEdges", "value": 3}, - ], - ), - item_title="text", - item_value="value", - label="Representation", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - with v3.VRow(classes="pt-2", density="compact"): - with v3.VCol(cols="6"): - v3.VSelect( - # Color By - label="Color by", - v_model=("contour_color_array_idx", 0), - items=("array_list", dataset_arrays), - item_title="text", - item_value="value", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - with v3.VCol(cols="6"): - v3.VSelect( - # Color Map - label="Colormap", - v_model=("contour_color_preset", LookupTable.Rainbow), - items=( - "colormaps", - [ - {"text": "Rainbow", "value": 0}, - {"text": "Inv Rainbow", "value": 1}, - {"text": "Greyscale", "value": 2}, - {"text": "Inv Greyscale", "value": 3}, - ], - ), - item_title="text", - item_value="value", - hide_details=True, - density="compact", - outlined=True, - classes="pt-1", - ) - v3.VSlider( - # Opacity - v_model=("contour_opacity", 1.0), - min=0, - max=1, - step=0.1, - label="Opacity", - classes="mt-1", - hide_details=True, - density="compact", - ) - - # ----------------------------------------------------------------------------- # GUI # ----------------------------------------------------------------------------- @@ -601,8 +605,8 @@ def _build_ui(self): drawer.width = 325 self.pipeline_widget() v3.VDivider(classes="mb-2") - self.mesh_card() - self.contour_card() + mesh_card() + contour_card() with self.ui.content: # content components diff --git a/05_paraview/SimpleCone.py b/05_paraview/SimpleCone.py index 9a2d470..ac5e4a9 100644 --- a/05_paraview/SimpleCone.py +++ b/05_paraview/SimpleCone.py @@ -30,7 +30,7 @@ def _init_paraview(self): @change("resolution") - def update_cone(self, resolution, **_kwargs): + def update_cone(self, resolution, **_): self.cone.Resolution = resolution self.ctrl.view_update() diff --git a/05_paraview/StateLoader.py b/05_paraview/StateLoader.py index ec7759f..97be183 100644 --- a/05_paraview/StateLoader.py +++ b/05_paraview/StateLoader.py @@ -29,7 +29,7 @@ def __init__(self, server=None): # ----------------------------------------------------------------------------- - def load_data(self, **_kwargs): + def load_data(self, **_): # CLI args, _ = self.server.cli.parse_known_args()