Skip to content

Commit 01acc21

Browse files
feat: Add dark mode
1 parent 1a13257 commit 01acc21

File tree

9 files changed

+66
-40
lines changed

9 files changed

+66
-40
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,25 @@ def scene(self) -> pv.Plotter:
179179
"""PyVista scene."""
180180
return self._pl.scene
181181

182-
def enable_widgets(self):
182+
def enable_widgets(self, dark_mode: bool = False) -> None:
183183
"""Enable the widgets for the plotter."""
184184
# Create Plotter widgets
185185
if self._enable_widgets:
186186
self._widgets: List[PlotterWidget] = []
187-
self._widgets.append(Ruler(self._pl._scene))
187+
self._widgets.append(Ruler(self._pl._scene, dark_mode))
188188
[
189-
self._widgets.append(DisplacementArrow(self._pl._scene, direction=dir))
189+
self._widgets.append(DisplacementArrow(self._pl._scene, dir, dark_mode))
190190
for dir in CameraPanDirection
191191
]
192192
[
193-
self._widgets.append(ViewButton(self._pl._scene, direction=dir))
193+
self._widgets.append(ViewButton(self._pl._scene, dir, dark_mode))
194194
for dir in ViewDirection
195195
]
196-
self._widgets.append(MeasureWidget(self))
197-
self._widgets.append(ScreenshotButton(self))
196+
self._widgets.append(MeasureWidget(self, dark_mode))
197+
self._widgets.append(ScreenshotButton(self, dark_mode))
198198
if not self._use_qt:
199-
self._widgets.append(MeshSliderWidget(self))
200-
self._widgets.append(HideButton(self))
199+
self._widgets.append(MeshSliderWidget(self, dark_mode))
200+
self._widgets.append(HideButton(self, dark_mode))
201201

202202
def add_widget(self, widget: Union[PlotterWidget, List[PlotterWidget]]):
203203
"""Add one or more custom widgets to the plotter.
@@ -446,7 +446,7 @@ def show(
446446
)
447447
# Enable widgets and picking capabilities
448448
if screenshot is None and not ansys.tools.visualization_interface.DOCUMENTATION_BUILD:
449-
self.enable_widgets()
449+
self.enable_widgets(dark_mode=True)
450450

451451
if self._allow_picking:
452452
self.enable_picking()

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ class Button(PlotterWidget):
4646
4747
"""
4848

49-
def __init__(self, plotter: Plotter, button_config: tuple):
49+
def __init__(self, plotter: Plotter, button_config: tuple, dark_mode: bool = False) -> None:
5050
"""Initialize the ``Button`` class."""
5151
super().__init__(plotter)
52+
self._dark_mode = dark_mode
5253
self._button: vtkButtonWidget = self.plotter.add_checkbox_button_widget(
5354
self.callback, position=button_config.value[2], size=30, border_size=3
5455
)
@@ -68,9 +69,13 @@ def callback(self, state: bool) -> None:
6869

6970
def update(self) -> None:
7071
"""Assign the image that represents the button."""
72+
if self._dark_mode:
73+
is_inv = "_inv"
74+
else:
75+
is_inv = ""
7176
button_repr = self._button.GetRepresentation()
7277
button_icon_path = Path(
73-
Path(__file__).parent / "_images", self.button_config.value[1]
78+
Path(__file__).parent / "_images", self.button_config.value[1] + is_inv + ".png"
7479
)
7580
button_icon = vtkPNGReader()
7681
button_icon.SetFileName(button_icon_path)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class DisplacementArrow(Button):
5050
5151
"""
5252

53-
def __init__(self, plotter: Plotter, direction: CameraPanDirection):
53+
def __init__(self, plotter: Plotter, direction: CameraPanDirection, dark_mode: bool = False) -> None:
5454
"""Initialize the ``DisplacementArrow`` class."""
55-
super().__init__(plotter, direction)
55+
super().__init__(plotter, direction, dark_mode)
5656
self.direction = direction
5757
self.update()
5858

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class HideButton(PlotterWidget):
4141
4242
"""
4343

