bec-widgets 0.84.0__py3-none-any.whl → 0.85.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.85.0 (2024-07-16)
4
+
5
+ ### Feature
6
+
7
+ * feat(color_map_selector): added colormap selector with plugin ([`b98fd00`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b98fd00adef97adf57f49b60ade99972b9f5a6bc))
8
+
3
9
  ## v0.84.0 (2024-07-15)
4
10
 
5
11
  ### Feature
@@ -133,9 +139,3 @@
133
139
  * fix(motor_control): temporary remove of motor control widgets ([`99114f1`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/99114f14f62202e1fd8bf145616fa8c69937ada4))
134
140
 
135
141
  ## v0.81.0 (2024-07-06)
136
-
137
- ### Feature
138
-
139
- * feat(color_button): can get colors in RGBA or HEX ([`9594be2`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9594be260680d11c8550ff74ffb8d679e5a5b8f6))
140
-
141
- ## v0.80.1 (2024-07-06)
PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bec_widgets
3
- Version: 0.84.0
3
+ Version: 0.85.0
4
4
  Summary: BEC Widgets
5
5
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec_widgets/issues
6
6
  Project-URL: Homepage, https://gitlab.psi.ch/bec/bec_widgets
File without changes
@@ -0,0 +1,111 @@
1
+ import pyqtgraph as pg
2
+ from qtpy.QtCore import Property, Signal, Slot
3
+ from qtpy.QtGui import QColor, QFontMetrics, QImage
4
+ from qtpy.QtWidgets import QApplication, QComboBox, QStyledItemDelegate, QVBoxLayout, QWidget
5
+
6
+
7
+ class ColormapDelegate(QStyledItemDelegate):
8
+ def __init__(self, parent=None):
9
+ super(ColormapDelegate, self).__init__(parent)
10
+ self.image_width = 25
11
+ self.image_height = 10
12
+ self.gap = 10
13
+
14
+ def paint(self, painter, option, index):
15
+ text = index.data()
16
+ colormap = pg.colormap.get(text)
17
+ colors = colormap.getLookupTable(start=0.0, stop=1.0, alpha=False)
18
+
19
+ font_metrics = QFontMetrics(painter.font())
20
+ text_width = font_metrics.width(text)
21
+ text_height = font_metrics.height()
22
+
23
+ total_height = max(text_height, self.image_height)
24
+
25
+ image = QImage(self.image_width, self.image_height, QImage.Format_RGB32)
26
+ for i in range(self.image_width):
27
+ color = QColor(*colors[int(i * (len(colors) - 1) / (self.image_width - 1))])
28
+ for j in range(self.image_height):
29
+ image.setPixel(i, j, color.rgb())
30
+
31
+ painter.drawImage(
32
+ option.rect.x(), option.rect.y() + (total_height - self.image_height) // 2, image
33
+ )
34
+ painter.drawText(
35
+ option.rect.x() + self.image_width + self.gap,
36
+ option.rect.y() + (total_height - text_height) // 2 + font_metrics.ascent(),
37
+ text,
38
+ )
39
+
40
+
41
+ class ColormapSelector(QWidget):
42
+ """
43
+ Simple colormap combobox widget. By default it loads all the available colormaps in pyqtgraph.
44
+ """
45
+
46
+ colormap_changed_signal = Signal(str)
47
+
48
+ def __init__(self, parent=None, default_colormaps=None):
49
+ super().__init__(parent)
50
+ self._colormaps = []
51
+ self.initUI(default_colormaps)
52
+
53
+ def initUI(self, default_colormaps=None):
54
+ self.layout = QVBoxLayout(self)
55
+ self.combo = QComboBox()
56
+ self.combo.setItemDelegate(ColormapDelegate())
57
+ self.combo.currentTextChanged.connect(self.colormap_changed)
58
+ self.available_colormaps = pg.colormap.listMaps()
59
+ if default_colormaps is None:
60
+ default_colormaps = self.available_colormaps
61
+ self.add_color_maps(default_colormaps)
62
+ self.layout.addWidget(self.combo)
63
+
64
+ @Slot()
65
+ def colormap_changed(self):
66
+ """
67
+ Emit the colormap changed signal with the current colormap selected in the combobox.
68
+ """
69
+ self.colormap_changed_signal.emit(self.combo.currentText())
70
+
71
+ def add_color_maps(self, colormaps=None):
72
+ """
73
+ Add colormaps to the combobox.
74
+
75
+ Args:
76
+ colormaps(list): List of colormaps to add to the combobox. If None, all available colormaps are added.
77
+ """
78
+ self.combo.clear()
79
+ if colormaps is not None:
80
+ for name in colormaps:
81
+ if name in self.available_colormaps:
82
+ self.combo.addItem(name)
83
+ else:
84
+ for name in self.available_colormaps:
85
+ self.combo.addItem(name)
86
+ self._colormaps = colormaps if colormaps is not None else self.available_colormaps
87
+
88
+ @Property("QStringList")
89
+ def colormaps(self):
90
+ """
91
+ Property to get and set the colormaps in the combobox.
92
+ """
93
+ return self._colormaps
94
+
95
+ @colormaps.setter
96
+ def colormaps(self, value):
97
+ """
98
+ Set the colormaps in the combobox.
99
+ """
100
+ if self._colormaps != value:
101
+ self._colormaps = value
102
+ self.add_color_maps(value)
103
+
104
+
105
+ if __name__ == "__main__": # pragma: no cover
106
+ import sys
107
+
108
+ app = QApplication(sys.argv)
109
+ ex = ColormapSelector()
110
+ ex.show()
111
+ sys.exit(app.exec_())
@@ -0,0 +1 @@
1
+ {'files': ['color_map_selector.py']}
@@ -0,0 +1,57 @@
1
+ # Copyright (C) 2022 The Qt Company Ltd.
2
+ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
+ import os
4
+
5
+ from qtpy.QtDesigner import QDesignerCustomWidgetInterface
6
+ from qtpy.QtGui import QIcon
7
+
8
+ from bec_widgets.widgets.color_map_selector.color_map_selector import ColormapSelector
9
+
10
+ DOM_XML = """
11
+ <ui language='c++'>
12
+ <widget class='ColormapSelector' name='color_map_selector'>
13
+ </widget>
14
+ </ui>
15
+ """
16
+
17
+
18
+ class ColormapSelectorPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
19
+ def __init__(self):
20
+ super().__init__()
21
+ self._form_editor = None
22
+
23
+ def createWidget(self, parent):
24
+ t = ColormapSelector(parent)
25
+ return t
26
+
27
+ def domXml(self):
28
+ return DOM_XML
29
+
30
+ def group(self):
31
+ return "BEC Buttons"
32
+
33
+ def icon(self):
34
+ current_path = os.path.dirname(__file__)
35
+ icon_path = os.path.join(current_path, "assets", "color_map_selector_icon.png")
36
+ return QIcon(icon_path)
37
+
38
+ def includeFile(self):
39
+ return "color_map_selector"
40
+
41
+ def initialize(self, form_editor):
42
+ self._form_editor = form_editor
43
+
44
+ def isContainer(self):
45
+ return False
46
+
47
+ def isInitialized(self):
48
+ return self._form_editor is not None
49
+
50
+ def name(self):
51
+ return "ColormapSelector"
52
+
53
+ def toolTip(self):
54
+ return "A custom QComboBox widget for selecting colormaps."
55
+
56
+ def whatsThis(self):
57
+ return self.toolTip()
@@ -0,0 +1,17 @@
1
+ def main(): # pragma: no cover
2
+ from qtpy import PYSIDE6
3
+
4
+ if not PYSIDE6:
5
+ print("PYSIDE6 is not available in the environment. Cannot patch designer.")
6
+ return
7
+ from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
8
+
9
+ from bec_widgets.widgets.color_map_selector.color_map_selector_plugin import (
10
+ ColormapSelectorPlugin,
11
+ )
12
+
13
+ QPyDesignerCustomWidgetCollection.addCustomWidget(ColormapSelectorPlugin())
14
+
15
+
16
+ if __name__ == "__main__": # pragma: no cover
17
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bec_widgets
3
- Version: 0.84.0
3
+ Version: 0.85.0
4
4
  Summary: BEC Widgets
