Skip to content

Commit 5678add

Browse files
fix: Revert refactor commits
Revert "fix: Sys deps" This reverts commit aba32e4. Revert "fix: Minor details" This reverts commit 42a3459. Revert "fix: Depenency pinning, remove sys deps" This reverts commit e688320. Revert "fix: Refactor to have independent backend" This reverts commit 508b625.
1 parent 42a3459 commit 5678add

File tree

8 files changed

+56
-440
lines changed

8 files changed

+56
-440
lines changed

.github/workflows/ci_cd.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ jobs:
6969
docs-build:
7070
name: Documentation Build
7171
runs-on: ubuntu-latest
72-
needs: [docs-style]
72+
# needs: [docs-style]
7373
steps:
74+
- name: Install system dependencies
75+
run: sudo apt install -qq libglu1-mesa-dev libx11-xcb-dev '^libxcb*'
7476
- name: Setup headless display
7577
uses: pyvista/setup-headless-display-action@v2
7678

@@ -102,9 +104,11 @@ jobs:
102104

103105
testing:
104106
name: Run Unit Tests
105-
needs: [ smoke-tests ]
107+
# needs: [ smoke-tests ]
106108
runs-on: ubuntu-latest
107109
steps:
110+
- name: Install system dependencies
111+
run: sudo apt install libegl1 libxcb-cursor0 libsm6 libxext6 libxcb-xinerama0 -y
108112
- name: Restore images cache
109113
uses: actions/cache@v4
110114
with:

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

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

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

4442
#########################
4543
# Open a pyvistaqt window
4644
# =======================
4745
# .. code-block:: python
4846
#
4947
# cube = pv.Cube()
50-
# pv_backend = PyVistaQtBackend()
48+
# pv_backend = PyVistaBackend(use_qt=True)
5149
# pl = Plotter(backend=pv_backend)
5250
# pl.plot(cube)
5351
# pl.show()

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tests = [
4040
"pytest-cov==6.0.0",
4141
"pyside6==6.7.3",
4242
"pyvistaqt==0.11.1,<1",
43-
"pytest-qt==4.4.0"
43+
"pytest-qt"
4444
]
4545

4646
doc = [
@@ -49,6 +49,8 @@ doc = [
4949
"jupytext==1.16.4",
5050
"nbsphinx==0.9.5",
5151
"numpydoc==1.8.0",
52+
"pyside6==6.7.3",
53+
"pyvistaqt==0.11.1,<1",
5254
"sphinx==8.1.3",
5355
"sphinx-autoapi==3.3.3",
5456
"sphinx-copybutton==0.5.2",

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ 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.
9193
"""
9294

9395
def __init__(
@@ -97,12 +99,14 @@ def __init__(
9799
allow_hovering: Optional[bool] = False,
98100
plot_picked_names: Optional[bool] = False,
99101
show_plane: Optional[bool] = False,
102+
use_qt: Optional[bool] = False,
100103
**plotter_kwargs,
101104
) -> None:
102105
"""Initialize the ``use_trame`` parameter and save the current ``pv.OFF_SCREEN`` value."""
103106
# Check if the use of trame was requested
104107
if use_trame is None:
105108
use_trame = ansys.tools.visualization_interface.USE_TRAME
109+
self._use_qt = use_qt
106110
self._use_trame = use_trame
107111
self._allow_picking = allow_picking
108112
self._allow_hovering = allow_hovering
@@ -149,7 +153,7 @@ def __init__(
149153
logger.warning(warn_msg)
150154
self._pl = PyVistaInterface(show_plane=show_plane)
151155
else:
152-
self._pl = PyVistaInterface(show_plane=show_plane, **plotter_kwargs)
156+
self._pl = PyVistaInterface(show_plane=show_plane, use_qt=use_qt, **plotter_kwargs)
153157

154158
self._enable_widgets = self._pl._enable_widgets
155159

@@ -178,7 +182,8 @@ def enable_widgets(self):
178182
]
179183
self._widgets.append(MeasureWidget(self))
180184
self._widgets.append(ScreenshotButton(self))
181-
self._widgets.append(MeshSliderWidget(self))
185+
if not self._use_qt:
186+
self._widgets.append(MeshSliderWidget(self))
182187
self._widgets.append(HideButton(self))
183188

184189
def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]):
@@ -544,10 +549,11 @@ def __init__(
544549
use_trame: Optional[bool] = None,
545550
allow_picking: Optional[bool] = False,
546551
allow_hovering: Optional[bool] = False,
547-
plot_picked_names: Optional[bool] = True
552+
plot_picked_names: Optional[bool] = True,
553+
use_qt: Optional[bool] = False
548554
) -> None:
549555
"""Initialize the generic plotter."""
550-
super().__init__(use_trame, allow_picking, allow_hovering, plot_picked_names)
556+
super().__init__(use_trame, allow_picking, allow_hovering, plot_picked_names, use_qt=use_qt)
551557

552558
def plot_iter(
553559
self,
@@ -593,3 +599,8 @@ def plot(self, plottable_object: Any, name_filter: str = None, **plotting_option
593599
self.pv_interface.plot_iter(plottable_object, name_filter, **plotting_options)
594600
else:
595601
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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
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
2324
import re
2425
from typing import Any, Dict, List, Optional, Union
2526

2627
import pyvista as pv
2728
from pyvista.plotting.plotter import Plotter as PyVistaPlotter
29+
import pyvistaqt
2830

2931
import ansys.tools.visualization_interface as viz_interface
3032
from ansys.tools.visualization_interface.types.edge_plot import EdgePlot
@@ -33,6 +35,8 @@
3335
from ansys.tools.visualization_interface.utils.color import Color
3436
from ansys.tools.visualization_interface.utils.logger import logger
3537

38+
_HAS_PYVISTAQT = importlib.util.find_spec("pyvistaqt")
39+
3640

3741
class PyVistaInterface:
3842
"""Provides the middle class between PyVista plotting operations and PyAnsys objects.
@@ -58,6 +62,9 @@ class PyVistaInterface:
5862
for visualization.
5963
show_plane : bool, default: False
6064
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+
6168
"""
6269

6370
def __init__(
@@ -67,16 +74,27 @@ def __init__(
6774
num_points: int = 100,
6875
enable_widgets: bool = True,
6976
show_plane: bool = False,
77+
use_qt: bool = False,
7078
**plotter_kwargs,
7179
) -> None:
7280
"""Initialize the plotter."""
7381
# Generate custom scene if ``None`` is provided
7482
if scene is None:
7583
if viz_interface.TESTING_MODE:
76-
scene = pv.Plotter(off_screen=True, **plotter_kwargs)
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()
7794
else:
7895
scene = pv.Plotter(**plotter_kwargs)
7996

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

92110
# Show the XY plane
93111
self._show_plane = show_plane
94-
self.scene.add_axes(interactive=False)
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)
95115

96116
# objects to actors mapping
97117
self._object_to_actors_map = {}
@@ -335,7 +355,10 @@ def show(
335355
if jupyter_backend:
336356
self.scene.show(jupyter_backend=jupyter_backend, **kwargs)
337357
else:
338-
self.scene.show(**kwargs)
358+
if self._use_qt:
359+
self.scene.show()
360+
else:
361+
self.scene.show(**kwargs)
339362

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

0 commit comments

Comments
 (0)