mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(resume_button): resume button added
This commit is contained in:
@ -27,6 +27,7 @@ class Widgets(str, enum.Enum):
|
||||
DeviceLineEdit = "DeviceLineEdit"
|
||||
PositionerBox = "PositionerBox"
|
||||
PositionerControlLine = "PositionerControlLine"
|
||||
ResumeButton = "ResumeButton"
|
||||
RingProgressBar = "RingProgressBar"
|
||||
ScanControl = "ScanControl"
|
||||
StopButton = "StopButton"
|
||||
@ -2393,6 +2394,24 @@ class PositionerControlLine(RPCBase):
|
||||
"""
|
||||
|
||||
|
||||
class ResumeButton(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 Ring(RPCBase):
|
||||
@rpc_call
|
||||
def _get_all_rpc(self) -> "dict":
|
||||
|
0
bec_widgets/widgets/button_resume/__init__.py
Normal file
0
bec_widgets/widgets/button_resume/__init__.py
Normal file
42
bec_widgets/widgets/button_resume/button_resume.py
Normal file
42
bec_widgets/widgets/button_resume/button_resume.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 ResumeButton(BECWidget, QWidget):
|
||||
"""A button that continue scan queue."""
|
||||
|
||||
ICON_NAME = "resume"
|
||||
|
||||
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("resume", color="#2793e8", filled=True)
|
||||
self.button = QToolButton(icon=icon)
|
||||
self.button.triggered.connect(self.continue_scan)
|
||||
else:
|
||||
self.button = QPushButton()
|
||||
self.button.setText("Resume")
|
||||
self.button.setStyleSheet(
|
||||
"background-color: #2793e8 color: white; font-weight: bold; font-size: 12px;"
|
||||
)
|
||||
self.button.clicked.connect(self.continue_scan)
|
||||
|
||||
self.layout.addWidget(self.button)
|
||||
|
||||
@SafeSlot()
|
||||
def continue_scan(self):
|
||||
"""Stop the scan."""
|
||||
self.queue.request_scan_continuation()
|
15
bec_widgets/widgets/button_resume/register_resume_button.py
Normal file
15
bec_widgets/widgets/button_resume/register_resume_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_resume.resume_button_plugin import ResumeButtonPlugin
|
||||
|
||||
QPyDesignerCustomWidgetCollection.addCustomWidget(ResumeButtonPlugin())
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
main()
|
@ -0,0 +1 @@
|
||||
{'files': ['button_resume.py']}
|
54
bec_widgets/widgets/button_resume/resume_button_plugin.py
Normal file
54
bec_widgets/widgets/button_resume/resume_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_resume.button_resume import ResumeButton
|
||||
|
||||
DOM_XML = """
|
||||
<ui language='c++'>
|
||||
<widget class='ResumeButton' name='resume_button'>
|
||||
</widget>
|
||||
</ui>
|
||||
"""
|
||||
|
||||
|
||||
class ResumeButtonPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._form_editor = None
|
||||
|
||||
def createWidget(self, parent):
|
||||
t = ResumeButton(parent)
|
||||
return t
|
||||
|
||||
def domXml(self):
|
||||
return DOM_XML
|
||||
|
||||
def group(self):
|
||||
return "BEC Buttons"
|
||||
|
||||
def icon(self):
|
||||
return designer_material_icon(ResumeButton.ICON_NAME)
|
||||
|
||||
def includeFile(self):
|
||||
return "resume_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 "ResumeButton"
|
||||
|
||||
def toolTip(self):
|
||||
return "A button that continue scan queue."
|
||||
|
||||
def whatsThis(self):
|
||||
return self.toolTip()
|
@ -23,9 +23,7 @@ class StopButton(BECWidget, QWidget):
|
||||
self.layout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
if toolbar:
|
||||
icon = material_icon(
|
||||
"stop", size=(20, 20), color="#cc181e", filled=True, convert_to_pixmap=False
|
||||
)
|
||||
icon = material_icon("stop", color="#cc181e", filled=True)
|
||||
self.button = QToolButton(icon=icon)
|
||||
self.button.triggered.connect(self.stop_scan)
|
||||
else:
|
||||
|
@ -31,7 +31,7 @@ class StopButtonPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
||||
return DOM_XML
|
||||
|
||||
def group(self):
|
||||
return "BEC Utils"
|
||||
return "BEC Buttons"
|
||||
|
||||
def icon(self):
|
||||
return designer_material_icon(StopButton.ICON_NAME)
|
||||
|
26
tests/unit_tests/test_resume_button.py
Normal file
26
tests/unit_tests/test_resume_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_resume.button_resume import ResumeButton
|
||||
|
||||
from .client_mocks import mocked_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def resume_button(qtbot, mocked_client):
|
||||
widget = ResumeButton(client=mocked_client)
|
||||
qtbot.addWidget(widget)
|
||||
qtbot.waitExposed(widget)
|
||||
yield widget
|
||||
|
||||
|
||||
def test_resume_button(resume_button):
|
||||
assert resume_button.button.text() == "Resume"
|
||||
assert (
|
||||
resume_button.button.styleSheet()
|
||||
== "background-color: #2793e8 color: white; font-weight: bold; font-size: 12px;"
|
||||
)
|
||||
resume_button.button.click()
|
||||
assert resume_button.queue.request_scan_continuation.called
|
||||
resume_button.close()
|
Reference in New Issue
Block a user