Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/358.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix: Avoid importing VTK on startup
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

import pyvista as pv
from vtkmodules.vtkCommonCore import vtkCommand
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget
from vtkmodules.vtkRenderingCore import vtkPointPicker

import ansys.tools.visualization_interface
from ansys.tools.visualization_interface.backends._base import BaseBackend
Expand Down Expand Up @@ -111,6 +108,9 @@ def __init__(
**plotter_kwargs,
) -> None:
"""Initialize the ``use_trame`` parameter and save the current ``pv.OFF_SCREEN`` value."""
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget
from vtkmodules.vtkRenderingCore import vtkPointPicker

# Check if the use of trame was requested
if use_trame is None:
use_trame = ansys.tools.visualization_interface.USE_TRAME
Expand Down Expand Up @@ -419,6 +419,9 @@ def enable_set_focus_center(self):

def enable_hover(self):
"""Enable hover capabilities in the plotter."""
from vtkmodules.vtkCommonCore import vtkCommand
from vtkmodules.vtkInteractionWidgets import vtkHoverWidget

self._hover_widget = vtkHoverWidget()
self._hover_widget.SetInteractor(self._pl.scene.iren.interactor)
self._hover_widget.SetTimerDuration(100) # Time (ms) required to trigger a hover event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from pathlib import Path

from pyvista import Plotter
from vtk import vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

Expand All @@ -49,6 +48,8 @@ class Button(PlotterWidget):

def __init__(self, plotter: Plotter, button_config: tuple, dark_mode: bool = False) -> None:
"""Initialize the ``Button`` class."""
from vtk import vtkButtonWidget

super().__init__(plotter)
self._dark_mode = dark_mode
self._button: vtkButtonWidget = self.plotter.add_checkbox_button_widget(
Expand All @@ -70,6 +71,8 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Assign the image that represents the button."""
from vtk import vtkPNGReader

if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

if TYPE_CHECKING:
Expand All @@ -45,6 +43,9 @@ class HideButton(PlotterWidget):

def __init__(self, plotter: "Plotter", dark_mode: bool = False) -> None:
"""Initialize the ``HideButton`` class."""
from vtk import vtkActor, vtkButtonWidget


# Call PlotterWidget ctor
super().__init__(plotter._pl.scene)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -77,6 +78,8 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the hide widget button parameters."""
from vtk import vtkPNGReader

if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

if TYPE_CHECKING:
Expand All @@ -45,6 +43,8 @@ class MeasureWidget(PlotterWidget):

def __init__(self, plotter_helper: "Plotter", dark_mode: bool = False) -> None:
"""Initialize the ``MeasureWidget`` class."""
from vtk import vtkActor, vtkButtonWidget

# Call PlotterWidget ctor
super().__init__(plotter_helper._pl.scene)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -89,6 +89,8 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the measurement widget button parameters."""
from vtk import vtkPNGReader

if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from typing import TYPE_CHECKING

import pyvista as pv
from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

Expand All @@ -45,6 +44,8 @@ class MeshSliderWidget(PlotterWidget):

def __init__(self, plotter_helper: "Plotter", dark_mode: bool = False) -> None:
"""Initialize the ``MeshSliderWidget`` class."""
from vtk import vtkActor, vtkButtonWidget

# Call PlotterWidget ctor
super().__init__(plotter_helper._pl.scene)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -103,6 +104,8 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the mesh slider widget button parameters."""
from vtk import vtkPNGReader

if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

if TYPE_CHECKING:
Expand All @@ -45,6 +43,7 @@ class PickRotCenterButton(PlotterWidget):

def __init__(self, plotter_helper: "Plotter", dark_mode: bool = False) -> None:
"""Initialize the ``PickRotCenterWidget`` class."""
from vtk import vtkActor, vtkButtonWidget
# Call PlotterWidget ctor
super().__init__(plotter_helper._pl.scene)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -94,6 +93,7 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the measurement widget button parameters."""
from vtk import vtkPNGReader
if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from pathlib import Path

from pyvista import Plotter
from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

Expand All @@ -43,6 +42,7 @@ class Ruler(PlotterWidget):

def __init__(self, plotter: Plotter, dark_mode: bool = False) -> None:
"""Initialize the ``Ruler`` class."""
from vtk import vtkActor, vtkButtonWidget
# Call PlotterWidget ctor
super().__init__(plotter)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -85,6 +85,7 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the configuration and representation of the ruler widget button."""
from vtk import vtkPNGReader
if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from pathlib import Path

from pyvista import Plotter
from vtk import vtkActor, vtkButtonWidget, vtkPNGReader

from ansys.tools.visualization_interface.backends.pyvista.widgets.widget import PlotterWidget

Expand All @@ -43,6 +42,7 @@ class ScreenshotButton(PlotterWidget):

def __init__(self, plotter: Plotter, dark_mode: bool = False) -> None:
"""Initialize the ``ScreenshotButton`` class."""
from vtk import vtkActor, vtkButtonWidget
# Call PlotterWidget ctor
super().__init__(plotter)
self._dark_mode = dark_mode
Expand Down Expand Up @@ -77,6 +77,7 @@ def callback(self, state: bool) -> None:

def update(self) -> None:
"""Define the configuration and representation of the screenshot widget button."""
from vtk import vtkPNGReader
if self._dark_mode:
is_inv = "_inv"
else:
Expand Down
Loading