Skip to content

Commit 508b625

Browse files
fix: Refactor to have independent backend
1 parent 0f3ac43 commit 508b625

File tree

6 files changed

+437
-47
lines changed

6 files changed

+437
-47
lines changed

.github/workflows/ci_cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
docs-build:
7070
name: Documentation Build
7171
runs-on: ubuntu-latest
72-
# needs: [docs-style]
72+
needs: [docs-style]
7373
steps:
7474
- name: Install system dependencies
7575
run: sudo apt install -qq libglu1-mesa-dev libx11-xcb-dev '^libxcb*'
@@ -104,7 +104,7 @@ jobs:
104104

105105
testing:
106106
name: Run Unit Tests
107-
# needs: [ smoke-tests ]
107+
needs: [ smoke-tests ]
108108
runs-on: ubuntu-latest
109109
steps:
110110
- name: Install system dependencies

examples/00-basic-pyvista-examples/qt_backend.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@
3737
import pyvista as pv
3838

3939
from ansys.tools.visualization_interface import Plotter
40-
from ansys.tools.visualization_interface.backends.pyvista import PyVistaBackend
40+
from ansys.tools.visualization_interface.backends.pyvista.pyvistaqt_interface import (
41+
PyVistaQtBackend,
42+
)
4143

4244
#########################
4345
# Open a pyvistaqt window
4446
# =======================
4547
# .. code-block:: python
4648
#
4749
# cube = pv.Cube()
48-
# pv_backend = PyVistaBackend(use_qt=True)
50+
# pv_backend = PyVistaQtBackend()
4951
# pl = Plotter(backend=pv_backend)
5052
# pl.plot(cube)
5153
# pl.show()

