mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(queue_reset_button): queue reset has to be confirmed with msgBox
This commit is contained in:
@ -1,11 +1,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from bec_lib.endpoints import MessageEndpoints
|
from bec_lib.endpoints import MessageEndpoints
|
||||||
|
from bec_qthemes import material_icon
|
||||||
from qtpy.QtCore import Property, Qt, Slot
|
from qtpy.QtCore import Property, Qt, Slot
|
||||||
from qtpy.QtGui import QColor
|
from qtpy.QtGui import QColor
|
||||||
from qtpy.QtWidgets import QHeaderView, QLabel, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget
|
from qtpy.QtWidgets import QHeaderView, QLabel, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget
|
||||||
|
|
||||||
from bec_qthemes import material_icon
|
|
||||||
from bec_widgets.qt_utils.toolbar import ModularToolBar, SeparatorAction, WidgetAction
|
from bec_widgets.qt_utils.toolbar import ModularToolBar, SeparatorAction, WidgetAction
|
||||||
from bec_widgets.utils.bec_connector import ConnectionConfig
|
from bec_widgets.utils.bec_connector import ConnectionConfig
|
||||||
from bec_widgets.utils.bec_widget import BECWidget
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
from bec_qthemes import material_icon
|
from bec_qthemes import material_icon
|
||||||
from qtpy.QtCore import Qt
|
from qtpy.QtCore import Qt
|
||||||
from qtpy.QtWidgets import QHBoxLayout, QPushButton, QToolButton, QWidget
|
from qtpy.QtWidgets import QHBoxLayout, QMessageBox, QPushButton, QToolButton, QWidget
|
||||||
|
|
||||||
from bec_widgets.qt_utils.error_popups import SafeSlot
|
from bec_widgets.qt_utils.error_popups import SafeSlot
|
||||||
from bec_widgets.utils.bec_widget import BECWidget
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
|
|
||||||
|
|
||||||
class ResetButton(BECWidget, QWidget):
|
class ResetButton(BECWidget, QWidget):
|
||||||
"""A button that reset the scan queue."""
|
"""A button that resets the scan queue."""
|
||||||
|
|
||||||
ICON_NAME = "restart_alt"
|
ICON_NAME = "restart_alt"
|
||||||
|
|
||||||
@ -34,11 +34,26 @@ class ResetButton(BECWidget, QWidget):
|
|||||||
self.button.setStyleSheet(
|
self.button.setStyleSheet(
|
||||||
"background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
"background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
||||||
)
|
)
|
||||||
self.button.clicked.connect(self.reset_queue)
|
self.button.clicked.connect(self.confirm_reset_queue)
|
||||||
|
|
||||||
self.layout.addWidget(self.button)
|
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()
|
@SafeSlot()
|
||||||
def reset_queue(self):
|
def reset_queue(self):
|
||||||
"""Stop the scan."""
|
"""Reset the scan queue."""
|
||||||
self.queue.request_queue_reset()
|
self.queue.request_queue_reset()
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from qtpy.QtWidgets import QMessageBox
|
||||||
|
|
||||||
from bec_widgets.widgets.button_reset.button_reset import ResetButton
|
from bec_widgets.widgets.button_reset.button_reset import ResetButton
|
||||||
|
|
||||||
@ -15,12 +18,23 @@ def reset_button(qtbot, mocked_client):
|
|||||||
yield widget
|
yield widget
|
||||||
|
|
||||||
|
|
||||||
def test_stop_button(reset_button):
|
def test_reset_button_appearance(reset_button):
|
||||||
assert reset_button.button.text() == "Reset Queue"
|
assert reset_button.button.text() == "Reset Queue"
|
||||||
assert (
|
assert (
|
||||||
reset_button.button.styleSheet()
|
reset_button.button.styleSheet()
|
||||||
== "background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
== "background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch.object(QMessageBox, "exec_", return_value=QMessageBox.Yes)
|
||||||
|
def test_reset_button_confirmed(mock_exec, reset_button):
|
||||||
reset_button.button.click()
|
reset_button.button.click()
|
||||||
assert reset_button.queue.request_queue_reset.called
|
assert reset_button.queue.request_queue_reset.called
|
||||||
reset_button.close()
|
reset_button.close()
|
||||||
|
|
||||||
|
|
||||||
|
@patch.object(QMessageBox, "exec_", return_value=QMessageBox.No)
|
||||||
|
def test_reset_button_cancelled(mock_exec, reset_button):
|
||||||
|
reset_button.button.click()
|
||||||
|
assert not reset_button.queue.request_queue_reset.called
|
||||||
|
reset_button.close()
|
||||||
|
Reference in New Issue
Block a user