5
5
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec_widgets/issues
6
6
  Project-URL: Homepage, https://gitlab.psi.ch/bec/bec_widgets
@@ -2,11 +2,11 @@
2
2
  .gitlab-ci.yml,sha256=zvb4A6QI5lQTsdfI5nPPL-tUNfcrz__SQjxW03QZ5Ek,8204
3
3
  .pylintrc,sha256=eeY8YwSI74oFfq6IYIbCqnx3Vk8ZncKaatv96n_Y8Rs,18544
4
4
  .readthedocs.yaml,sha256=aSOc277LqXcsTI6lgvm_JY80lMlr69GbPKgivua2cS0,603
5
- CHANGELOG.md,sha256=8LHyMBpONJxRZzFKJC41_wZpRYs8xLd7LoScfoX_6yY,7418
5
+ CHANGELOG.md,sha256=qfCubB8BgPi9QiPtGGeDxjPct_eSvK1Ep9UIP9Rgh34,7430
6
6
  LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
7
- PKG-INFO,sha256=6MK38NWwgiJwKkI_rztciPHn5gYOsTyMWU4snlgNwZk,1308
7
+ PKG-INFO,sha256=WWcaoP_OMmYA22TW83DKHT9_qQS5IpZxIOV5wcyUPkM,1308
8
8
  README.md,sha256=Od69x-RS85Hph0-WwWACwal4yUd67XkEn4APEfHhHFw,2649
