mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-04-27 10:34:53 +02:00
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from bec_qthemes import material_icon
|
|
from qtpy.QtCore import Qt
|
|
from qtpy.QtWidgets import QHBoxLayout, QMessageBox, QPushButton, QToolButton, QWidget
|
|
|
|
from bec_widgets.qt_utils.error_popups import SafeSlot
|
|
from bec_widgets.utils.bec_widget import BECWidget
|
|
|
|
|
|
class ResetButton(BECWidget, QWidget):
|
|
"""A button that resets the scan queue."""
|
|
|
|
ICON_NAME = "restart_alt"
|
|
|
|
def __init__(self, parent=None, client=None, config=None, gui_id=None, toolbar=False):
|
|
super().__init__(client=client, config=config, gui_id=gui_id)
|
|
QWidget.__init__(self, parent=parent)
|
|
|
|
self.get_bec_shortcuts()
|
|
|
|
self.layout = QHBoxLayout(self)
|
|
self.layout.setSpacing(0)
|
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
|
self.layout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
|
|
|
|
if toolbar:
|
|
icon = material_icon(
|
|
"restart_alt", color="#F19E39", filled=True, convert_to_pixmap=False
|
|
)
|
|
self.button = QToolButton(icon=icon)
|
|
self.button.setToolTip("Reset the scan queue")
|
|
else:
|
|
self.button = QPushButton()
|
|
self.button.setText("Reset Queue")
|
|
self.button.setStyleSheet(
|
|
"background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
|
)
|
|
self.button.clicked.connect(self.confirm_reset_queue)
|
|
|
|
self.layout.addWidget(self.button)
|
|
|
|
@SafeSlot()
|
|
def confirm_reset_queue(self):
|
|
"""Prompt the user to confirm the queue reset."""
|
|
msg_box = QMessageBox()
|
|
msg_box.setIcon(QMessageBox.Warning)
|
|
msg_box.setWindowTitle("Confirm Reset")
|
|
msg_box.setText(
|
|
"Are you sure you want to reset the scan queue? This action cannot be undone."
|
|
)
|
|
msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
msg_box.setDefaultButton(QMessageBox.No)
|
|
|
|
if msg_box.exec_() == QMessageBox.Yes:
|
|
self.reset_queue()
|
|
|
|
@SafeSlot()
|
|
def reset_queue(self):
|
|
"""Reset the scan queue."""
|
|
self.queue.request_queue_reset()
|