mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(abort_button): abort button added; some minor fixes
This commit is contained in:
@ -13,6 +13,7 @@ class Widgets(str, enum.Enum):
|
|||||||
Enum for the available widgets.
|
Enum for the available widgets.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
AbortButton = "AbortButton"
|
||||||
BECDock = "BECDock"
|
BECDock = "BECDock"
|
||||||
BECDockArea = "BECDockArea"
|
BECDockArea = "BECDockArea"
|
||||||
BECFigure = "BECFigure"
|
BECFigure = "BECFigure"
|
||||||
@ -36,6 +37,24 @@ class Widgets(str, enum.Enum):
|
|||||||
WebsiteWidget = "WebsiteWidget"
|
WebsiteWidget = "WebsiteWidget"
|
||||||
|
|
||||||
|
|
||||||
|
class AbortButton(RPCBase):
|
||||||
|
@property
|
||||||
|
@rpc_call
|
||||||
|
def _config_dict(self) -> "dict":
|
||||||
|
"""
|
||||||
|
Get the configuration of the widget.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: The configuration of the widget.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def _get_all_rpc(self) -> "dict":
|
||||||
|
"""
|
||||||
|
Get all registered RPC objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class BECCurve(RPCBase):
|
class BECCurve(RPCBase):
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def remove(self):
|
def remove(self):
|
||||||
@ -2374,7 +2393,7 @@ class DeviceLineEdit(RPCBase):
|
|||||||
|
|
||||||
class PositionerBox(RPCBase):
|
class PositionerBox(RPCBase):
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def set_positioner(self, positioner: str):
|
def set_positioner(self, positioner: "str | Positioner"):
|
||||||
"""
|
"""
|
||||||
Set the device
|
Set the device
|
||||||
|
|
||||||
@ -2385,7 +2404,7 @@ class PositionerBox(RPCBase):
|
|||||||
|
|
||||||
class PositionerControlLine(RPCBase):
|
class PositionerControlLine(RPCBase):
|
||||||
@rpc_call
|
@rpc_call
|
||||||
def set_positioner(self, positioner: str):
|
def set_positioner(self, positioner: "str | Positioner"):
|
||||||
"""
|
"""
|
||||||
Set the device
|
Set the device
|
||||||
|
|
||||||
|
0
bec_widgets/widgets/button_abort/__init__.py
Normal file
0
bec_widgets/widgets/button_abort/__init__.py
Normal file
1
bec_widgets/widgets/button_abort/abort_button.pyproject
Normal file
1
bec_widgets/widgets/button_abort/abort_button.pyproject
Normal file
@ -0,0 +1 @@
|
|||||||
|
{'files': ['button_abort.py']}
|
54
bec_widgets/widgets/button_abort/abort_button_plugin.py
Normal file
54
bec_widgets/widgets/button_abort/abort_button_plugin.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||||
|
|
||||||
|
from qtpy.QtDesigner import QDesignerCustomWidgetInterface
|
||||||
|
|
||||||
|
from bec_widgets.utils.bec_designer import designer_material_icon
|
||||||
|
from bec_widgets.widgets.button_abort.button_abort import AbortButton
|
||||||
|
|
||||||
|
DOM_XML = """
|
||||||
|
<ui language='c++'>
|
||||||
|
<widget class='AbortButton' name='abort_button'>
|
||||||
|
</widget>
|
||||||
|
</ui>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class AbortButtonPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self._form_editor = None
|
||||||
|
|
||||||
|
def createWidget(self, parent):
|
||||||
|
t = AbortButton(parent)
|
||||||
|
return t
|
||||||
|
|
||||||
|
def domXml(self):
|
||||||
|
return DOM_XML
|
||||||
|
|
||||||
|
def group(self):
|
||||||
|
return "BEC Buttons"
|
||||||
|
|
||||||
|
def icon(self):
|
||||||
|
return designer_material_icon(AbortButton.ICON_NAME)
|
||||||
|
|
||||||
|
def includeFile(self):
|
||||||
|
return "abort_button"
|
||||||
|
|
||||||
|
def initialize(self, form_editor):
|
||||||
|
self._form_editor = form_editor
|
||||||
|
|
||||||
|
def isContainer(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def isInitialized(self):
|
||||||
|
return self._form_editor is not None
|
||||||
|
|
||||||
|
def name(self):
|
||||||
|
return "AbortButton"
|
||||||
|
|
||||||
|
def toolTip(self):
|
||||||
|
return "A button that abort the scan."
|
||||||
|
|
||||||
|
def whatsThis(self):
|
||||||
|
return self.toolTip()
|
49
bec_widgets/widgets/button_abort/button_abort.py
Normal file
49
bec_widgets/widgets/button_abort/button_abort.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
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
|
||||||
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
|
|
||||||
|
|
||||||
|
class AbortButton(BECWidget, QWidget):
|
||||||
|
"""A button that abort the scan."""
|
||||||
|
|
||||||
|
ICON_NAME = "cancel"
|
||||||
|
|
||||||
|
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("cancel", color="#666666", filled=True)
|
||||||
|
self.button = QToolButton(icon=icon)
|
||||||
|
self.button.triggered.connect(self.abort_scan)
|
||||||
|
else:
|
||||||
|
self.button = QPushButton()
|
||||||
|
self.button.setText("Abort")
|
||||||
|
self.button.setStyleSheet(
|
||||||
|
"background-color: #666666; color: white; font-weight: bold; font-size: 12px;"
|
||||||
|
)
|
||||||
|
self.button.clicked.connect(self.abort_scan)
|
||||||
|
|
||||||
|
self.layout.addWidget(self.button)
|
||||||
|
|
||||||
|
@SafeSlot()
|
||||||
|
def abort_scan(
|
||||||
|
self,
|
||||||
|
): # , scan_id: str | None = None): #FIXME scan_id will be added when combining with Queue widget
|
||||||
|
"""
|
||||||
|
Abort the scan.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
scan_id(str|None): The scan id to abort. If None, the current scan will be aborted.
|
||||||
|
"""
|
||||||
|
self.queue.request_scan_abortion()
|
15
bec_widgets/widgets/button_abort/register_abort_button.py
Normal file
15
bec_widgets/widgets/button_abort/register_abort_button.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
def main(): # pragma: no cover
|
||||||
|
from qtpy import PYSIDE6
|
||||||
|
|
||||||
|
if not PYSIDE6:
|
||||||
|
print("PYSIDE6 is not available in the environment. Cannot patch designer.")
|
||||||
|
return
|
||||||
|
from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
|
||||||
|
|
||||||
|
from bec_widgets.widgets.button_abort.abort_button_plugin import AbortButtonPlugin
|
||||||
|
|
||||||
|
QPyDesignerCustomWidgetCollection.addCustomWidget(AbortButtonPlugin())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": # pragma: no cover
|
||||||
|
main()
|
@ -30,7 +30,7 @@ class ResumeButton(BECWidget, QWidget):
|
|||||||
self.button = QPushButton()
|
self.button = QPushButton()
|
||||||
self.button.setText("Resume")
|
self.button.setText("Resume")
|
||||||
self.button.setStyleSheet(
|
self.button.setStyleSheet(
|
||||||
"background-color: #2793e8 color: white; font-weight: bold; font-size: 12px;"
|
"background-color: #2793e8; color: white; font-weight: bold; font-size: 12px;"
|
||||||
)
|
)
|
||||||
self.button.clicked.connect(self.continue_scan)
|
self.button.clicked.connect(self.continue_scan)
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
""" Module for a PositionerBox widget to control a positioner device."""
|
""" Module for a PositionerBox widget to control a positioner device."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
@ -37,6 +37,13 @@ class StopButton(BECWidget, QWidget):
|
|||||||
self.layout.addWidget(self.button)
|
self.layout.addWidget(self.button)
|
||||||
|
|
||||||
@SafeSlot()
|
@SafeSlot()
|
||||||
def stop_scan(self):
|
def stop_scan(
|
||||||
"""Stop the scan."""
|
self,
|
||||||
|
): # , scan_id: str | None = None): #FIXME scan_id will be added when combining with Queue widget
|
||||||
|
"""
|
||||||
|
Stop the scan.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
scan_id(str|None): The scan id to stop. If None, the current scan will be stopped.
|
||||||
|
"""
|
||||||
self.queue.request_scan_halt()
|
self.queue.request_scan_halt()
|
||||||
|
26
tests/unit_tests/test_abort_button.py
Normal file
26
tests/unit_tests/test_abort_button.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from bec_widgets.widgets.button_abort.button_abort import AbortButton
|
||||||
|
|
||||||
|
from .client_mocks import mocked_client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def abort_button(qtbot, mocked_client):
|
||||||
|
widget = AbortButton(client=mocked_client)
|
||||||
|
qtbot.addWidget(widget)
|
||||||
|
qtbot.waitExposed(widget)
|
||||||
|
yield widget
|
||||||
|
|
||||||
|
|
||||||
|
def test_abort_button(abort_button):
|
||||||
|
assert abort_button.button.text() == "Abort"
|
||||||
|
assert (
|
||||||
|
abort_button.button.styleSheet()
|
||||||
|
== "background-color: #666666; color: white; font-weight: bold; font-size: 12px;"
|
||||||
|
)
|
||||||
|
abort_button.button.click()
|
||||||
|
assert abort_button.queue.request_scan_abortion.called
|
||||||
|
abort_button.close()
|
@ -19,7 +19,7 @@ def test_resume_button(resume_button):
|
|||||||
assert resume_button.button.text() == "Resume"
|
assert resume_button.button.text() == "Resume"
|
||||||
assert (
|
assert (
|
||||||
resume_button.button.styleSheet()
|
resume_button.button.styleSheet()
|
||||||
== "background-color: #2793e8 color: white; font-weight: bold; font-size: 12px;"
|
== "background-color: #2793e8; color: white; font-weight: bold; font-size: 12px;"
|
||||||
)
|
)
|
||||||
resume_button.button.click()
|
resume_button.button.click()
|
||||||
assert resume_button.queue.request_scan_continuation.called
|
assert resume_button.queue.request_scan_continuation.called
|
||||||
|
Reference in New Issue
Block a user