0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

feat(widgets/stop_button): General stop button added

This commit is contained in:
2024-06-12 00:42:37 +02:00
parent 40b5688158
commit 61ba08d0b8
7 changed files with 98 additions and 0 deletions

View File

@ -1,3 +1,4 @@
from .buttons import StopButton
from .dock import BECDock, BECDockArea from .dock import BECDock, BECDockArea
from .figure import BECFigure, FigureConfig from .figure import BECFigure, FigureConfig
from .scan_control import ScanControl from .scan_control import ScanControl

View File

@ -0,0 +1 @@
from .stop_button.stop_button import StopButton

View File

@ -0,0 +1,32 @@
from qtpy.QtWidgets import QPushButton
from bec_widgets.utils import BECConnector
class StopButton(BECConnector, QPushButton):
"""A button that stops the current scan."""
def __init__(self, parent=None, client=None, config=None, gui_id=None):
super().__init__(client=client, config=config, gui_id=gui_id)
QPushButton.__init__(self, parent=parent)
self.get_bec_shortcuts()
self.setText("Stop")
self.setStyleSheet("background-color: #cc181e; color: white")
self.clicked.connect(self.stop_scan)
def stop_scan(self):
"""Stop the scan."""
self.queue.request_scan_abortion()
self.queue.request_queue_reset()
if __name__ == "__main__": # pragma: no cover
import sys
from qtpy.QtWidgets import QApplication
app = QApplication(sys.argv)
widget = StopButton()
widget.show()
sys.exit(app.exec_())

View File

@ -0,0 +1,38 @@
(user.widgets.buttons)=
# Buttons Widgets
This section consolidates various custom buttons used within the BEC GUIs, facilitating the integration of these
controls into different layouts.
## Stop Button
**Purpose:**
The `Stop Button` provides a user interface control to immediately halt the execution of the current operation in the
BEC Client. It is designed for easy integration into any BEC GUI layout.
**Key Features:**
- **Immediate Termination:** Halts the execution of the current script or process.
- **Queue Management:** Clears any pending operations in the scan queue, ensuring the system is ready for new tasks.
**Code example:**
Integrating the `StopButton` into a BEC GUI layout is straightforward. The following example demonstrates how to embed
a `StopButton` within a GUI layout:
```python
from qtpy.QtWidgets import QWidget, QVBoxLayout
from bec_widgets.widgets import StopButton
class MyGui(QWidget):
def __init__(self):
super().__init__()
self.setLayout(QVBoxLayout(self)) # Initialize the layout for the widget
# Create and add the StopButton to the layout
self.stop_button = StopButton()
self.layout().addWidget(self.stop_button)
```

View File

@ -11,6 +11,7 @@ hidden: false
bec_figure/ bec_figure/
spiral_progress_bar/ spiral_progress_bar/
website/ website/
buttons/
``` ```

View File

@ -0,0 +1,25 @@
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
import pytest
from bec_widgets.widgets import StopButton
from .client_mocks import mocked_client
@pytest.fixture
def stop_button(qtbot, mocked_client):
widget = StopButton(client=mocked_client)
qtbot.addWidget(widget)
qtbot.waitExposed(widget)
yield widget
widget.close()
def test_stop_button(stop_button):
assert stop_button.text() == "Stop"
assert stop_button.styleSheet() == "background-color: #cc181e; color: white"
stop_button.click()
assert stop_button.queue.request_scan_abortion.called
assert stop_button.queue.request_queue_reset.called
stop_button.close()