mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(reset_button): reset button added
This commit is contained in:
@ -28,6 +28,7 @@ class Widgets(str, enum.Enum):
|
|||||||
DeviceLineEdit = "DeviceLineEdit"
|
DeviceLineEdit = "DeviceLineEdit"
|
||||||
PositionerBox = "PositionerBox"
|
PositionerBox = "PositionerBox"
|
||||||
PositionerControlLine = "PositionerControlLine"
|
PositionerControlLine = "PositionerControlLine"
|
||||||
|
ResetButton = "ResetButton"
|
||||||
ResumeButton = "ResumeButton"
|
ResumeButton = "ResumeButton"
|
||||||
RingProgressBar = "RingProgressBar"
|
RingProgressBar = "RingProgressBar"
|
||||||
ScanControl = "ScanControl"
|
ScanControl = "ScanControl"
|
||||||
@ -2413,6 +2414,24 @@ class PositionerControlLine(RPCBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ResetButton(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 ResumeButton(RPCBase):
|
class ResumeButton(RPCBase):
|
||||||
@property
|
@property
|
||||||
@rpc_call
|
@rpc_call
|
||||||
|
0
bec_widgets/widgets/button_reset/__init__.py
Normal file
0
bec_widgets/widgets/button_reset/__init__.py
Normal file
42
bec_widgets/widgets/button_reset/button_reset.py
Normal file
42
bec_widgets/widgets/button_reset/button_reset.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
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 ResetButton(BECWidget, QWidget):
|
||||||
|
"""A button that reset 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)
|
||||||
|
self.button = QToolButton(icon=icon)
|
||||||
|
self.button.triggered.connect(self.reset_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.reset_queue)
|
||||||
|
|
||||||
|
self.layout.addWidget(self.button)
|
||||||
|
|
||||||
|
@SafeSlot()
|
||||||
|
def reset_queue(self):
|
||||||
|
"""Stop the scan."""
|
||||||
|
self.queue.request_queue_reset()
|
15
bec_widgets/widgets/button_reset/register_reset_button.py
Normal file
15
bec_widgets/widgets/button_reset/register_reset_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_reset.reset_button_plugin import ResetButtonPlugin
|
||||||
|
|
||||||
|
QPyDesignerCustomWidgetCollection.addCustomWidget(ResetButtonPlugin())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": # pragma: no cover
|
||||||
|
main()
|
1
bec_widgets/widgets/button_reset/reset_button.pyproject
Normal file
1
bec_widgets/widgets/button_reset/reset_button.pyproject
Normal file
@ -0,0 +1 @@
|
|||||||
|
{'files': ['button_reset.py']}
|
54
bec_widgets/widgets/button_reset/reset_button_plugin.py
Normal file
54
bec_widgets/widgets/button_reset/reset_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_reset.button_reset import ResetButton
|
||||||
|
|
||||||
|
DOM_XML = """
|
||||||
|
<ui language='c++'>
|
||||||
|
<widget class='ResetButton' name='reset_button'>
|
||||||
|
</widget>
|
||||||
|
</ui>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ResetButtonPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self._form_editor = None
|
||||||
|
|
||||||
|
def createWidget(self, parent):
|
||||||
|
t = ResetButton(parent)
|
||||||
|
return t
|
||||||
|
|
||||||
|
def domXml(self):
|
||||||
|
return DOM_XML
|
||||||
|
|
||||||
|
def group(self):
|
||||||
|
return "BEC Buttons"
|
||||||
|
|
||||||
|
def icon(self):
|
||||||
|
return designer_material_icon(ResetButton.ICON_NAME)
|
||||||
|
|
||||||
|
def includeFile(self):
|
||||||
|
return "reset_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 "ResetButton"
|
||||||
|
|
||||||
|
def toolTip(self):
|
||||||
|
return "A button that reset the scan queue."
|
||||||
|
|
||||||
|
def whatsThis(self):
|
||||||
|
return self.toolTip()
|
26
tests/unit_tests/test_reset_button.py
Normal file
26
tests/unit_tests/test_reset_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_reset.button_reset import ResetButton
|
||||||
|
|
||||||
|
from .client_mocks import mocked_client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def reset_button(qtbot, mocked_client):
|
||||||
|
widget = ResetButton(client=mocked_client)
|
||||||
|
qtbot.addWidget(widget)
|
||||||
|
qtbot.waitExposed(widget)
|
||||||
|
yield widget
|
||||||
|
|
||||||
|
|
||||||
|
def test_stop_button(reset_button):
|
||||||
|
assert reset_button.button.text() == "Reset Queue"
|
||||||
|
assert (
|
||||||
|
reset_button.button.styleSheet()
|
||||||
|
== "background-color: #F19E39; color: white; font-weight: bold; font-size: 12px;"
|
||||||
|
)
|
||||||
|
reset_button.button.click()
|
||||||
|
assert reset_button.queue.request_queue_reset.called
|
||||||
|
reset_button.close()
|
Reference in New Issue
Block a user