mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-12 18:51:50 +02:00
improve scan history device fixup
This commit is contained in:
@ -17,15 +17,16 @@ logger = bec_logger.logger
|
||||
# TODO check cleanup
|
||||
# Custom model
|
||||
class DeviceModel(QtCore.QAbstractListModel):
|
||||
def __init__(self, devices=None):
|
||||
super().__init__()
|
||||
|
||||
def __init__(self, parent=None, devices: dict[str, int] = None):
|
||||
super().__init__(parent)
|
||||
if devices is None:
|
||||
devices = {}
|
||||
self._devices = sorted(devices.items(), key=lambda x: -x[1])
|
||||
self._devices: list[tuple] = sorted(devices.items(), key=lambda x: -x[1])
|
||||
|
||||
# @SafeProperty(list) # TODO if SafeProperty, how to pass the type list[tuple[str, int]]?
|
||||
@property
|
||||
def devices(self) -> list[tuple[str, int]]:
|
||||
def devices(self):
|
||||
"""Return the list of devices."""
|
||||
return self._devices
|
||||
|
||||
@ -35,8 +36,8 @@ class DeviceModel(QtCore.QAbstractListModel):
|
||||
self._devices = sorted(value.items(), key=lambda x: -x[1])
|
||||
self.endResetModel()
|
||||
|
||||
def rowCount(self, **kwargs): # parent=QtCore.QModelIndex()):
|
||||
return len(self.devices)
|
||||
def rowCount(self, parent=QtCore.QModelIndex()):
|
||||
return len(self._devices)
|
||||
|
||||
def data(self, index, role=QtCore.Qt.DisplayRole):
|
||||
if not index.isValid():
|
||||
@ -104,14 +105,14 @@ class ScanHistoryDeviceViewer(BECWidget, QtWidgets.QWidget):
|
||||
layout = QtWidgets.QHBoxLayout(self)
|
||||
self.setLayout(layout)
|
||||
# Init ComboBox
|
||||
self.device_combo = QtWidgets.QComboBox(self)
|
||||
self.device_combo = QtWidgets.QComboBox(parent=self)
|
||||
colors = get_accent_colors()
|
||||
self.request_plotting_button = QtWidgets.QPushButton(
|
||||
material_icon("play_arrow", size=(24, 24), color=colors.success),
|
||||
"Request Plotting",
|
||||
self,
|
||||
)
|
||||
self.device_model = DeviceModel({})
|
||||
self.device_model = DeviceModel(parent=self.device_combo)
|
||||
self.device_combo.setModel(self.device_model)
|
||||
layout.addWidget(self.device_combo)
|
||||
layout.addWidget(self.request_plotting_button)
|
||||
@ -166,6 +167,14 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
main_window = QtWidgets.QMainWindow()
|
||||
central_widget = QtWidgets.QWidget()
|
||||
main_window.setCentralWidget(central_widget)
|
||||
layout = QtWidgets.QVBoxLayout(central_widget)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
viewer = ScanHistoryDeviceViewer()
|
||||
viewer.show()
|
||||
sys.exit(app.exec_())
|
||||
layout.addWidget(viewer)
|
||||
main_window.show()
|
||||
app.exec_()
|
||||
|
Reference in New Issue
Block a user