From aa33d044443477e69df92efea99cef683ecc13d4 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 2 Jul 2024 15:49:32 +0200 Subject: [PATCH] feat(motor_map_widget): combobox in toolbar changes color if changed --- bec_widgets/widgets/motor_map/motor_map_toolbar.py | 5 +++++ bec_widgets/widgets/motor_map/motor_map_widget.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bec_widgets/widgets/motor_map/motor_map_toolbar.py b/bec_widgets/widgets/motor_map/motor_map_toolbar.py index 9eacb632..346c979d 100644 --- a/bec_widgets/widgets/motor_map/motor_map_toolbar.py +++ b/bec_widgets/widgets/motor_map/motor_map_toolbar.py @@ -23,6 +23,8 @@ class DeviceSelectionAction(ToolBarAction): self.label = label self.device_combobox = DeviceComboBox(device_filter="Positioner") + self.device_combobox.currentIndexChanged.connect(lambda: self.set_combobox_style("#ffa700")) + def add_to_toolbar(self, toolbar, target): widget = QWidget() layout = QHBoxLayout(widget) @@ -33,6 +35,9 @@ class DeviceSelectionAction(ToolBarAction): layout.addWidget(self.device_combobox) toolbar.addWidget(widget) + def set_combobox_style(self, color: str): + self.device_combobox.setStyleSheet(f"QComboBox {{ background-color: {color}; }}") + class ConnectAction(ToolBarAction): def add_to_toolbar(self, toolbar, target): diff --git a/bec_widgets/widgets/motor_map/motor_map_widget.py b/bec_widgets/widgets/motor_map/motor_map_widget.py index a95f9933..73c11761 100644 --- a/bec_widgets/widgets/motor_map/motor_map_widget.py +++ b/bec_widgets/widgets/motor_map/motor_map_widget.py @@ -1,8 +1,10 @@ from __future__ import annotations +import os + from qtpy.QtWidgets import QVBoxLayout, QWidget -from bec_widgets.utils import BECConnector +from bec_widgets.utils import BECConnector, UILoader from bec_widgets.widgets.figure import BECFigure from bec_widgets.widgets.figure.plots.motor_map.motor_map import MotorMapConfig from bec_widgets.widgets.motor_map.motor_map_toolbar import ( @@ -69,9 +71,13 @@ class BECMotorMapWidget(BECConnector, QWidget): self.toolbar.widgets["connect"].action.triggered.connect(self._action_motors) def _action_motors(self): - motor_x = self.toolbar.widgets["motor_x"].device_combobox.currentText() - motor_y = self.toolbar.widgets["motor_y"].device_combobox.currentText() + toolbar_x = self.toolbar.widgets["motor_x"].device_combobox + toolbar_y = self.toolbar.widgets["motor_y"].device_combobox + motor_x = toolbar_x.currentText() + motor_y = toolbar_y.currentText() self.change_motors(motor_x, motor_y, None, None, True) + toolbar_x.setStyleSheet("QComboBox {{ background-color: " "; }}") + toolbar_y.setStyleSheet("QComboBox {{ background-color: " "; }}") ################################### # User Access Methods from MotorMap @@ -170,7 +176,7 @@ class BECMotorMapWidget(BECConnector, QWidget): if __name__ == "__main__": import sys - from PySide6.QtWidgets import QApplication + from PySide6.QtWidgets import QApplication, QDialog app = QApplication(sys.argv) widget = BECMotorMapWidget()