0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 11:11:49 +02:00

refactor(colormap-selector): inheritance changed to QComboBox from QWidget

This commit is contained in:
2024-10-17 18:36:22 +02:00
parent 98c68e9ff4
commit 192b268c56
4 changed files with 36 additions and 26 deletions

View File

@ -34,6 +34,7 @@ class Widgets(str, enum.Enum):
PositionIndicator = "PositionIndicator" PositionIndicator = "PositionIndicator"
PositionerBox = "PositionerBox" PositionerBox = "PositionerBox"
PositionerControlLine = "PositionerControlLine" PositionerControlLine = "PositionerControlLine"
PositionerGroup = "PositionerGroup"
ResetButton = "ResetButton" ResetButton = "ResetButton"
ResumeButton = "ResumeButton" ResumeButton = "ResumeButton"
RingProgressBar = "RingProgressBar" RingProgressBar = "RingProgressBar"
@ -552,6 +553,7 @@ class BECFigure(RPCBase):
def image( def image(
self, self,
monitor: "str" = None, monitor: "str" = None,
monitor_type: "Literal['1d', '2d']" = "2d",
color_bar: "Literal['simple', 'full']" = "full", color_bar: "Literal['simple', 'full']" = "full",
color_map: "str" = "magma", color_map: "str" = "magma",
data: "np.ndarray" = None, data: "np.ndarray" = None,
@ -856,6 +858,7 @@ class BECImageShow(RPCBase):
def image( def image(
self, self,
monitor: "str", monitor: "str",
monitor_type: "Literal['1d', '2d']" = "2d",
color_map: "Optional[str]" = "magma", color_map: "Optional[str]" = "magma",
color_bar: "Optional[Literal['simple', 'full']]" = "full", color_bar: "Optional[Literal['simple', 'full']]" = "full",
downsample: "Optional[bool]" = True, downsample: "Optional[bool]" = True,
@ -868,6 +871,7 @@ class BECImageShow(RPCBase):
Args: Args:
monitor(str): The name of the monitor to display. 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_bar(Literal["simple","full"]): The type of color bar to display.
color_map(str): The color map to use for the image. color_map(str): The color map to use for the image.
data(np.ndarray): Custom data to display. data(np.ndarray): Custom data to display.
@ -1180,6 +1184,7 @@ class BECImageWidget(RPCBase):
def image( def image(
self, self,
monitor: "str", monitor: "str",
monitor_type: "Optional[Literal['1d', '2d']]" = "2d",
color_map: "Optional[str]" = "magma", color_map: "Optional[str]" = "magma",
color_bar: "Optional[Literal['simple', 'full']]" = "full", color_bar: "Optional[Literal['simple', 'full']]" = "full",
downsample: "Optional[bool]" = True, 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): class ResetButton(RPCBase):
@property @property
@rpc_call @rpc_call

View File

@ -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. 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) self.initUI(default_colormaps)
def initUI(self, default_colormaps=None): def initUI(self, default_colormaps=None):
self.layout = QVBoxLayout(self) self.setItemDelegate(ColormapDelegate())
self.combo = QComboBox() self.currentTextChanged.connect(self.colormap_changed)
self.combo.setItemDelegate(ColormapDelegate())
self.combo.currentTextChanged.connect(self.colormap_changed)
self.available_colormaps = pg.colormap.listMaps() self.available_colormaps = pg.colormap.listMaps()
if default_colormaps is None: if default_colormaps is None:
default_colormaps = self.available_colormaps default_colormaps = self.available_colormaps
self.add_color_maps(default_colormaps) self.add_color_maps(default_colormaps)
self.layout.addWidget(self.combo)
@Slot() @Slot()
def colormap_changed(self): def colormap_changed(self):
""" """
Emit the colormap changed signal with the current colormap selected in the combobox. 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): def add_color_maps(self, colormaps=None):
""" """
@ -78,14 +75,14 @@ class ColormapSelector(QWidget):
Args: Args:
colormaps(list): List of colormaps to add to the combobox. If None, all available colormaps are added. 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: if colormaps is not None:
for name in colormaps: for name in colormaps:
if name in self.available_colormaps: if name in self.available_colormaps:
self.combo.addItem(name) self.addItem(name)
else: else:
for name in self.available_colormaps: 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 self._colormaps = colormaps if colormaps is not None else self.available_colormaps
@Property("QStringList") @Property("QStringList")

View File

@ -53,7 +53,7 @@ class CurveSettings(SettingWidget):
x_entry = self.target_widget.waveform._x_axis_mode["entry"] x_entry = self.target_widget.waveform._x_axis_mode["entry"]
self._enable_ui_elements(x_name, x_entry) self._enable_ui_elements(x_name, x_entry)
cm = self.target_widget.config.color_palette 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 # Scan Curve Table
for source in ["scan_segment", "async"]: for source in ["scan_segment", "async"]:
@ -115,10 +115,10 @@ class CurveSettings(SettingWidget):
@Slot() @Slot()
def change_colormap(self, target: Literal["scan", "dap"]): def change_colormap(self, target: Literal["scan", "dap"]):
if target == "scan": 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 table = self.ui.scan_table
if target == "dap": 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 table = self.ui.dap_table
rows = table.rowCount() rows = table.rowCount()
colors = Colors.golden_angle_color(colormap=cm, num=max(10, rows + 1), format="HEX") colors = Colors.golden_angle_color(colormap=cm, num=max(10, rows + 1), format="HEX")

View File

@ -17,26 +17,24 @@ def test_color_map_selector_init(color_map_selector):
assert isinstance(color_map_selector, ColormapSelector) assert isinstance(color_map_selector, ColormapSelector)
all_maps = pg.colormap.listMaps() all_maps = pg.colormap.listMaps()
loaded_maps = [ loaded_maps = [color_map_selector.itemText(i) for i in range(color_map_selector.count())]
color_map_selector.combo.itemText(i) for i in range(color_map_selector.combo.count())
]
assert len(loaded_maps) > 0 assert len(loaded_maps) > 0
assert all_maps == loaded_maps assert all_maps == loaded_maps
def test_color_map_selector_add_color_maps(color_map_selector): def test_color_map_selector_add_color_maps(color_map_selector):
color_map_selector.add_color_maps(["cividis", "viridis"]) color_map_selector.add_color_maps(["cividis", "viridis"])
assert color_map_selector.combo.count() == 2 assert color_map_selector.count() == 2
assert color_map_selector.combo.itemText(0) == "cividis" assert color_map_selector.itemText(0) == "cividis"
assert color_map_selector.combo.itemText(1) == "viridis" assert color_map_selector.itemText(1) == "viridis"
assert color_map_selector.combo.itemText(2) != "cividis" assert color_map_selector.itemText(2) != "cividis"
assert color_map_selector.combo.itemText(2) != "viridis" assert color_map_selector.itemText(2) != "viridis"
def test_colormap_add_maps_by_property(color_map_selector): def test_colormap_add_maps_by_property(color_map_selector):
color_map_selector.colormaps = ["cividis", "viridis"] color_map_selector.colormaps = ["cividis", "viridis"]
assert color_map_selector.combo.count() == 2 assert color_map_selector.count() == 2
assert color_map_selector.combo.itemText(0) == "cividis" assert color_map_selector.itemText(0) == "cividis"
assert color_map_selector.combo.itemText(1) == "viridis" assert color_map_selector.itemText(1) == "viridis"
assert color_map_selector.combo.itemText(2) != "cividis" assert color_map_selector.itemText(2) != "cividis"
assert color_map_selector.combo.itemText(2) != "viridis" assert color_map_selector.itemText(2) != "viridis"