mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-06-03 20:08:42 +02:00
feat(device_browser): connect update to item refresh
This commit is contained in:
@@ -29,7 +29,8 @@ class DeviceBrowser(BECWidget, QWidget):
|
||||
DeviceBrowser is a widget that displays all available devices in the current BEC session.
|
||||
"""
|
||||
|
||||
device_update: Signal = Signal()
|
||||
devices_changed: Signal = Signal()
|
||||
device_update: Signal = Signal(str, dict)
|
||||
PLUGIN = True
|
||||
ICON_NAME = "lists"
|
||||
|
||||
@@ -55,7 +56,7 @@ class DeviceBrowser(BECWidget, QWidget):
|
||||
self.bec_dispatcher.client.callbacks.register(
|
||||
EventType.DEVICE_UPDATE, self.on_device_update
|
||||
)
|
||||
self.device_update.connect(self.update_device_list)
|
||||
self.devices_changed.connect(self.update_device_list)
|
||||
self.ui.add_button.clicked.connect(self._create_add_dialog)
|
||||
self.ui.add_button.setIcon(material_icon("add", size=(20, 20), convert_to_pixmap=False))
|
||||
|
||||
@@ -85,7 +86,9 @@ class DeviceBrowser(BECWidget, QWidget):
|
||||
content (dict): The content of the config update.
|
||||
"""
|
||||
if action in ["add", "remove", "reload"]:
|
||||
self.device_update.emit()
|
||||
self.devices_changed.emit()
|
||||
if action in ["update", "reload"]:
|
||||
self.device_update.emit(action, content)
|
||||
|
||||
def init_device_list(self):
|
||||
self.dev_list.clear()
|
||||
@@ -117,6 +120,7 @@ class DeviceBrowser(BECWidget, QWidget):
|
||||
)
|
||||
device_item.expansion_state_changed.connect(partial(_updatesize, item, device_item))
|
||||
device_item.imminent_deletion.connect(partial(_remove_item, item))
|
||||
self.device_update.connect(device_item.config_update)
|
||||
tooltip = self.dev[device]._config.get("description", "")
|
||||
device_item.setToolTip(tooltip)
|
||||
device_item.broadcast_size_hint.connect(item.setSizeHint)
|
||||
|
||||
@@ -6,6 +6,7 @@ from bec_lib.atlas_models import Device as DeviceConfigModel
|
||||
from bec_lib.config_helper import ConfigHelper
|
||||
from bec_lib.devicemanager import DeviceContainer
|
||||
from bec_lib.logger import bec_logger
|
||||
from bec_lib.messages import ConfigAction
|
||||
from bec_qthemes import material_icon
|
||||
from qtpy.QtCore import QMimeData, QSize, Qt, QThreadPool, Signal
|
||||
from qtpy.QtGui import QDrag
|
||||
@@ -139,6 +140,11 @@ class DeviceItem(ExpandableGroupFrame):
|
||||
self.adjustSize()
|
||||
self.broadcast_size_hint.emit(self.sizeHint())
|
||||
|
||||
@SafeSlot(str, dict)
|
||||
def config_update(self, action: ConfigAction, content: dict) -> None:
|
||||
if self.device in content:
|
||||
self._reload_config()
|
||||
|
||||
@SafeSlot(popup_error=True)
|
||||
def _reload_config(self, *_):
|
||||
self.set_display_config(self.dev[self.device]._config)
|
||||
|
||||
@@ -7,6 +7,7 @@ from qtpy.QtWidgets import QDialogButtonBox, QPushButton
|
||||
from bec_widgets.utils.forms_from_types.items import StrFormItem
|
||||
from bec_widgets.widgets.services.device_browser.device_item.device_config_dialog import (
|
||||
DeviceConfigDialog,
|
||||
_try_literal_eval,
|
||||
)
|
||||
|
||||
_BASIC_CONFIG = {
|
||||
@@ -129,3 +130,12 @@ def test_add_form_validates_and_disables_on_init(add_dialog, qtbot):
|
||||
assert (ok_button := add_dialog.button_box.button(QDialogButtonBox.Ok)) is not None
|
||||
assert isinstance(ok_button, QPushButton)
|
||||
assert not ok_button.isEnabled()
|
||||
|
||||
|
||||
def test_try_literal_eval():
|
||||
assert _try_literal_eval("") == ""
|
||||
assert _try_literal_eval("[1, 2, 3]") == [1, 2, 3]
|
||||
assert _try_literal_eval('"[,,]"') == "[,,]"
|
||||
with pytest.raises(ValueError) as e:
|
||||
_try_literal_eval("[,,]")
|
||||
assert e.match("Entered config value [,,]")
|
||||
|
||||
Reference in New Issue
Block a user