src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class PyVistaBackendInterface(BaseBackend):
8888
Whether to plot the names of the picked objects.
8989
show_plane : Optional[bool], default: False
9090
Whether to show the plane in the plotter.
91-
use_qt : Optional[bool], default: False
92-
Whether to use the Qt backend for the plotter.
9391
"""
9492

9593
def __init__(
@@ -99,14 +97,12 @@ def __init__(
9997
allow_hovering: Optional[bool] = False,
10098
plot_picked_names: Optional[bool] = False,
10199
show_plane: Optional[bool] = False,
102-
use_qt: Optional[bool] = False,
103100
**plotter_kwargs,
104101
) -> None:
105102
"""Initialize the ``use_trame`` parameter and save the current ``pv.OFF_SCREEN`` value."""
106103
# Check if the use of trame was requested
107104
if use_trame is None:
108105
use_trame = ansys.tools.visualization_interface.USE_TRAME
109-
self._use_qt = use_qt
110106
self._use_trame = use_trame
111107
self._allow_picking = allow_picking
112108
self._allow_hovering = allow_hovering
@@ -153,7 +149,7 @@ def __init__(
153149
logger.warning(warn_msg)
154150
self._pl = PyVistaInterface(show_plane=show_plane)
155151
else:
156-
self._pl = PyVistaInterface(show_plane=show_plane, use_qt=use_qt, **plotter_kwargs)
152+
self._pl = PyVistaInterface(show_plane=show_plane, **plotter_kwargs)
157153

158154
self._enable_widgets = self._pl._enable_widgets
159155

@@ -182,8 +178,7 @@ def enable_widgets(self):
182178
]
183179
self._widgets.append(MeasureWidget(self))
184180
self._widgets.append(ScreenshotButton(self))
185-
if not self._use_qt:
186-
self._widgets.append(MeshSliderWidget(self))
181+
self._widgets.append(MeshSliderWidget(self))
187182
self._widgets.append(HideButton(self))
188183

189184
def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]):
@@ -550,10 +545,9 @@ def __init__(
550545
allow_picking: Optional[bool] = False,
551546
allow_hovering: Optional[bool] = False,
552547
plot_picked_names: Optional[bool] = True,
553-
use_qt: Optional[bool] = False
554548
) -> None:
555549
"""Initialize the generic plotter."""
556-
super().__init__(use_trame, allow_picking, allow_hovering, plot_picked_names, use_qt=use_qt)
550+
super().__init__(use_trame, allow_picking, allow_hovering, plot_picked_names)
557551

558552
def plot_iter(
559553
self,
@@ -599,8 +593,3 @@ def plot(self, plottable_object: Any, name_filter: str = None, **plotting_option
599593
self.pv_interface.plot_iter(plottable_object, name_filter, **plotting_options)
600594
else:
601595
self.pv_interface.plot(plottable_object, name_filter, **plotting_options)
602-
603-
def close(self):
604-
"""Close the plotter for PyVistaQT."""
605-
if self._use_qt:
606-
self.pv_interface.scene.close()

src/ansys/tools/visualization_interface/backends/pyvista/pyvista_interface.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222
"""Provides plotting for various PyAnsys objects."""
23-
import importlib
2423
import re
2524
from typing import Any, Dict, List, Optional, Union
2625

2726
import pyvista as pv
2827
from pyvista.plotting.plotter import Plotter as PyVistaPlotter
29-
import pyvistaqt
3028

3129
import ansys.tools.visualization_interface as viz_interface
3230
from ansys.tools.visualization_interface.types.edge_plot import EdgePlot
@@ -35,8 +33,6 @@
3533
from ansys.tools.visualization_interface.utils.color import Color
3634
from ansys.tools.visualization_interface.utils.logger import logger
3735

38-
_HAS_PYVISTAQT = importlib.util.find_spec("pyvistaqt")
39-
4036

4137
class PyVistaInterface:
4238
"""Provides the middle class between PyVista plotting operations and PyAnsys objects.
@@ -62,9 +58,6 @@ class PyVistaInterface:
6258
for visualization.
6359
show_plane : bool, default: False
6460
Whether to show the XY plane in the plotter window.
65-
use_qt : bool, default: False
66-
Whether to use the Qt backend for the plotter window.
67-
6861
"""
6962

7063
def __init__(
@@ -74,27 +67,16 @@ def __init__(
7467
num_points: int = 100,
7568
enable_widgets: bool = True,
7669
show_plane: bool = False,
77-
use_qt: bool = False,
7870
**plotter_kwargs,
7971
) -> None:
8072
"""Initialize the plotter."""
8173
# Generate custom scene if ``None`` is provided
8274
if scene is None:
8375
if viz_interface.TESTING_MODE:
84-
if use_qt and _HAS_PYVISTAQT:
85-
scene = pyvistaqt.BackgroundPlotter(off_screen=True)
86-
else:
87-
if use_qt and not _HAS_PYVISTAQT:
88-
message = "PyVistaQt dependency is not installed. Install it with " + \
89-
"`pip install ansys-tools-visualization-interface[pyvistaqt]`."
90-
logger.warning(message)
91-
scene = pv.Plotter(off_screen=True, **plotter_kwargs)
92-
elif use_qt:
93-
scene = pyvistaqt.BackgroundPlotter()
76+
scene = pv.Plotter(off_screen=True, **plotter_kwargs)
9477
else:
9578
scene = pv.Plotter(**plotter_kwargs)
9679

97-
self._use_qt = use_qt
9880
# If required, use a white background with no gradient
9981
if not color_opts:
10082
color_opts = dict(color="white")
@@ -109,9 +91,7 @@ def __init__(
10991

11092
# Show the XY plane
11193
self._show_plane = show_plane
112-
# if (not DOCUMENTATION_BUILD) or (DOCUMENTATION_BUILD and not use_qt) or (TESTING_MODE and not use_qt):
113-
if not use_qt:
114-
self.scene.add_axes(interactive=False)
94+
self.scene.add_axes(interactive=False)
11595

11696
# objects to actors mapping
11797
self._object_to_actors_map = {}
@@ -355,10 +335,7 @@ def show(
355335
if jupyter_backend:
356336
self.scene.show(jupyter_backend=jupyter_backend, **kwargs)
357337
else:
358-
if self._use_qt:
359-
self.scene.show()
360-
else:
361-
self.scene.show(**kwargs)
338+
self.scene.show(**kwargs)
362339

363340
def set_add_mesh_defaults(self, plotting_options: Optional[Dict]) -> None:
364341
"""Set the default values for the plotting options.

0 commit comments

Comments
 (0)