9
- pyproject.toml,sha256=Dl8H7EqAUt5W6-BJvC2tHM9ONu1ZKGBdCUI1CWm6SgI,2357
9
+ pyproject.toml,sha256=bCu_XxdOirPXbnbNVdYtCKmbhJCJFxnxINDiZU02bnE,2357
10
10
  .git_hooks/pre-commit,sha256=n3RofIZHJl8zfJJIUomcMyYGFi_rwq4CC19z0snz3FI,286
11
11
  .gitlab/issue_templates/bug_report_template.md,sha256=gAuyEwl7XlnebBrkiJ9AqffSNOywmr8vygUFWKTuQeI,386
12
12
  .gitlab/issue_templates/documentation_update_template.md,sha256=FHLdb3TS_D9aL4CYZCjyXSulbaW5mrN2CmwTaeLPbNw,860
@@ -78,6 +78,12 @@ bec_widgets/widgets/color_button/color_button.pyproject,sha256=LUYF4VkDOB4ttVe7Y
78
78
  bec_widgets/widgets/color_button/color_button_plugin.py,sha256=CvO3L6r8pBd-0DNuqjQ7uKF9u1mU6xFs23sS_dsj4tw,1256
79
79
  bec_widgets/widgets/color_button/register_color_button.py,sha256=ZAx3t7G2VI2S-1qcEof31Xi9O0X8deLeZNgS651L1JI,475
80
80
  bec_widgets/widgets/color_button/assets/color_button.png,sha256=dkjgGHSdxu98nM68O16fGpxBjxkkeLN8iu9M_8i5-NY,5618
81
+ bec_widgets/widgets/color_map_selector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
+ bec_widgets/widgets/color_map_selector/color_map_selector.py,sha256=V0nmY2_X76xJmLXOfjW6rG7ipJKFT8swo3bkJZDXBGE,3751
83
+ bec_widgets/widgets/color_map_selector/color_map_selector.pyproject,sha256=sGQE4s6gia1PIz9p6c2mZX12geCk8G384gjL2PE_qEc,36
84
+ bec_widgets/widgets/color_map_selector/color_map_selector_plugin.py,sha256=9V7xvq2SB_YZU7W1E6aEKx38REOTspFNc7x57Fyd9mY,1436
85
+ bec_widgets/widgets/color_map_selector/register_color_map_selector.py,sha256=crZsJcH4z1DHfsfA7iHiQFDggslNyzfuHfo-YdAoca4,514
86
+ bec_widgets/widgets/color_map_selector/assets/color_map_selector_icon.png,sha256=o8zRmMvXhGhMyBklH_Vfjn-jpDL4Nw03fLqDk_wx_JI,11975
81
87
  bec_widgets/widgets/console/console.py,sha256=IW1OerycmS-cm8CKGFig44Qye8mxsmVcKvLHAc3lXco,17845
82
88
  bec_widgets/widgets/device_box/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
89
  bec_widgets/widgets/device_box/device_box.py,sha256=ofYQJLY02pitmAJG0Y3GWBg8txNmaJDWhQVe9KFQDYA,6938
@@ -233,6 +239,7 @@ tests/unit_tests/test_bec_motor_map.py,sha256=dSYopbZS8lGD9cB26Kwmqw5zBoKCZs8t7D
233
239
  tests/unit_tests/test_bec_queue.py,sha256=u-uc-iZeGAS8P90o6Cxy5oz_60zHpirGAu04OgQPDXw,4598
234
240
  tests/unit_tests/test_bec_status_box.py,sha256=gZdjyy9DNuUP9UwleTLj2Dp5HUImiqnkHjXWiqL0Q-o,4868
235
241
  tests/unit_tests/test_client_utils.py,sha256=CBdWIVJ_UiyFzTJnX3XJm4PGw2uXhFvRCP_Y9ifckbw,2630
242
+ tests/unit_tests/test_color_map_selector.py,sha256=NVnKrz5kFUKgljm7HslIpMII-IpzPAKHIX_KeqpNUew,1518
236
243
  tests/unit_tests/test_color_validation.py,sha256=xbFbtFDia36XLgaNrX2IwvAX3IDC_Odpj5BGoJSgiIE,2389
