mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-03-04 16:02:51 +01:00
wip: refactor
This commit is contained in:
@@ -2,13 +2,15 @@ from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import operator
|
||||
import os
|
||||
from enum import Enum, auto
|
||||
from functools import reduce
|
||||
from functools import partial, reduce
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
from typing import AbstractSet, Protocol
|
||||
|
||||
import bec_lib
|
||||
from bec_lib.atlas_models import Device
|
||||
from bec_lib.bec_yaml_loader import yaml_load
|
||||
from bec_lib.logger import bec_logger
|
||||
@@ -18,6 +20,7 @@ from pydantic import model_validator
|
||||
logger = bec_logger.logger
|
||||
|
||||
DEVICE_HASH_MODEL_KEY = "_hash_model"
|
||||
_BASE_REPO_PATH = Path(os.path.dirname(bec_lib.__file__)) / "../.."
|
||||
|
||||
|
||||
class HashModel(str, Enum):
|
||||
@@ -40,6 +43,7 @@ def _hash_input(device: HashableDevice) -> bytes:
|
||||
return (reduce(operator.add, (device.name, device.deviceClass, *config_values))).encode()
|
||||
|
||||
def _default_epics(device: HashableDevice):
|
||||
"""For EPICS devices, we care about the class and the PV prefix"""
|
||||
if device.deviceConfig is None or "prefix" not in device.deviceConfig:
|
||||
logger.warning(
|
||||
f"Device {device.name} doesn't specify a prefix, reverting to default HashModel"
|
||||
@@ -168,14 +172,17 @@ class _ConfigFileBackend(DeviceResourceBackend):
|
||||
def __init__(self) -> None:
|
||||
self._raw_device_set: set[
|
||||
HashableDevice
|
||||
] = self._get_config_from_backup_file() | self._get_configs_from_plugin_files(
|
||||
] = self._get_config_from_backup_files() | self._get_configs_from_plugin_files(
|
||||
Path(plugin_repo_path()) / plugin_package_name() / "device_configs/"
|
||||
)
|
||||
self._tag_groups = self._get_tag_groups()
|
||||
|
||||
def _get_config_from_backup_file(self):
|
||||
return _devices_from_file(
|
||||
"/home/perl_d/Development/bec/bec/logs/device_configs/recovery_configs/recovery_config_2025-08-22_14-02-29.yaml"
|
||||
def _get_config_from_backup_files(self):
|
||||
dir = _BASE_REPO_PATH / "logs/device_configs/recovery_configs"
|
||||
files = glob("*.yaml", root_dir=dir)
|
||||
return reduce(
|
||||
operator.or_,
|
||||
map(partial(_devices_from_file, include_source=False), (str(dir / f) for f in files)),
|
||||
)
|
||||
|
||||
def _get_configs_from_plugin_files(self, dir: Path):
|
||||
|
||||
@@ -7,7 +7,7 @@ from qtpy.QtWidgets import QFrame, QHBoxLayout, QLabel, QListWidgetItem, QVBoxLa
|
||||
from bec_widgets.widgets.control.device_manager.components.available_device_resources.device_resource_backend import (
|
||||
HashableDevice,
|
||||
)
|
||||
from bec_widgets.widgets.control.device_manager.components.available_device_resources.device_tag_group_item_ui import (
|
||||
from bec_widgets.widgets.control.device_manager.components.available_device_resources.device_tag_group_ui import (
|
||||
Ui_DeviceTagGroup,
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ def _warning_string(spec: HashableDevice):
|
||||
|
||||
|
||||
class _DeviceEntryWidget(QFrame):
|
||||
_grid_size = QSize(120, 80)
|
||||
# _grid_size = QSize(120, 80)
|
||||
|
||||
def __init__(self, device_spec: HashableDevice, parent=None, **kwargs):
|
||||
super().__init__(parent, **kwargs)
|
||||
@@ -42,17 +42,17 @@ class _DeviceEntryWidget(QFrame):
|
||||
self._layout = QVBoxLayout()
|
||||
self._layout.setContentsMargins(5, 5, 5, 5)
|
||||
self.setLayout(self._layout)
|
||||
self.setMinimumSize(self._grid_size)
|
||||
# self.setMinimumSize(self._grid_size)
|
||||
|
||||
self.setup_title_layout(device_spec)
|
||||
self.check_and_display_warning()
|
||||
|
||||
self.setToolTip(device_spec.rich_text())
|
||||
|
||||
self.details = QLabel(f"Tags:\n{', '.join(device_spec.deviceTags)}")
|
||||
self.details.setStyleSheet("QLabel { font-size: 8pt; }")
|
||||
self.details.setWordWrap(True)
|
||||
self._layout.addWidget(self.details)
|
||||
# self.details = QLabel(f"Tags:\n{', '.join(device_spec.deviceTags)}")
|
||||
# self.details.setStyleSheet("QLabel { font-size: 8pt; }")
|
||||
# self.details.setWordWrap(True)
|
||||
# self._layout.addWidget(self.details)
|
||||
|
||||
def setup_title_layout(self, device_spec: HashableDevice):
|
||||
self._title_layout = QHBoxLayout()
|
||||
@@ -104,7 +104,6 @@ class DeviceTagGroup(QWidget, Ui_DeviceTagGroup):
|
||||
):
|
||||
super().__init__(parent=parent, **kwargs)
|
||||
self.setupUi(self)
|
||||
self.device_list.setGridSize(_DeviceEntryWidget._grid_size)
|
||||
self.title.setText(name)
|
||||
self._devices: dict[str, _DeviceEntry] = {}
|
||||
for device in data:
|
||||
|
||||
@@ -20,9 +20,9 @@ from qtpy.QtWidgets import (
|
||||
class AutoHeightListWidget(QListWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setViewMode(QListView.ViewMode.IconMode)
|
||||
self.setViewMode(QListView.ViewMode.ListMode)
|
||||
self.setResizeMode(QListView.ResizeMode.Adjust)
|
||||
self.setWrapping(True)
|
||||
self.setWrapping(False)
|
||||
self.setUniformItemSizes(True)
|
||||
self.setMovement(QListView.Movement.Static)
|
||||
self.setAcceptDrops(False)
|
||||
Reference in New Issue
Block a user