44-
def __init__(self, plotter: "Plotter") -> None:
44+
def __init__(self, plotter: "Plotter", dark_mode: bool = False) -> None:
4545
"""Initialize the ``HideButton`` class."""
4646
# Call PlotterWidget ctor
4747
super().__init__(plotter._pl.scene)
48-
48+
self._dark_mode = dark_mode
4949
# Initialize variables
5050
self._actor: vtkActor = None
5151
self._plotter = plotter
@@ -70,17 +70,22 @@ def callback(self, state: bool) -> None:
7070
widget._button.GetRepresentation().SetVisibility(0)
7171
else:
7272
for widget in self.plotter._widgets:
73-
widget._button.On()
74-
widget._button.GetRepresentation().SetVisibility(1)
73+
widget._button.On()
74+
widget._button.GetRepresentation().SetVisibility(1)
7575

7676
def update(self) -> None:
7777
"""Define the hide widget button parameters."""
78+
if self._dark_mode:
79+
is_inv = "_inv"
80+
else:
81+
is_inv = ""
82+
7883
show_vr = self._button.GetRepresentation()
7984
show_vison_icon_file = Path(
80-
Path(__file__).parent / "_images"/ "visibilityon.png"
85+
Path(__file__).parent / "_images" / ("visibilityon" + is_inv + ".png")
8186
)
8287
show_visoff_icon_file = Path(
83-
Path(__file__).parent / "_images"/ "visibilityoff.png"
88+
Path(__file__).parent / "_images" / ("visibilityon" + is_inv + ".png")
8489
)
8590
show_r_on = vtkPNGReader()
8691
show_r_on.SetFileName(show_vison_icon_file)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class MeasureWidget(PlotterWidget):
4141
4242
"""
4343

44-
def __init__(self, plotter_helper: "Plotter") -> None:
44+
def __init__(self, plotter_helper: "Plotter", dark_mode: bool = False) -> None:
4545
"""Initialize the ``MeasureWidget`` class."""
4646
# Call PlotterWidget ctor
4747
super().__init__(plotter_helper._pl.scene)
48-
48+
self._dark_mode = dark_mode
4949
# Initialize variables
5050
self._actor: vtkActor = None
5151
self.plotter_helper = plotter_helper
@@ -84,9 +84,13 @@ def callback(self, state: bool) -> None:
8484

8585
def update(self) -> None:
8686
"""Define the measurement widget button parameters."""
87+
if self._dark_mode:
88+
is_inv = "_inv"
89+
else:
90+
is_inv = ""
8791
show_measure_vr = self._button.GetRepresentation()
8892
show_measure_icon_file = Path(
89-
Path(__file__).parent / "_images"/ "measurement.png"
93+
Path(__file__).parent / "_images" / ("measurement" + is_inv + ".png")
9094
)
9195
show_measure_r = vtkPNGReader()
9296
show_measure_r.SetFileName(show_measure_icon_file)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class MeshSliderWidget(PlotterWidget):
4141
4242
"""
4343

44-
def __init__(self, plotter_helper: "Plotter") -> None:
44+
def __init__(self, plotter_helper: "Plotter", dark_mode: bool = False) -> None:
4545
"""Initialize the ``MeshSliderWidget`` class."""
4646
# Call PlotterWidget ctor
4747
super().__init__(plotter_helper._pl.scene)
48-
48+
self._dark_mode = dark_mode
4949
# Initialize variables
5050
self._widget_actor: vtkActor = None
5151
self.plotter_helper = plotter_helper
@@ -101,9 +101,13 @@ def callback(self, state: bool) -> None:
101101

