Skip to content

Commit b6ec15d

Browse files
feat: Add threshold for auto selection
1 parent 01acc21 commit b6ec15d

File tree

9 files changed

+44
-10
lines changed

9 files changed

+44
-10
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
_HAS_TRAME = importlib.util.find_spec("pyvista.trame") and importlib.util.find_spec("trame.app")
5757

58+
DARK_MODE_THRESHOLD = 120
59+
5860
if TYPE_CHECKING:
5961
import numpy as np
6062

@@ -180,7 +182,13 @@ def scene(self) -> pv.Plotter:
180182
return self._pl.scene
181183

182184
def enable_widgets(self, dark_mode: bool = False) -> None:
183-
"""Enable the widgets for the plotter."""
185+
"""Enable the widgets for the plotter.
186+
187+
Parameters
188+
----------
189+
dark_mode : bool, default: False
190+
Whether to use dark mode for the widgets.
191+
"""
184192
# Create Plotter widgets
185193
if self._enable_widgets:
186194
self._widgets: List[PlotterWidget] = []
@@ -403,6 +411,7 @@ def show(
403411
screenshot: Optional[str] = None,
404412
view_2d: Dict = None,
405413
name_filter: str = None,
414+
dark_mode: bool = False,
406415
**plotting_options,
407416
) -> List[Any]:
408417
"""Plot and show any PyAnsys object.
@@ -420,6 +429,8 @@ def show(
420429
Dictionary with the plane and the viewup vectors of the 2D plane.
421430
name_filter : str, default: None
422431
Regular expression with the desired name or names to include in the plotter.
432+
dark_mode : bool, default: False
433+
Whether to use dark mode for the widgets.
423434
**plotting_options : dict, default: None
424435
Keyword arguments. For allowable keyword arguments, see the
425436
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
@@ -446,7 +457,16 @@ def show(
446457
)
447458
# Enable widgets and picking capabilities
448459
if screenshot is None and not ansys.tools.visualization_interface.DOCUMENTATION_BUILD:
449-
self.enable_widgets(dark_mode=True)
460+
if dark_mode:
461+
self.enable_widgets(dark_mode=dark_mode)
462+
elif all([
463+
color < DARK_MODE_THRESHOLD
464+
for color in self._pl.scene.background_color.int_rgb
465+
]):
466+
print([color for color in self._pl.scene.background_color.int_rgb])
467+
self.enable_widgets(dark_mode=True)
468+
else:
469+
self.enable_widgets()
450470

451471
if self._allow_picking:
452472
self.enable_picking()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Button(PlotterWidget):
4343
Plotter to draw the buttons on.
4444
button_config : tuple
4545
Tuple containing the position and the path to the icon of the button.
46+
dark_mode : bool, optional
47+
Whether to activate the dark mode or not.
4648
4749
"""
4850

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
class CameraPanDirection(Enum):
3131
"""Provides an enum with the available movement directions of the camera."""
3232

33-
XUP = 0, "upxarrow.png", (5, 170)
34-
XDOWN = 1, "downarrow.png", (5, 130)
35-
YUP = 2, "upyarrow.png", (35, 170)
36-
YDOWN = 3, "downarrow.png", (35, 130)
37-
ZUP = 4, "upzarrow.png", (65, 170)
38-
ZDOWN = 5, "downarrow.png", (65, 130)
33+
XUP = 0, "upxarrow", (5, 170)
34+
XDOWN = 1, "downarrow", (5, 130)
35+
YUP = 2, "upyarrow", (35, 170)
36+
YDOWN = 3, "downarrow", (35, 130)
37+
ZUP = 4, "upzarrow", (65, 170)
38+
ZDOWN = 5, "downarrow", (65, 130)
3939

4040

4141
class DisplacementArrow(Button):
@@ -47,7 +47,8 @@ class DisplacementArrow(Button):
4747
Plotter to draw the buttons on.
4848
direction : CameraPanDirection
4949
Direction that the camera is to move.
50-
50+
dark_mode : bool, optional
51+
Whether to activate the dark mode or not.
5152
"""
5253

5354
def __init__(self, plotter: Plotter, direction: CameraPanDirection, dark_mode: bool = False) -> None:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class HideButton(PlotterWidget):
3838
----------
3939
plotter_helper : PlotterHelper
4040
Plotter to add the hide widget to.
41+
dark_mode : bool, optional
42+
Whether to activate the dark mode or not.
4143
4244
"""
4345

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class MeasureWidget(PlotterWidget):
3838
----------
3939
plotter_helper : PlotterHelper
4040
Plotter to add the measure widget to.
41+
dark_mode : bool, optional
42+
Whether to activate the dark mode or not.
4143
4244
"""
4345

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class MeshSliderWidget(PlotterWidget):
3838
----------
3939
plotter_helper : PlotterHelper
4040
Plotter to add the mesh slider widget to.
41+
dark_mode : bool, optional
42+
Whether to activate the dark mode or not.
4143
4244
"""
4345

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Ruler(PlotterWidget):
3636
----------
3737
plotter : ~pyvista.Plotter
3838
Provides the plotter to add the ruler widget to.
39+
dark_mode : bool, optional
40+
Whether to activate the dark mode or not.
3941
4042
"""
4143

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ScreenshotButton(PlotterWidget):
3636
----------
3737
plotter : ~pyvista.Plotter
3838
Provides the plotter to add the screenshot widget to.
39+
dark_mode : bool, optional
40+
Whether to activate the dark mode or not.
3941
4042
"""
4143

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class ViewButton(Button):
4949
Plotter to draw the buttons on.
5050
direction : ViewDirection
5151
Direction of the view.
52-
52+
dark_mode : bool, optional
53+
Whether to activate the dark mode or not.
5354
"""
5455

5556
def __init__(self, plotter: Plotter, direction: tuple, dark_mode: bool = False) -> None:

0 commit comments

Comments
 (0)