diff --git a/bec_widgets/tests/utils.py b/bec_widgets/tests/utils.py index 6351180a..1b0b9885 100644 --- a/bec_widgets/tests/utils.py +++ b/bec_widgets/tests/utils.py @@ -184,8 +184,8 @@ class FakePositioner(BECPositioner): class Positioner(FakePositioner): """just placeholder for testing embedded isinstance check in DeviceCombobox""" - def __init__(self, name="test", limits=None, read_value=1.0): - super().__init__(name, limits, read_value) + def __init__(self, name="test", limits=None, read_value=1.0, enabled=True): + super().__init__(name, limits=limits, read_value=read_value, enabled=enabled) class Device(FakeDevice): diff --git a/bec_widgets/utils/expandable_frame.py b/bec_widgets/utils/expandable_frame.py index 2f5f994a..b5fd590b 100644 --- a/bec_widgets/utils/expandable_frame.py +++ b/bec_widgets/utils/expandable_frame.py @@ -20,7 +20,9 @@ class ExpandableGroupFrame(QFrame): EXPANDED_ICON_NAME: str = "collapse_all" COLLAPSED_ICON_NAME: str = "expand_all" - def __init__(self, title: str, parent: QWidget | None = None, expanded: bool = True) -> None: + def __init__( + self, title: str, parent: QWidget | None = None, expanded: bool = True, icon: str = "" + ) -> None: super().__init__(parent=parent) self._expanded = expanded @@ -29,13 +31,21 @@ class ExpandableGroupFrame(QFrame): self._layout = QVBoxLayout() self._layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self._layout) + self._title_layout = QHBoxLayout() self._layout.addLayout(self._title_layout) - self._expansion_button = QToolButton() - self._update_icon() + self._title = QLabel(f"{title}") - self._title_layout.addWidget(self._expansion_button) + self._title_icon = QLabel() + self._title_layout.addWidget(self._title_icon) self._title_layout.addWidget(self._title) + self.icon_name = icon + + self._title_layout.addStretch(1) + + self._expansion_button = QToolButton() + self._update_expansion_icon() + self._title_layout.addWidget(self._expansion_button, stretch=1) self._contents = QWidget(self) self._layout.addWidget(self._contents) @@ -50,7 +60,7 @@ class ExpandableGroupFrame(QFrame): @SafeSlot() def switch_expanded_state(self): self.expanded = not self.expanded # type: ignore - self._update_icon() + self._update_expansion_icon() @SafeProperty(bool) def expanded(self): # type: ignore @@ -62,7 +72,7 @@ class ExpandableGroupFrame(QFrame): self._contents.setVisible(expanded) self.updateGeometry() - def _update_icon(self): + def _update_expansion_icon(self): self._expansion_button.setIcon( material_icon(icon_name=self.EXPANDED_ICON_NAME, size=(10, 10), convert_to_pixmap=False) if self.expanded @@ -70,3 +80,21 @@ class ExpandableGroupFrame(QFrame): icon_name=self.COLLAPSED_ICON_NAME, size=(10, 10), convert_to_pixmap=False ) ) + + @SafeProperty(str) + def icon_name(self): # type: ignore + return self._title_icon_name + + @icon_name.setter + def icon_name(self, icon_name: str): + self._title_icon_name = icon_name + self._set_title_icon(self._title_icon_name) + + def _set_title_icon(self, icon_name: str): + if icon_name: + self._title_icon.setVisible(True) + self._title_icon.setPixmap( + material_icon(icon_name=icon_name, size=(20, 20), convert_to_pixmap=True) + ) + else: + self._title_icon.setVisible(False) diff --git a/bec_widgets/widgets/editors/dict_backed_table.py b/bec_widgets/widgets/editors/dict_backed_table.py index 05e42543..a504b3d5 100644 --- a/bec_widgets/widgets/editors/dict_backed_table.py +++ b/bec_widgets/widgets/editors/dict_backed_table.py @@ -45,7 +45,11 @@ class DictBackedTableModel(QAbstractTableModel): def data(self, index, role=Qt.ItemDataRole): if index.isValid(): - if role == Qt.ItemDataRole.DisplayRole or role == Qt.ItemDataRole.EditRole: + if role in [ + Qt.ItemDataRole.DisplayRole, + Qt.ItemDataRole.EditRole, + Qt.ItemDataRole.ToolTipRole, + ]: return str(self._data[index.row()][index.column()]) def setData(self, index, value, role): @@ -132,7 +136,7 @@ class DictBackedTable(QWidget): self._table_view = QTreeView() self._table_view.setModel(self._table_model) self._table_view.setSizePolicy( - QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum) + QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) ) self._table_view.setAlternatingRowColors(True) self._layout.addWidget(self._table_view) diff --git a/tests/unit_tests/test_device_browser.py b/tests/unit_tests/test_device_browser.py index b7559e4d..b530aa7d 100644 --- a/tests/unit_tests/test_device_browser.py +++ b/tests/unit_tests/test_device_browser.py @@ -11,7 +11,13 @@ from .client_mocks import mocked_client if TYPE_CHECKING: # pragma: no cover from qtpy.QtWidgets import QListWidgetItem - from bec_widgets.widgets.services.device_browser import DeviceItem + from bec_widgets.widgets.services.device_browser.device_item import DeviceItem + + +# pylint: disable=no-member +# pylint: disable=missing-function-docstring +# pylint: disable=redefined-outer-name +# pylint: disable=protected-access @pytest.fixture @@ -34,18 +40,21 @@ def test_device_browser_filtering(qtbot, device_browser): """ Test that the device browser is able to filter the device list. """ - device_list = device_browser.ui.device_list + + def num_visible(item_dict): + return len(list(filter(lambda i: not i.isHidden(), item_dict.values()))) + device_browser.ui.filter_input.setText("sam") qtbot.wait(1000) - assert device_list.count() == 3 + assert num_visible(device_browser._device_items) == 3 device_browser.ui.filter_input.setText("nonexistent") qtbot.wait(1000) - assert device_list.count() == 0 + assert num_visible(device_browser._device_items) == 0 device_browser.ui.filter_input.setText("") qtbot.wait(1000) - assert device_list.count() == len(device_browser.dev) + assert num_visible(device_browser._device_items) == len(device_browser.dev) def test_device_item_mouse_press_event(device_browser, qtbot): @@ -55,7 +64,7 @@ def test_device_item_mouse_press_event(device_browser, qtbot): # Simulate a left mouse press event on the device item device_item: QListWidgetItem = device_browser.ui.device_list.itemAt(0, 0) widget: DeviceItem = device_browser.ui.device_list.itemWidget(device_item) - qtbot.mouseClick(widget.label, Qt.MouseButton.LeftButton) + qtbot.mouseClick(widget._title, Qt.MouseButton.LeftButton) def test_device_item_mouse_press_and_move_events_creates_drag(device_browser, qtbot): @@ -67,7 +76,7 @@ def test_device_item_mouse_press_and_move_events_creates_drag(device_browser, qt device_name = widget.device with mock.patch("qtpy.QtGui.QDrag.exec_") as mock_exec: with mock.patch("qtpy.QtGui.QDrag.setMimeData") as mock_set_mimedata: - qtbot.mousePress(widget.label, Qt.MouseButton.LeftButton, pos=QPoint(0, 0)) + qtbot.mousePress(widget._title, Qt.MouseButton.LeftButton, pos=QPoint(0, 0)) qtbot.mouseMove(widget, pos=QPoint(10, 10)) qtbot.mouseRelease(widget, Qt.MouseButton.LeftButton) mock_set_mimedata.assert_called_once()