102102
def update(self) -> None:
103103
"""Define the mesh slider widget button parameters."""
104+
if self._dark_mode:
105+
is_inv = "_inv"
106+
else:
107+
is_inv = ""
104108
show_measure_vr = self._button.GetRepresentation()
105109
show_measure_icon_file = Path(
106-
Path(__file__).parent / "_images"/ "planecut.png"
110+
Path(__file__).parent / "_images"/ ("planecut" + is_inv + ".png")
107111
)
108112
show_measure_r = vtkPNGReader()
109113
show_measure_r.SetFileName(show_measure_icon_file)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class Ruler(PlotterWidget):
3939
4040
"""
4141

42-
def __init__(self, plotter: Plotter) -> None:
42+
def __init__(self, plotter: Plotter, dark_mode: bool = False) -> None:
4343
"""Initialize the ``Ruler`` class."""
4444
# Call PlotterWidget ctor
4545
super().__init__(plotter)
46-
46+
self._dark_mode = dark_mode
4747
# Initialize variables
4848
self._actor: vtkActor = None
4949
self._button: vtkButtonWidget = self.plotter.add_checkbox_button_widget(
@@ -84,8 +84,12 @@ def callback(self, state: bool) -> None:
8484

8585
def update(self) -> None:
8686
"""Define the configuration and representation of the ruler widget button."""
87+
if self._dark_mode:
88+
is_inv = "_inv"
89+
else:
90+
is_inv = ""
8791
show_ruler_vr = self._button.GetRepresentation()
88-
show_ruler_icon_file = Path(Path(__file__).parent / "_images" / "ruler.png")
92+
show_ruler_icon_file = Path(Path(__file__).parent / "_images" / ("ruler" + is_inv + ".png"))
8993
show_ruler_r = vtkPNGReader()
9094
show_ruler_r.SetFileName(show_ruler_icon_file)
9195
show_ruler_r.Update()

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class ScreenshotButton(PlotterWidget):
3939
4040
"""
4141

42-
def __init__(self, plotter: Plotter) -> None:
42+
def __init__(self, plotter: Plotter, dark_mode: bool = False) -> None:
4343
"""Initialize the ``ScreenshotButton`` class."""
4444
# Call PlotterWidget ctor
4545
super().__init__(plotter)
46-
46+
self._dark_mode = dark_mode
4747
# Initialize variables
4848
self._actor: vtkActor = None
4949
self._button: vtkButtonWidget = self.plotter._pl.scene.add_checkbox_button_widget(
@@ -69,8 +69,12 @@ def callback(self, state: bool) -> None:
6969

7070
def update(self) -> None:
7171
"""Define the configuration and representation of the screenshot widget button."""
72+
if self._dark_mode:
73+
is_inv = "_inv"
74+
else:
75+
is_inv = ""
7276
show_vr = self._button.GetRepresentation()
73-
show_icon_file = Path(Path(__file__).parent / "_images" / "screenshot.png")
77+
show_icon_file = Path(Path(__file__).parent / "_images" / ("screenshot" + is_inv + ".png"))
7478
show_r = vtkPNGReader()
7579
show_r.SetFileName(show_icon_file)
7680
show_r.Update()

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
class ViewDirection(Enum):
3232
"""Provides an enum with the available views."""
3333

34-
XYPLUS = 0, "+xy.png", (5, 220)
35-
XYMINUS = 1, "-xy.png", (5, 251)
36-
XZPLUS = 2, "+xz.png", (5, 282)
37-
XZMINUS = 3, "-xz.png", (5, 313)
38-
YZPLUS = 4, "+yz.png", (5, 344)
39-
YZMINUS = 5, "-yz.png", (5, 375)
40-
ISOMETRIC = 6, "isometric.png", (5, 406)
34+
XYPLUS = 0, "+xy", (5, 220)
35+
XYMINUS = 1, "-xy", (5, 251)
36+
XZPLUS = 2, "+xz", (5, 282)
37+
XZMINUS = 3, "-xz", (5, 313)
38+
YZPLUS = 4, "+yz", (5, 344)
39+
YZMINUS = 5, "-yz", (5, 375)
40+
ISOMETRIC = 6, "isometric", (5, 406)
4141

4242

4343
class ViewButton(Button):
@@ -52,9 +52,9 @@ class ViewButton(Button):
5252
5353
"""
5454

55-
def __init__(self, plotter: Plotter, direction: tuple):
55+
def __init__(self, plotter: Plotter, direction: tuple, dark_mode: bool = False) -> None:
5656
"""Initialize the ``ViewButton`` class."""
57-
super().__init__(plotter, direction)
57+
super().__init__(plotter, direction, dark_mode)
5858
self.direction = direction
5959
self.update()
6060

0 commit comments

Comments
 (0)