237
244
  tests/unit_tests/test_crosshair.py,sha256=3OMAJ2ZaISYXMOtkXf1rPdy94vCr8njeLi6uHblBL9Q,5045
238
245
  tests/unit_tests/test_device_box.py,sha256=q9IVFpt1NF3TBF0Jhk-I-LRiuvvHG3FGUalw4jEYwVo,3431
@@ -264,8 +271,8 @@ tests/unit_tests/test_configs/config_device_no_entry.yaml,sha256=hdvue9KLc_kfNzG
264
271
  tests/unit_tests/test_configs/config_scan.yaml,sha256=vo484BbWOjA_e-h6bTjSV9k7QaQHrlAvx-z8wtY-P4E,1915
265
272
  tests/unit_tests/test_msgs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
266
273
  tests/unit_tests/test_msgs/available_scans_message.py,sha256=m_z97hIrjHXXMa2Ex-UvsPmTxOYXfjxyJaGkIY6StTY,46532
267
- bec_widgets-0.84.0.dist-info/METADATA,sha256=6MK38NWwgiJwKkI_rztciPHn5gYOsTyMWU4snlgNwZk,1308
268
- bec_widgets-0.84.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
269
- bec_widgets-0.84.0.dist-info/entry_points.txt,sha256=3otEkCdDB9LZJuBLzG4pFLK5Di0CVybN_12IsZrQ-58,166
270
- bec_widgets-0.84.0.dist-info/licenses/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
271
- bec_widgets-0.84.0.dist-info/RECORD,,
274
+ bec_widgets-0.85.0.dist-info/METADATA,sha256=WWcaoP_OMmYA22TW83DKHT9_qQS5IpZxIOV5wcyUPkM,1308
275
+ bec_widgets-0.85.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
276
+ bec_widgets-0.85.0.dist-info/entry_points.txt,sha256=3otEkCdDB9LZJuBLzG4pFLK5Di0CVybN_12IsZrQ-58,166
277
+ bec_widgets-0.85.0.dist-info/licenses/LICENSE,sha256=YRKe85CBRyP7UpEAWwU8_qSIyuy5-l_9C-HKg5Qm8MQ,1511
278
+ bec_widgets-0.85.0.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bec_widgets"
7
- version = "0.84.0"
7
+ version = "0.85.0"
8
8
  description = "BEC Widgets"
9
9
  requires-python = ">=3.10"
10
10
  classifiers = [
@@ -0,0 +1,43 @@
1
+ import pyqtgraph as pg
2
+ import pytest
3
+
4
+ from bec_widgets.widgets.color_map_selector.color_map_selector import ColormapSelector
5
+
6
+
7
+ @pytest.fixture
8
+ def color_map_selector(qtbot):
9
+ widget = ColormapSelector()
10
+ qtbot.addWidget(widget)
11
+ qtbot.waitExposed(widget)
12
+ yield widget
13
+ widget.close()
14
+
15
+
16
+ def test_color_map_selector_init(color_map_selector):
17
+ assert color_map_selector is not None
18
+ assert isinstance(color_map_selector, ColormapSelector)
19
+
20
+ all_maps = pg.colormap.listMaps()
21
+ loaded_maps = [
22
+ color_map_selector.combo.itemText(i) for i in range(color_map_selector.combo.count())
23
+ ]
24
+ assert len(loaded_maps) > 0
25
+ assert all_maps == loaded_maps
26
+
27
+
28
+ def test_color_map_selector_add_color_maps(color_map_selector):
29
+ color_map_selector.add_color_maps(["cividis", "viridis"])
30
+ assert color_map_selector.combo.count() == 2
31
+ assert color_map_selector.combo.itemText(0) == "cividis"
32
+ assert color_map_selector.combo.itemText(1) == "viridis"
33
+ assert color_map_selector.combo.itemText(2) != "cividis"
34
+ assert color_map_selector.combo.itemText(2) != "viridis"
35
+
36
+
37
+ def test_colormap_add_maps_by_property(color_map_selector):
38
+ color_map_selector.colormaps = ["cividis", "viridis"]
39
+ assert color_map_selector.combo.count() == 2
40
+ assert color_map_selector.combo.itemText(0) == "cividis"
41
+ assert color_map_selector.combo.itemText(1) == "viridis"
42
+ assert color_map_selector.combo.itemText(2) != "cividis"
43
+ assert color_map_selector.combo.itemText(2) != "viridis"