From 192b268c564cdf2cdc68941568055f0136bd4166 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 17 Oct 2024 18:36:22 +0200 Subject: [PATCH] refactor(colormap-selector): inheritance changed to QComboBox from QWidget --- bec_widgets/cli/client.py | 15 ++++++++++++ .../colormap_selector/colormap_selector.py | 17 ++++++------- .../curve_dialog/curve_dialog.py | 6 ++--- tests/unit_tests/test_color_map_selector.py | 24 +++++++++---------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 93d72a61..4aa23288 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -34,6 +34,7 @@ class Widgets(str, enum.Enum): PositionIndicator = "PositionIndicator" PositionerBox = "PositionerBox" PositionerControlLine = "PositionerControlLine" + PositionerGroup = "PositionerGroup" ResetButton = "ResetButton" ResumeButton = "ResumeButton" RingProgressBar = "RingProgressBar" @@ -552,6 +553,7 @@ class BECFigure(RPCBase): def image( self, monitor: "str" = None, + monitor_type: "Literal['1d', '2d']" = "2d", color_bar: "Literal['simple', 'full']" = "full", color_map: "str" = "magma", data: "np.ndarray" = None, @@ -856,6 +858,7 @@ class BECImageShow(RPCBase): def image( self, monitor: "str", + monitor_type: "Literal['1d', '2d']" = "2d", color_map: "Optional[str]" = "magma", color_bar: "Optional[Literal['simple', 'full']]" = "full", downsample: "Optional[bool]" = True, @@ -868,6 +871,7 @@ class BECImageShow(RPCBase): Args: monitor(str): The name of the monitor to display. + monitor_type(Literal["1d","2d"]): The type of monitor to display. color_bar(Literal["simple","full"]): The type of color bar to display. color_map(str): The color map to use for the image. data(np.ndarray): Custom data to display. @@ -1180,6 +1184,7 @@ class BECImageWidget(RPCBase): def image( self, monitor: "str", + monitor_type: "Optional[Literal['1d', '2d']]" = "2d", color_map: "Optional[str]" = "magma", color_bar: "Optional[Literal['simple', 'full']]" = "full", downsample: "Optional[bool]" = True, @@ -2648,6 +2653,16 @@ class PositionerControlLine(RPCBase): """ +class PositionerGroup(RPCBase): + @rpc_call + def set_positioners(self, device_names: "str"): + """ + Redraw grid with positioners from device_names string + + Device names must be separated by space + """ + + class ResetButton(RPCBase): @property @rpc_call diff --git a/bec_widgets/widgets/colormap_selector/colormap_selector.py b/bec_widgets/widgets/colormap_selector/colormap_selector.py index 52e9b2dc..876eb8b9 100644 --- a/bec_widgets/widgets/colormap_selector/colormap_selector.py +++ b/bec_widgets/widgets/colormap_selector/colormap_selector.py @@ -40,7 +40,7 @@ class ColormapDelegate(QStyledItemDelegate): ) -class ColormapSelector(QWidget): +class ColormapSelector(QComboBox): """ Simple colormap combobox widget. By default it loads all the available colormaps in pyqtgraph. """ @@ -54,22 +54,19 @@ class ColormapSelector(QWidget): self.initUI(default_colormaps) def initUI(self, default_colormaps=None): - self.layout = QVBoxLayout(self) - self.combo = QComboBox() - self.combo.setItemDelegate(ColormapDelegate()) - self.combo.currentTextChanged.connect(self.colormap_changed) + self.setItemDelegate(ColormapDelegate()) + self.currentTextChanged.connect(self.colormap_changed) self.available_colormaps = pg.colormap.listMaps() if default_colormaps is None: default_colormaps = self.available_colormaps self.add_color_maps(default_colormaps) - self.layout.addWidget(self.combo) @Slot() def colormap_changed(self): """ Emit the colormap changed signal with the current colormap selected in the combobox. """ - self.colormap_changed_signal.emit(self.combo.currentText()) + self.colormap_changed_signal.emit(self.currentText()) def add_color_maps(self, colormaps=None): """ @@ -78,14 +75,14 @@ class ColormapSelector(QWidget): Args: colormaps(list): List of colormaps to add to the combobox. If None, all available colormaps are added. """ - self.combo.clear() + self.clear() if colormaps is not None: for name in colormaps: if name in self.available_colormaps: - self.combo.addItem(name) + self.addItem(name) else: for name in self.available_colormaps: - self.combo.addItem(name) + self.addItem(name) self._colormaps = colormaps if colormaps is not None else self.available_colormaps @Property("QStringList") diff --git a/bec_widgets/widgets/waveform/waveform_popups/curve_dialog/curve_dialog.py b/bec_widgets/widgets/waveform/waveform_popups/curve_dialog/curve_dialog.py index c7f3ea80..61e97cbb 100644 --- a/bec_widgets/widgets/waveform/waveform_popups/curve_dialog/curve_dialog.py +++ b/bec_widgets/widgets/waveform/waveform_popups/curve_dialog/curve_dialog.py @@ -53,7 +53,7 @@ class CurveSettings(SettingWidget): x_entry = self.target_widget.waveform._x_axis_mode["entry"] self._enable_ui_elements(x_name, x_entry) cm = self.target_widget.config.color_palette - self.ui.color_map_selector_scan.combo.setCurrentText(cm) + self.ui.color_map_selector_scan.setCurrentText(cm) # Scan Curve Table for source in ["scan_segment", "async"]: @@ -115,10 +115,10 @@ class CurveSettings(SettingWidget): @Slot() def change_colormap(self, target: Literal["scan", "dap"]): if target == "scan": - cm = self.ui.color_map_selector_scan.combo.currentText() + cm = self.ui.color_map_selector_scan.currentText() table = self.ui.scan_table if target == "dap": - cm = self.ui.color_map_selector_dap.combo.currentText() + cm = self.ui.color_map_selector_dap.currentText() table = self.ui.dap_table rows = table.rowCount() colors = Colors.golden_angle_color(colormap=cm, num=max(10, rows + 1), format="HEX") diff --git a/tests/unit_tests/test_color_map_selector.py b/tests/unit_tests/test_color_map_selector.py index 31f6c797..39939b62 100644 --- a/tests/unit_tests/test_color_map_selector.py +++ b/tests/unit_tests/test_color_map_selector.py @@ -17,26 +17,24 @@ def test_color_map_selector_init(color_map_selector): assert isinstance(color_map_selector, ColormapSelector) all_maps = pg.colormap.listMaps() - loaded_maps = [ - color_map_selector.combo.itemText(i) for i in range(color_map_selector.combo.count()) - ] + loaded_maps = [color_map_selector.itemText(i) for i in range(color_map_selector.count())] assert len(loaded_maps) > 0 assert all_maps == loaded_maps def test_color_map_selector_add_color_maps(color_map_selector): color_map_selector.add_color_maps(["cividis", "viridis"]) - assert color_map_selector.combo.count() == 2 - assert color_map_selector.combo.itemText(0) == "cividis" - assert color_map_selector.combo.itemText(1) == "viridis" - assert color_map_selector.combo.itemText(2) != "cividis" - assert color_map_selector.combo.itemText(2) != "viridis" + assert color_map_selector.count() == 2 + assert color_map_selector.itemText(0) == "cividis" + assert color_map_selector.itemText(1) == "viridis" + assert color_map_selector.itemText(2) != "cividis" + assert color_map_selector.itemText(2) != "viridis" def test_colormap_add_maps_by_property(color_map_selector): color_map_selector.colormaps = ["cividis", "viridis"] - assert color_map_selector.combo.count() == 2 - assert color_map_selector.combo.itemText(0) == "cividis" - assert color_map_selector.combo.itemText(1) == "viridis" - assert color_map_selector.combo.itemText(2) != "cividis" - assert color_map_selector.combo.itemText(2) != "viridis" + assert color_map_selector.count() == 2 + assert color_map_selector.itemText(0) == "cividis" + assert color_map_selector.itemText(1) == "viridis" + assert color_map_selector.itemText(2) != "cividis" + assert color_map_selector.itemText(2) != "viridis"