0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

refactor(stop_button): stop button changed to QWidget and adapted for toolbar

This commit is contained in:
2024-08-29 11:11:54 +02:00
parent 4a890281f7
commit 097946fd68
2 changed files with 33 additions and 16 deletions

View File

@ -1,26 +1,44 @@
from qtpy.QtWidgets import QPushButton
from bec_qthemes import material_icon
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QHBoxLayout, QPushButton, QToolButton, QWidget
from bec_widgets.qt_utils.error_popups import SafeSlot as Slot
from bec_widgets.qt_utils.error_popups import SafeSlot
from bec_widgets.utils.bec_widget import BECWidget
class StopButton(BECWidget, QPushButton):
class StopButton(BECWidget, QWidget):
"""A button that stops the current scan."""
ICON_NAME = "dangerous"
def __init__(self, parent=None, client=None, config=None, gui_id=None):
def __init__(self, parent=None, client=None, config=None, gui_id=None, toolbar=False):
super().__init__(client=client, config=config, gui_id=gui_id)
QPushButton.__init__(self, parent=parent)
QWidget.__init__(self, parent=parent)
self.get_bec_shortcuts()
self.setText("Stop")
self.setStyleSheet(
"background-color: #cc181e; color: white; font-weight: bold; font-size: 12px;"
)
self.clicked.connect(self.stop_scan)
@Slot()
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(
"stop", size=(20, 20), color="#cc181e", filled=True, convert_to_pixmap=False
)
self.button = QToolButton(icon=icon)
self.button.triggered.connect(self.stop_scan)
else:
self.button = QPushButton()
self.button.setText("Stop")
self.button.setStyleSheet(
"background-color: #cc181e; color: white; font-weight: bold; font-size: 12px;"
)
self.button.clicked.connect(self.stop_scan)
self.layout.addWidget(self.button)
@SafeSlot()
def stop_scan(self):
"""Stop the scan."""
self.queue.request_scan_halt()

View File

@ -16,12 +16,11 @@ def stop_button(qtbot, mocked_client):
def test_stop_button(stop_button):
assert stop_button.text() == "Stop"
assert stop_button.button.text() == "Stop"
assert (
stop_button.styleSheet()
stop_button.button.styleSheet()
== "background-color: #cc181e; color: white; font-weight: bold; font-size: 12px;"
)
stop_button.click()
assert stop_button.queue.request_scan_abortion.called
assert stop_button.queue.request_queue_reset.called
stop_button.button.click()
assert stop_button.queue.request_scan_halt.called
stop_button.close()