0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

feat(widgets/figure.py): dark/light theme changer

This commit is contained in:
wyzula-jan
2024-02-21 21:29:30 +01:00
parent 1db77b969b
commit 08534a4739
2 changed files with 23 additions and 3 deletions

View File

@ -108,11 +108,12 @@ class BECWaveform1D(RPCBase):
def add_curve_scan(
self,
x_name: "str",
x_entry: "str",
y_name: "str",
y_entry: "str",
x_entry: "Optional[str]" = None,
y_entry: "Optional[str]" = None,
color: "Optional[str]" = None,
label: "Optional[str]" = None,
validate_bec: "bool" = True,
**kwargs
) -> "BECCurve":
"""
@ -255,6 +256,14 @@ class BECFigure(RPCBase, BECFigureClientMixin):
max_rows (Optional[int]): The new maximum number of rows in the figure.
"""
@rpc_call
def change_theme(self, theme: "Literal['dark', 'light']") -> "None":
"""
Change the theme of the figure widget.
Args:
theme(Literal["dark","light"]): The theme to set for the figure widget.
"""
class BECCurve(RPCBase):
@rpc_call

View File

@ -8,6 +8,7 @@ from typing import Literal, Optional
import numpy as np
import pyqtgraph as pg
import qdarktheme
from pydantic import Field
from pyqtgraph.Qt import uic
from qtpy.QtWidgets import QApplication, QWidget
@ -80,7 +81,7 @@ class WidgetHandler:
class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
USER_ACCESS = ["add_plot", "remove", "change_layout"]
USER_ACCESS = ["add_plot", "remove", "change_layout", "change_theme"]
def __init__(
self,
@ -104,6 +105,16 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
# Container to keep track of the grid
self.grid = []
def change_theme(self, theme: Literal["dark", "light"]) -> None:
"""
Change the theme of the figure widget.
Args:
theme(Literal["dark","light"]): The theme to set for the figure widget.
"""
qdarktheme.setup_theme(theme)
self.setBackground("k" if theme == "dark" else "w")
self.config.theme = theme
def add_plot(
self, widget_id: str = None, row: int = None, col: int = None, config=None, **axis_kwargs
) -> BECWaveform1D: