diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 9b02d0a2..a123a3a7 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -21,6 +21,7 @@ class Widgets(str, enum.Enum): BECStatusBox = "BECStatusBox" RingProgressBar = "RingProgressBar" ScanControl = "ScanControl" + StopButton = "StopButton" TextBox = "TextBox" VSCodeEditor = "VSCodeEditor" WebsiteWidget = "WebsiteWidget" diff --git a/bec_widgets/widgets/buttons/__init__.py b/bec_widgets/widgets/buttons/__init__.py deleted file mode 100644 index 3d77c605..00000000 --- a/bec_widgets/widgets/buttons/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .stop_button.stop_button import StopButton diff --git a/bec_widgets/widgets/scan_control/scan_control.py b/bec_widgets/widgets/scan_control/scan_control.py index 514d10c7..a66ea421 100644 --- a/bec_widgets/widgets/scan_control/scan_control.py +++ b/bec_widgets/widgets/scan_control/scan_control.py @@ -12,8 +12,8 @@ from qtpy.QtWidgets import ( ) from bec_widgets.utils import BECConnector -from bec_widgets.widgets.buttons.stop_button.stop_button import StopButton from bec_widgets.widgets.scan_control.scan_group_box import ScanGroupBox +from bec_widgets.widgets.stop_button.stop_button import StopButton class ScanControl(BECConnector, QWidget): diff --git a/bec_widgets/widgets/buttons/stop_button/__init__.py b/bec_widgets/widgets/stop_button/__init__.py similarity index 100% rename from bec_widgets/widgets/buttons/stop_button/__init__.py rename to bec_widgets/widgets/stop_button/__init__.py diff --git a/bec_widgets/widgets/stop_button/assets/stop.png b/bec_widgets/widgets/stop_button/assets/stop.png new file mode 100644 index 00000000..a6392d1a Binary files /dev/null and b/bec_widgets/widgets/stop_button/assets/stop.png differ diff --git a/bec_widgets/widgets/stop_button/register_stop_button.py b/bec_widgets/widgets/stop_button/register_stop_button.py new file mode 100644 index 00000000..5f1e8235 --- /dev/null +++ b/bec_widgets/widgets/stop_button/register_stop_button.py @@ -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.stop_button.stop_button_plugin import StopButtonPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(StopButtonPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/bec_widgets/widgets/buttons/stop_button/stop_button.py b/bec_widgets/widgets/stop_button/stop_button.py similarity index 68% rename from bec_widgets/widgets/buttons/stop_button/stop_button.py rename to bec_widgets/widgets/stop_button/stop_button.py index 9805fa0a..0f617a43 100644 --- a/bec_widgets/widgets/buttons/stop_button/stop_button.py +++ b/bec_widgets/widgets/stop_button/stop_button.py @@ -1,3 +1,4 @@ +from qtpy.QtCore import Slot from qtpy.QtWidgets import QPushButton from bec_widgets.utils import BECConnector @@ -12,21 +13,13 @@ class StopButton(BECConnector, QPushButton): self.get_bec_shortcuts() self.setText("Stop") - self.setStyleSheet("background-color: #cc181e; color: white") + self.setStyleSheet( + "background-color: #cc181e; color: white; font-weight: bold; font-size: 12px;" + ) self.clicked.connect(self.stop_scan) + @Slot() 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_()) diff --git a/bec_widgets/widgets/stop_button/stop_button.pyproject b/bec_widgets/widgets/stop_button/stop_button.pyproject new file mode 100644 index 00000000..01536add --- /dev/null +++ b/bec_widgets/widgets/stop_button/stop_button.pyproject @@ -0,0 +1 @@ +{'files': ['stop_button.py']} \ No newline at end of file diff --git a/bec_widgets/widgets/stop_button/stop_button_plugin.py b/bec_widgets/widgets/stop_button/stop_button_plugin.py new file mode 100644 index 00000000..8148ef15 --- /dev/null +++ b/bec_widgets/widgets/stop_button/stop_button_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import os + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtGui import QIcon + +from bec_widgets.widgets.stop_button.stop_button import StopButton + +DOM_XML = """ + + + + +""" + + +class StopButtonPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + t = StopButton(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "BEC Buttons" + + def icon(self): + current_path = os.path.dirname(__file__) + icon_path = os.path.join(current_path, "assets", "stop.png") + return QIcon(icon_path) + + def includeFile(self): + return "stop_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 "StopButton" + + def toolTip(self): + return "A button that stops the current scan." + + def whatsThis(self): + return self.toolTip() diff --git a/tests/unit_tests/test_stop_button.py b/tests/unit_tests/test_stop_button.py index c57c60d5..cd9e57b6 100644 --- a/tests/unit_tests/test_stop_button.py +++ b/tests/unit_tests/test_stop_button.py @@ -2,8 +2,7 @@ import pytest -from bec_widgets.widgets.buttons import StopButton - +from bec_widgets.widgets.stop_button.stop_button import StopButton from .client_mocks import mocked_client @@ -18,7 +17,10 @@ def stop_button(qtbot, mocked_client): def test_stop_button(stop_button): assert stop_button.text() == "Stop" - assert stop_button.styleSheet() == "background-color: #cc181e; color: white" + assert ( + stop_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