diff --git a/bec_widgets/cli/designer_plugins.py b/bec_widgets/cli/designer_plugins.py index 18427e9d..76c6f0c9 100644 --- a/bec_widgets/cli/designer_plugins.py +++ b/bec_widgets/cli/designer_plugins.py @@ -28,10 +28,6 @@ designer_plugins = { "bec_widgets.widgets.utility.visual.color_button_native.color_button_native", "ColorButtonNative", ), - "ColormapSelector": ( - "bec_widgets.widgets.utility.visual.colormap_selector.colormap_selector", - "ColormapSelector", - ), "DapComboBox": ("bec_widgets.widgets.dap.dap_combo_box.dap_combo_box", "DapComboBox"), "DarkModeButton": ( "bec_widgets.widgets.utility.visual.dark_mode_button.dark_mode_button", @@ -132,7 +128,6 @@ widget_icons = { "BeamlineStateManager": "format_list_bulleted", "BecConsole": "terminal", "ColorButtonNative": "colors", - "ColormapSelector": "palette", "DapComboBox": "data_exploration", "DarkModeButton": "dark_mode", "DeviceBrowser": "lists", diff --git a/bec_widgets/widgets/utility/visual/colormap_selector/__init__.py b/bec_widgets/widgets/utility/visual/colormap_selector/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.py b/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.py deleted file mode 100644 index cc353c87..00000000 --- a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.py +++ /dev/null @@ -1,115 +0,0 @@ -from __future__ import annotations - -import pyqtgraph as pg -from qtpy.QtCore import Property, Signal, Slot -from qtpy.QtGui import QColor, QFontMetrics, QImage -from qtpy.QtWidgets import QApplication, QComboBox, QStyledItemDelegate, QVBoxLayout, QWidget - - -class ColormapDelegate(QStyledItemDelegate): - def __init__(self, parent=None): - super(ColormapDelegate, self).__init__(parent) - self.image_width = 25 - self.image_height = 10 - self.gap = 10 - - def paint(self, painter, option, index): - text = index.data() - colormap = pg.colormap.get(text) - colors = colormap.getLookupTable(start=0.0, stop=1.0, alpha=False) - - font_metrics = QFontMetrics(painter.font()) - text_width = font_metrics.width(text) - text_height = font_metrics.height() - - total_height = max(text_height, self.image_height) - - image = QImage(self.image_width, self.image_height, QImage.Format_RGB32) - for i in range(self.image_width): - color = QColor(*colors[int(i * (len(colors) - 1) / (self.image_width - 1))]) - for j in range(self.image_height): - image.setPixel(i, j, color.rgb()) - - painter.drawImage( - option.rect.x(), option.rect.y() + (total_height - self.image_height) // 2, image - ) - painter.drawText( - option.rect.x() + self.image_width + self.gap, - option.rect.y() + (total_height - text_height) // 2 + font_metrics.ascent(), - text, - ) - - -class ColormapSelector(QWidget): - """ - Simple colormap combobox widget. By default it loads all the available colormaps in pyqtgraph. - """ - - colormap_changed_signal = Signal(str) - ICON_NAME = "palette" - PLUGIN = True - - def __init__(self, parent=None, default_colormaps=None): - super().__init__(parent=parent) - self._colormaps = [] - 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.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()) - - def add_color_maps(self, colormaps=None): - """ - Add colormaps to the combobox. - - Args: - colormaps(list): List of colormaps to add to the combobox. If None, all available colormaps are added. - """ - self.combo.clear() - if colormaps is not None: - for name in colormaps: - if name in self.available_colormaps: - self.combo.addItem(name) - else: - for name in self.available_colormaps: - self.combo.addItem(name) - self._colormaps = colormaps if colormaps is not None else self.available_colormaps - - @Property("QStringList") - def colormaps(self): - """ - Property to get and set the colormaps in the combobox. - """ - return self._colormaps - - @colormaps.setter - def colormaps(self, value): - """ - Set the colormaps in the combobox. - """ - if self._colormaps != value: - self._colormaps = value - self.add_color_maps(value) - - -if __name__ == "__main__": # pragma: no cover - import sys - - app = QApplication(sys.argv) - ex = ColormapSelector() - ex.show() - sys.exit(app.exec_()) diff --git a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.pyproject b/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.pyproject deleted file mode 100644 index b1816091..00000000 --- a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector.pyproject +++ /dev/null @@ -1 +0,0 @@ -{'files': ['colormap_selector.py']} \ No newline at end of file diff --git a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector_plugin.py b/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector_plugin.py deleted file mode 100644 index c031ced7..00000000 --- a/bec_widgets/widgets/utility/visual/colormap_selector/colormap_selector_plugin.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -from qtpy.QtDesigner import QDesignerCustomWidgetInterface -from qtpy.QtWidgets import QWidget - -from bec_widgets.utils.bec_designer import designer_material_icon -from bec_widgets.widgets.utility.visual.colormap_selector.colormap_selector import ColormapSelector - -DOM_XML = """ - - - - -""" - - -class ColormapSelectorPlugin(QDesignerCustomWidgetInterface): # pragma: no cover - def __init__(self): - super().__init__() - self._form_editor = None - - def createWidget(self, parent): - if parent is None: - return QWidget() - t = ColormapSelector(parent) - return t - - def domXml(self): - return DOM_XML - - def group(self): - return "BEC Visual Utils" - - def icon(self): - return designer_material_icon(ColormapSelector.ICON_NAME) - - def includeFile(self): - return "colormap_selector" - - def initialize(self, form_editor): - self._form_editor = form_editor - - def isContainer(self): - return False - - def isInitialized(self): - return self._form_editor is not None - - def name(self): - return "ColormapSelector" - - def toolTip(self): - return "" - - def whatsThis(self): - return self.toolTip() diff --git a/bec_widgets/widgets/utility/visual/colormap_selector/register_colormap_selector.py b/bec_widgets/widgets/utility/visual/colormap_selector/register_colormap_selector.py deleted file mode 100644 index ae9f245c..00000000 --- a/bec_widgets/widgets/utility/visual/colormap_selector/register_colormap_selector.py +++ /dev/null @@ -1,17 +0,0 @@ -def main(): # pragma: no cover - from qtpy import PYSIDE6 - - if not PYSIDE6: - print("PYSIDE6 is not available in the environment. Cannot patch designer.") - return - from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection - - from bec_widgets.widgets.utility.visual.colormap_selector.colormap_selector_plugin import ( - ColormapSelectorPlugin, - ) - - QPyDesignerCustomWidgetCollection.addCustomWidget(ColormapSelectorPlugin()) - - -if __name__ == "__main__": # pragma: no cover - main() diff --git a/tests/unit_tests/test_color_map_selector.py b/tests/unit_tests/test_color_map_selector.py deleted file mode 100644 index 504fa7fe..00000000 --- a/tests/unit_tests/test_color_map_selector.py +++ /dev/null @@ -1,42 +0,0 @@ -import pyqtgraph as pg -import pytest - -from bec_widgets.widgets.utility.visual.colormap_selector.colormap_selector import ColormapSelector - - -@pytest.fixture -def color_map_selector(qtbot): - widget = ColormapSelector() - qtbot.addWidget(widget) - qtbot.waitExposed(widget) - yield widget - - -def test_color_map_selector_init(color_map_selector): - assert color_map_selector is not None - 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()) - ] - 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" - - -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"