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

fix(dock_area): transitioned to MaterialIconAction

This commit is contained in:
2024-08-23 22:05:56 +02:00
parent 3f3b207295
commit 88a2f66758
3 changed files with 71 additions and 28 deletions

View File

@ -79,15 +79,29 @@ class MaterialIconAction:
icon_path (str, optional): The name of the icon file from `assets/toolbar_icons`. Defaults to None.
tooltip (bool, optional): The tooltip for the action. Defaults to None.
checkable (bool, optional): Whether the action is checkable. Defaults to False.
filled (bool, optional): Whether the icon is filled. Defaults to False.
"""
def __init__(self, icon_name: str = None, tooltip: str = None, checkable: bool = False):
def __init__(
self,
icon_name: str = None,
tooltip: str = None,
checkable: bool = False,
filled: bool = False,
):
self.icon_name = icon_name
self.tooltip = tooltip
self.checkable = checkable
self.action = None
self.filled = filled
def add_to_toolbar(self, toolbar: QToolBar, target: QWidget):
icon = self.get_icon()
self.action = QAction(icon, self.tooltip, target)
self.action.setCheckable(self.checkable)
toolbar.addAction(self.action)
def get_icon(self):
color = {
"dark": "#FFFFFF",
"light": "#000000",
@ -96,10 +110,10 @@ class MaterialIconAction:
# palette = QGuiApplication.palette()
# palette.toolTipBase().color()
icon = material_icon(self.icon_name, size=(20, 20), color=color, convert_to_pixmap=False)
self.action = QAction(icon, self.tooltip, target)
self.action.setCheckable(self.checkable)
toolbar.addAction(self.action)
icon = material_icon(
self.icon_name, size=(20, 20), color=color, convert_to_pixmap=False, filled=self.filled
)
return icon
class DeviceSelectionAction(ToolBarAction):
@ -165,10 +179,12 @@ class ExpandableMenuAction(ToolBarAction):
menu = QMenu(button)
for action_id, action in self.actions.items():
sub_action = QAction(action.tooltip, target)
if action.icon_path:
if hasattr(action, "icon_path"):
icon = QIcon()
icon.addFile(action.icon_path, size=QSize(20, 20))
sub_action.setIcon(icon)
elif hasattr(action, "get_icon"):
sub_action.setIcon(action.get_icon())
sub_action.setCheckable(action.checkable)
menu.addAction(sub_action)
self.widgets[action_id] = sub_action

View File

@ -9,17 +9,16 @@ from qtpy.QtCore import Qt
from qtpy.QtGui import QPainter, QPaintEvent
from qtpy.QtWidgets import QVBoxLayout, QWidget
from bec_widgets.qt_utils.error_popups import SafeSlot
from bec_widgets.qt_utils.toolbar import (
ExpandableMenuAction,
IconAction,
MaterialIconAction,
ModularToolBar,
SeparatorAction,
)
from bec_widgets.utils import ConnectionConfig, WidgetContainerUtils
from bec_widgets.utils.bec_widget import BECWidget
from ...qt_utils.error_popups import SafeSlot
from .dock import BECDock, DockConfig
from bec_widgets.widgets.dock.dock import BECDock, DockConfig
class DockAreaConfig(ConnectionConfig):
@ -71,20 +70,26 @@ class BECDockArea(BECWidget, QWidget):
"menu_plots": ExpandableMenuAction(
label="Add Plot ",
actions={
"waveform": IconAction(icon_path="waveform.svg", tooltip="Add Waveform"),
"image": IconAction(icon_path="image.svg", tooltip="Add Image"),
"motor_map": IconAction(icon_path="motor_map.svg", tooltip="Add Motor Map"),
"waveform": MaterialIconAction(
icon_name="show_chart", tooltip="Add Waveform", filled=True
),
"image": MaterialIconAction(
icon_name="image", tooltip="Add Image", filled=True
),
"motor_map": MaterialIconAction(
icon_name="my_location", tooltip="Add Motor Map", filled=True
),
},
),
"separator_0": SeparatorAction(),
"menu_devices": ExpandableMenuAction(
label="Add Device Control ",
actions={
"scan_control": IconAction(
icon_path="scan_control.svg", tooltip="Add Scan Control"
"scan_control": MaterialIconAction(
icon_name="stacked_line_chart", tooltip="Add Scan Control", filled=True
),
"positioner_box": IconAction(
icon_path="positioner_box.svg", tooltip="Add Device Box"
"positioner_box": MaterialIconAction(
icon_name="switch_right", tooltip="Add Device Box", filled=True
),
},
),
@ -92,21 +97,29 @@ class BECDockArea(BECWidget, QWidget):
"menu_utils": ExpandableMenuAction(
label="Add Utils ",
actions={
"queue": IconAction(icon_path="queue.svg", tooltip="Add Scan Queue"),
"vs_code": IconAction(icon_path="terminal.svg", tooltip="Add VS Code"),
"status": IconAction(icon_path="status.svg", tooltip="Add BEC Status Box"),
"progress_bar": IconAction(
icon_path="ring_progress.svg", tooltip="Add Circular ProgressBar"
"queue": MaterialIconAction(
icon_name="edit_note", tooltip="Add Scan Queue", filled=True
),
"vs_code": MaterialIconAction(
icon_name="show_chart", tooltip="Add VS Code", filled=True
),
"status": MaterialIconAction(
icon_name="dns", tooltip="Add BEC Status Box", filled=True
),
"progress_bar": MaterialIconAction(
icon_name="track_changes",
tooltip="Add Circular ProgressBar",
filled=True,
),
},
),
"separator_2": SeparatorAction(),
"attach_all": IconAction(
icon_path="attach_all.svg", tooltip="Attach all floating docks"
"attach_all": MaterialIconAction(
icon_name="zoom_in_map", tooltip="Attach all floating docks"
),
"save_state": IconAction(icon_path="save_state.svg", tooltip="Save Dock State"),
"restore_state": IconAction(
icon_path="restore_state.svg", tooltip="Restore Dock State"
"save_state": MaterialIconAction(icon_name="bookmark", tooltip="Save Dock State"),
"restore_state": MaterialIconAction(
icon_name="frame_reload", tooltip="Restore Dock State"
),
},
target_widget=self,
@ -368,3 +381,15 @@ class BECDockArea(BECWidget, QWidget):
"""
self.cleanup()
super().close()
if __name__ == "__main__":
from qtpy.QtWidgets import QApplication
from bec_widgets.utils.colors import set_theme
app = QApplication([])
set_theme("light")
dock_area = BECDockArea()
dock_area.show()
app.exec_()

View File

@ -260,10 +260,12 @@ class ScanControl(BECWidget, QWidget):
# Application example
if __name__ == "__main__": # pragma: no cover
from bec_widgets.utils.colors import set_theme
app = QApplication([])
scan_control = ScanControl()
apply_theme("dark")
set_theme("auto")
window = scan_control
window.show()
app.exec()