5555
5656_HAS_TRAME = importlib .util .find_spec ("pyvista.trame" ) and importlib .util .find_spec ("trame.app" )
5757
58+ DARK_MODE_THRESHOLD = 120
59+
5860if TYPE_CHECKING :
5961 import numpy as np
6062
@@ -179,25 +181,31 @@ def scene(self) -> pv.Plotter:
179181 """PyVista scene."""
180182 return self ._pl .scene
181183
182- def enable_widgets (self ):
183- """Enable the widgets for the plotter."""
184+ def enable_widgets (self , dark_mode : bool = False ) -> None :
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 ] = []
187- self ._widgets .append (Ruler (self ._pl ._scene ))
195+ self ._widgets .append (Ruler (self ._pl ._scene , dark_mode ))
188196 [
189- self ._widgets .append (DisplacementArrow (self ._pl ._scene , direction = dir ))
197+ self ._widgets .append (DisplacementArrow (self ._pl ._scene , dir , dark_mode ))
190198 for dir in CameraPanDirection
191199 ]
192200 [
193- self ._widgets .append (ViewButton (self ._pl ._scene , direction = dir ))
201+ self ._widgets .append (ViewButton (self ._pl ._scene , dir , dark_mode ))
194202 for dir in ViewDirection
195203 ]
196- self ._widgets .append (MeasureWidget (self ))
197- self ._widgets .append (ScreenshotButton (self ))
204+ self ._widgets .append (MeasureWidget (self , dark_mode ))
205+ self ._widgets .append (ScreenshotButton (self , dark_mode ))
198206 if not self ._use_qt :
199- self ._widgets .append (MeshSliderWidget (self ))
200- self ._widgets .append (HideButton (self ))
207+ self ._widgets .append (MeshSliderWidget (self , dark_mode ))
208+ self ._widgets .append (HideButton (self , dark_mode ))
201209
202210 def add_widget (self , widget : Union [PlotterWidget , List [PlotterWidget ]]):
203211 """Add one or more custom widgets to the plotter.
@@ -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 ()
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 ()
0 commit comments