GUI: updated reference_tools_panel.py and connected update_daq_status
This commit is contained in:
1 parent
4cd7c865f7
commit
e8c1040bec
2 files changed
+67
-24
No files matched your search
@@ -270,6 +270,7 @@ class MainWindow(QMainWindow):
|
||||
self.daq.update.connect(self.raster.update_daq_status)
|
||||
self.daq.update.connect(self.sample_camera.update_daq_status)
|
||||
self.daq.update.connect(self.tell_samples.update_daq_status)
|
||||
self.daq.update.connect(self.ref_tools_panel.update_daq_status)
|
||||
self.daq.update.connect(self.beamline.abr_tweak.update_daq_status)
|
||||
self.daq.update.connect(self.status_bar.update_daq_status)
|
||||
self.daq.update.connect(self.beamline.samcam.update_daq_status)
|
||||
|
||||
@@ -12,14 +12,23 @@ from PySide6.QtWidgets import (
|
||||
QMenu,
|
||||
QAbstractItemView,
|
||||
)
|
||||
from aaredaqlib.models import SampleShortInfoList, SampleShortInfo, BeamlineStateEnum
|
||||
from aaredaqlib.models import SampleShortInfoList, SampleShortInfo, BeamlineStateEnum, DAQStatusModel
|
||||
from aaregui.widgets.title_label import TitleLabel
|
||||
|
||||
def get_entry(sample: SampleShortInfo, column: int):
|
||||
if column == 0:
|
||||
return sample.loc_str()
|
||||
elif column == 1:
|
||||
return sample.sample_name
|
||||
elif column == 2:
|
||||
return sample.mount_count
|
||||
|
||||
class ReferenceToolsModel(QAbstractTableModel):
|
||||
def __init__(self, rows: Optional[list[SampleShortInfo]] | None = None, parent=None, current_reference: int | None = None,):
|
||||
super().__init__(parent)
|
||||
self._rows: list[SampleShortInfo] = rows or []
|
||||
self.current_reference = current_reference
|
||||
self.__sort_col = 1
|
||||
self.__sort_col = 4
|
||||
self.__sort_order = Qt.SortOrder.AscendingOrder
|
||||
self._sort()
|
||||
|
||||
@@ -46,7 +55,7 @@ class ReferenceToolsModel(QAbstractTableModel):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return None
|
||||
if orientation == Qt.Orientation.Horizontal:
|
||||
return ("position", "sample_name", "mount_count")[section]
|
||||
return ("Position", "Sample name", "Mount count")[section]
|
||||
return str(section + 1)
|
||||
|
||||
def update_rows(self, rows: list[SampleShortInfo]):
|
||||
@@ -64,9 +73,9 @@ class ReferenceToolsModel(QAbstractTableModel):
|
||||
def _sort(self):
|
||||
self.__sorted_samples = sorted(
|
||||
self._rows,
|
||||
key=lambda row: row[0],
|
||||
key=lambda row: get_entry(row, self.__sort_col),
|
||||
reverse=(
|
||||
self.__sort_order == Qt.SortOrder.AscendingOrder
|
||||
self.__sort_order == Qt.SortOrder.DescendingOrder
|
||||
), # Reverse for descending order
|
||||
)
|
||||
|
||||
@@ -78,7 +87,7 @@ class ReferenceToolsModel(QAbstractTableModel):
|
||||
return None
|
||||
|
||||
class ReferenceToolsPanel(QFrame):
|
||||
mount = Signal(SampleShortInfo)
|
||||
mount = Signal(SampleShortInfo, bool)
|
||||
unmount = Signal(SampleShortInfo)
|
||||
|
||||
def __init__(self, samples: SampleShortInfoList | None = None, parent=None, refresh_interval_ms: int = 5000):
|
||||
@@ -98,35 +107,43 @@ class ReferenceToolsPanel(QFrame):
|
||||
layout = QGridLayout(self)
|
||||
self.setLayout(layout)
|
||||
|
||||
layout.addWidget(QLabel("Reference tools", parent=self), 0, 0, 1, 2)
|
||||
layout.addWidget(TitleLabel("Reference tools", parent=self), 0, 0, 1, 4)
|
||||
|
||||
self.table_view = QTableView(parent=self)
|
||||
layout.addWidget(self.table_view, 1, 0, 1, 4)
|
||||
|
||||
self.curr_sample_label = QLabel("No sample mounted", parent=self)
|
||||
layout.addWidget(self.curr_sample_label, 2, 0)
|
||||
|
||||
self.unmount_button = QPushButton("Unmount", parent=self)
|
||||
layout.addWidget(self.unmount_button, 2, 1)
|
||||
self.unmount_button.clicked.connect(self._on_unmount_clicked)
|
||||
|
||||
layout.setColumnStretch(0, 1)
|
||||
layout.setColumnStretch(1, 0)
|
||||
|
||||
# initialize model with provided samples
|
||||
self.table_model = ReferenceToolsModel(rows=samples.s)
|
||||
self.table_view.setModel(self.table_model)
|
||||
self.table_view.verticalHeader().setVisible(False)
|
||||
self.table_view.horizontalHeader().setSectionResizeMode(
|
||||
QHeaderView.ResizeMode.Stretch
|
||||
)
|
||||
|
||||
self.table_view.setEditTriggers(QTableView.EditTrigger.NoEditTriggers)
|
||||
header = self.table_view.horizontalHeader()
|
||||
header.setSectionResizeMode(QHeaderView.ResizeMode.Interactive)
|
||||
header.setStretchLastSection(True)
|
||||
self.table_view.verticalHeader().setVisible(True)
|
||||
|
||||
|
||||
self.table_view.setSelectionBehavior(QTableView.SelectionBehavior.SelectRows)
|
||||
self.table_view.setSelectionMode(QTableView.SelectionMode.SingleSelection)
|
||||
self.table_view.setSortingEnabled(True)
|
||||
self.table_view.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
self.table_view.customContextMenuRequested.connect(self._context_menu)
|
||||
|
||||
layout.addWidget(self.table_view, 1, 0, 1, 2)
|
||||
|
||||
self.unmount_button = QPushButton("Unmount", parent=self)
|
||||
layout.addWidget(self.unmount_button, 2, 0)
|
||||
self.unmount_button.clicked.connect(self._on_unmount_clicked)
|
||||
|
||||
# self._timer = QTimer(self)
|
||||
# self._timer.setInterval(refresh_interval_ms)
|
||||
# self._timer.timeout.connect() # implement to call DAQ/adapter
|
||||
# self._timer.start()
|
||||
self.table_view.setSelectionBehavior(
|
||||
QAbstractItemView.SelectionBehavior.SelectRows
|
||||
)
|
||||
self.table_view.setSelectionMode(
|
||||
QTableView.SelectionMode.SingleSelection
|
||||
)
|
||||
|
||||
def _selected_item(self) -> Optional[SampleShortInfo]:
|
||||
idx = self.table_view.currentIndex()
|
||||
@@ -141,21 +158,46 @@ class ReferenceToolsPanel(QFrame):
|
||||
|
||||
def _context_menu(self, position):
|
||||
idx = self.table_view.indexAt(position)
|
||||
|
||||
if not idx.isValid():
|
||||
return
|
||||
|
||||
item = self.table_model.get_item(idx.row())
|
||||
|
||||
if item is None:
|
||||
return
|
||||
|
||||
menu = QMenu()
|
||||
act_mount = menu.addAction("Mount")
|
||||
|
||||
act_unmount = menu.addAction("Unmount")
|
||||
|
||||
action = menu.exec_(self.table_view.viewport().mapToGlobal(position))
|
||||
|
||||
if action == act_mount:
|
||||
self.mount.emit(item)
|
||||
self.mount.emit(item, True)
|
||||
elif action == act_unmount:
|
||||
self.unmount.emit(item)
|
||||
|
||||
@Slot(SampleShortInfoList)
|
||||
def new_list(self, samples: SampleShortInfoList):
|
||||
# signal from DAQWorker will call this with the model
|
||||
self.table_model.update_rows(rows=samples.s)
|
||||
self.table_model.update_rows(rows=samples.s)
|
||||
|
||||
@Slot(DAQStatusModel)
|
||||
def update_daq_status(self, status: DAQStatusModel):
|
||||
sample = status.sample
|
||||
if sample is None:
|
||||
self.curr_sample_label.setText("No sample mounted")
|
||||
else:
|
||||
try:
|
||||
if sample.location is None:
|
||||
self.curr_sample_label.setText(
|
||||
f"Current sample: <b>{sample.sample_name} (Manual mount)</b>"
|
||||
)
|
||||
else:
|
||||
self.curr_sample_label.setText(
|
||||
f"Current sample: <b>{sample.sample_name} ({sample.location.segment}{sample.location.pos}-{sample.pin})</b>"
|
||||
)
|
||||
except Exception as e:
|
||||
self.curr_sample_label.setText(f"Confusing information :/ {e}")
|
||||
Reference in new issue
Block a user