Skip to content

Commit 696eb2c

Browse files
fix: pre-commit
1 parent c520cfb commit 696eb2c

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

doc/source/user_guide/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The Visualization Interface Tool provides a base class, ``AbstractPicker``, for
117117
callbacks of the plotter. This class provides a set of methods that can be overridden so that you can adapt the
118118
picker and hover functionalities to the specific need of your PyAnsys library.
119119

120-
The first thing you must do is to create a class that inherits from the ``AbstractPicker`` class. After that, see
120+
The first thing you must do is to create a class that inherits from the ``AbstractPicker`` class. After that, see
121121
these main use cases for customizing the picker and hover callbacks:
122122

123123
* You may want to change the way that objects are picked in the plotter. To do this, you can override the

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
# SOFTWARE.
2222

2323
"""
24-
.. _ref_picker:
24+
.. _ref_custom_picker:
2525
26-
===================
27-
Activate the picker
28-
===================
26+
====================
27+
Create custom picker
28+
====================
2929
3030
This example shows how to create a custom picker. In this case we will show how the default
3131
picker is implemented through the ``AbstractPicker`` class.
@@ -51,6 +51,17 @@
5151
# =================================
5252

5353
class CustomPicker(AbstractPicker):
54+
"""Custom picker class that extends the AbstractPicker.
55+
This custom picker changes the color of picked objects to red and adds a label with the object's name.
56+
It also adds a label when hovering over an object.
57+
58+
Parameters
59+
----------
60+
plotter_backend : Plotter
61+
The plotter backend to use.
62+
plot_picked_names : bool, optional
63+
Whether to plot the names of picked objects, by default True.
64+
"""
5465
def __init__(self, plotter_backend: "Plotter", plot_picked_names: bool = True) -> None:
5566
"""Initialize the ``Picker`` class."""
5667
# Picking variables
@@ -101,7 +112,7 @@ def pick_select_object(self, custom_object: MeshObjectPlot, pt: "np.ndarray") ->
101112
)
102113
# Add the label actor to the list of added actors
103114
added_actors.append(label_actor)
104-
115+
105116
# Add the picked object to the picked dictionary if not already present, to keep track of it
106117
if custom_object.name not in self._picked_dict:
107118
self._picked_dict[custom_object.name] = custom_object
@@ -150,7 +161,7 @@ def hover_select_object(self, custom_object: MeshObjectPlot, actor: "Actor") ->
150161
show_points=False,
151162
)
152163
self._added_hover_labels.append(label_actor)
153-
164+
154165
def hover_unselect_object(self):
155166
"""Remove all hover labels from the scene."""
156167
for label in self._added_hover_labels:
@@ -159,7 +170,7 @@ def hover_unselect_object(self):
159170
@property
160171
def picked_dict(self) -> dict:
161172
"""Return the dictionary of picked objects.
162-
173+
163174
Returns
164175
-------
165176
dict

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
123
"""Module for managing picking and hovering of objects in a PyVista plotter."""
224
from typing import TYPE_CHECKING, Union
325

@@ -7,13 +29,15 @@
729

830
if TYPE_CHECKING:
931
import numpy as np
10-
from ansys.tools.visualization_interface.backends.pyvista.pyvista import Plotter
1132
from pyvista import Actor
1233

34+
from ansys.tools.visualization_interface.backends.pyvista.pyvista import Plotter
35+
1336
class AbstractPicker:
1437
"""Abstract base class for pickers."""
1538

1639
def __init__(self):
40+
"""Initialize the AbstractPicker class."""
1741
pass
1842

1943
def pick_select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: "np.ndarray") -> None:
@@ -36,6 +60,7 @@ def picked_dict(self) -> dict:
3660
"""Return the dictionary of picked objects."""
3761
pass
3862

63+
3964
class Picker(AbstractPicker):
4065
"""Class to manage picking and hovering of objects in the plotter.
4166
@@ -44,7 +69,7 @@ class Picker(AbstractPicker):
4469
currently selected and hovered objects, and provides methods to select and unselect
4570
them.
4671
47-
72+
4873
Parameters
4974
----------
5075
plotter_backend : Plotter
@@ -164,7 +189,7 @@ def hover_select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], ac
164189
show_points=False,
165190
)
166191
self._added_hover_labels.append(label_actor)
167-
192+
168193
def hover_unselect_object(self):
169194
"""Remove all hover labels from the scene."""
170195
for label in self._added_hover_labels:

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import ansys.tools.visualization_interface
3434
from ansys.tools.visualization_interface.backends._base import BaseBackend
35+
from ansys.tools.visualization_interface.backends.pyvista.picker import AbstractPicker, Picker
3536
from ansys.tools.visualization_interface.backends.pyvista.pyvista_interface import PyVistaInterface
3637
from ansys.tools.visualization_interface.backends.pyvista.widgets.dark_mode import DarkModeButton
3738
from ansys.tools.visualization_interface.backends.pyvista.widgets.displace_arrows import (
@@ -54,14 +55,13 @@
5455
from ansys.tools.visualization_interface.types.edge_plot import EdgePlot
5556
from ansys.tools.visualization_interface.utils.color import Color
5657
from ansys.tools.visualization_interface.utils.logger import logger
57-
from ansys.tools.visualization_interface.backends.pyvista.picker import Picker, AbstractPicker
5858

5959
_HAS_TRAME = importlib.util.find_spec("pyvista.trame") and importlib.util.find_spec("trame.app")
6060

6161
DARK_MODE_THRESHOLD = 120
6262

6363
if TYPE_CHECKING:
64-
import numpy as np
64+
pass
6565

6666

6767
class PyVistaBackendInterface(BaseBackend):
@@ -563,12 +563,12 @@ def __init__(
563563
) -> None:
564564
"""Initialize the generic plotter."""
565565
super().__init__(
566-
use_trame,
567-
allow_picking,
568-
allow_hovering,
569-
plot_picked_names,
570-
use_qt=use_qt,
571-
show_qt=show_qt,
566+
use_trame,
567+
allow_picking,
568+
allow_hovering,
569+
plot_picked_names,
570+
use_qt=use_qt,
571+
show_qt=show_qt,
572572
custom_picker=custom_picker
573573
)
574574

0 commit comments

Comments
 (0)