Skip to content

Commit db0a1d0

Browse files
fix: Reduce import time of the library
1 parent 4d22a05 commit db0a1d0

File tree

1 file changed

+13
-7
lines changed
  • src/ansys/tools/visualization_interface/backends/pyvista

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"""Provides a wrapper to aid in plotting."""
2323
from abc import abstractmethod
2424

25-
from beartype.typing import Any, Dict, List, Optional, Union
26-
import numpy as np
25+
from beartype.typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
2726
import pyvista as pv
2827
from vtkmodules.vtkCommonCore import vtkCommand
2928
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget
@@ -32,10 +31,6 @@
3231
import ansys.tools.visualization_interface
3332
from ansys.tools.visualization_interface.backends._base import BaseBackend
3433
from ansys.tools.visualization_interface.backends.pyvista.pyvista_interface import PyVistaInterface
35-
from ansys.tools.visualization_interface.backends.pyvista.trame_local import (
36-
_HAS_TRAME,
37-
TrameVisualizer,
38-
)
3934
from ansys.tools.visualization_interface.backends.pyvista.widgets.displace_arrows import (
4035
CameraPanDirection,
4136
DisplacementArrow,
@@ -57,6 +52,9 @@
5752
from ansys.tools.visualization_interface.utils.color import Color
5853
from ansys.tools.visualization_interface.utils.logger import logger
5954

55+
if TYPE_CHECKING:
56+
import numpy as np
57+
6058

6159
class PyVistaBackendInterface(BaseBackend):
6260
"""Provides the interface for the Visualization Interface Tool plotter.
@@ -131,6 +129,8 @@ def __init__(
131129
self._origin_colors = {}
132130

133131
# Enable the use of trame if requested and available
132+
from ansys.tools.visualization_interface.backends.pyvista.trame_local import _HAS_TRAME
133+
134134
if self._use_trame and _HAS_TRAME:
135135
# avoids GUI window popping up
136136
pv.OFF_SCREEN = True
@@ -193,7 +193,7 @@ def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]):
193193
self._widgets.append(widget)
194194
widget.update()
195195

196-
def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: np.ndarray) -> None:
196+
def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: "np.ndarray") -> None:
197197
"""Select a custom object in the plotter.
198198
199199
This method highlights the edges of a body and adds a label. It also adds
@@ -462,7 +462,13 @@ def show_plotter(self, screenshot: Optional[str] = None) -> None:
462462
Path for saving a screenshot of the image that is being represented.
463463
464464
"""
465+
from ansys.tools.visualization_interface.backends.pyvista.trame_local import (
466+
_HAS_TRAME,
467+
TrameVisualizer,
468+
)
469+
465470
if self._use_trame and _HAS_TRAME:
471+
466472
visualizer = TrameVisualizer()
467473
visualizer.set_scene(self._pl)
468474
visualizer.show()

0 commit comments

Comments
 (0)