From 81a1a5c3d3a89add2798fc540a48fea3cdb6dca5 Mon Sep 17 00:00:00 2001 From: afernand Date: Thu, 19 Jun 2025 10:35:52 +0200 Subject: [PATCH 1/5] feat: Improve optional arguments in `show` --- .../backends/pyvista/pyvista.py | 21 +++++++++++++++---- tests/test_generic_plotter.py | 12 +++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py index d70af00f..a53caa03 100644 --- a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py +++ b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py @@ -412,7 +412,8 @@ def show( view_2d: Dict = None, name_filter: str = None, dark_mode: bool = False, - **plotting_options, + plotting_options: Optional[Dict[str, Any]] = None, + **show_options: Any, ) -> List[Any]: """Plot and show any PyAnsys object. @@ -431,9 +432,11 @@ def show( Regular expression with the desired name or names to include in the plotter. dark_mode : bool, default: False Whether to use dark mode for the widgets. - **plotting_options : dict, default: None + plotting_options : dict, default: None Keyword arguments. For allowable keyword arguments, see the :meth:`Plotter.add_mesh ` method. + **show_options : Any + Additional keyword arguments for the show method. Returns ------- @@ -476,7 +479,7 @@ def show( # Update all buttons/widgets [widget.update() for widget in self._widgets] - self.show_plotter(screenshot, **plotting_options) + self.show_plotter(screenshot, **show_options) picked_objects_list = [] if isinstance(plottable_object, list): @@ -513,7 +516,17 @@ def show_plotter(self, screenshot: Optional[str] = None, **kwargs) -> None: visualizer.show() else: jupyter_backend = kwargs.pop("jupyter_backend", None) - self.pv_interface.show(screenshot=screenshot, jupyter_backend=jupyter_backend) + try: + self.pv_interface.show( + screenshot=screenshot, jupyter_backend=jupyter_backend, + **kwargs + ) + except TypeError as e: + logger.warning( + "There are incompatible keyword arguments in the `show` method. " + "Please check the documentation for the correct usage." + str(e) + ) + self.pv_interface.show(screenshot=screenshot, jupyter_backend=jupyter_backend) pv.OFF_SCREEN = self._pv_off_screen_original diff --git a/tests/test_generic_plotter.py b/tests/test_generic_plotter.py index cab27d2b..f6c28862 100644 --- a/tests/test_generic_plotter.py +++ b/tests/test_generic_plotter.py @@ -178,3 +178,15 @@ def test_dark_mode(): pl = Plotter() pl.plot(sphere) pl.show(dark_mode=True) + + +def test_plotter_show_mix(): + """Test mixing plot and show methods.""" + pl = Plotter() + sphere = pv.Sphere() + sphere1 = pv.Sphere(center=(0, 0, 1)) + # Plot + pl.plot(sphere1, opacity=0.5, color="blue") + + # Mix plot and show + pl.show(sphere, plotting_options={"show_edges": True}, cpos="xy") From 125216e8a6de30c68e6960432887b7138f556a5b Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Thu, 19 Jun 2025 08:38:37 +0000 Subject: [PATCH 2/5] chore: adding changelog file 306.miscellaneous.md [dependabot-skip] --- doc/changelog.d/306.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/306.miscellaneous.md diff --git a/doc/changelog.d/306.miscellaneous.md b/doc/changelog.d/306.miscellaneous.md new file mode 100644 index 00000000..d337884a --- /dev/null +++ b/doc/changelog.d/306.miscellaneous.md @@ -0,0 +1 @@ +Feat: improve optional arguments in `show` \ No newline at end of file From d49451a2750e7a4295dacff9be53c2a7ef474247 Mon Sep 17 00:00:00 2001 From: afernand Date: Thu, 19 Jun 2025 10:40:32 +0200 Subject: [PATCH 3/5] fix: Simplify code --- .../backends/pyvista/pyvista.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py index a53caa03..9c0ad8fa 100644 --- a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py +++ b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py @@ -515,18 +515,7 @@ def show_plotter(self, screenshot: Optional[str] = None, **kwargs) -> None: visualizer.set_scene(self._pl) visualizer.show() else: - jupyter_backend = kwargs.pop("jupyter_backend", None) - try: - self.pv_interface.show( - screenshot=screenshot, jupyter_backend=jupyter_backend, - **kwargs - ) - except TypeError as e: - logger.warning( - "There are incompatible keyword arguments in the `show` method. " - "Please check the documentation for the correct usage." + str(e) - ) - self.pv_interface.show(screenshot=screenshot, jupyter_backend=jupyter_backend) + self.pv_interface.show(screenshot=screenshot, **kwargs) pv.OFF_SCREEN = self._pv_off_screen_original From 1a86e4cac1564b6fdd2f47539b7f970fd77c2103 Mon Sep 17 00:00:00 2001 From: Alex Fernandez Date: Thu, 19 Jun 2025 11:00:56 +0200 Subject: [PATCH 4/5] Update src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com> --- .../tools/visualization_interface/backends/pyvista/pyvista.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py index 9c0ad8fa..cf38598c 100644 --- a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py +++ b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py @@ -413,7 +413,7 @@ def show( name_filter: str = None, dark_mode: bool = False, plotting_options: Optional[Dict[str, Any]] = None, - **show_options: Any, + **show_options: Dict[str, Any], ) -> List[Any]: """Plot and show any PyAnsys object. From 1908e9cb83d649cdc9eae39785ad980a0f84d4c8 Mon Sep 17 00:00:00 2001 From: afernand Date: Thu, 19 Jun 2025 11:09:59 +0200 Subject: [PATCH 5/5] fix: Default --- .../tools/visualization_interface/backends/pyvista/pyvista.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py index 9c0ad8fa..652d3a1d 100644 --- a/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py +++ b/src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py @@ -412,7 +412,7 @@ def show( view_2d: Dict = None, name_filter: str = None, dark_mode: bool = False, - plotting_options: Optional[Dict[str, Any]] = None, + plotting_options: Optional[Dict[str, Any]] = {}, **show_options: Any, ) -> List[Any]: """Plot and show any PyAnsys object.