0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

refactor(stop_button): moved to top layer, plugin added

This commit is contained in:
2024-07-06 20:48:15 +02:00
parent db1cdf4280
commit f5b8375fd3
10 changed files with 85 additions and 17 deletions

View File

@ -21,6 +21,7 @@ class Widgets(str, enum.Enum):
BECStatusBox = "BECStatusBox"
RingProgressBar = "RingProgressBar"
ScanControl = "ScanControl"
StopButton = "StopButton"
TextBox = "TextBox"
VSCodeEditor = "VSCodeEditor"
WebsiteWidget = "WebsiteWidget"

View File

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

View File

@ -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):

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View 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.stop_button.stop_button_plugin import StopButtonPlugin
QPyDesignerCustomWidgetCollection.addCustomWidget(StopButtonPlugin())
if __name__ == "__main__": # pragma: no cover
main()

View File

@ -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_())

View File

@ -0,0 +1 @@
{'files': ['stop_button.py']}

View File

@ -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 = """
<ui language='c++'>
<widget class='StopButton' name='stop_button'>
</widget>
</ui>
"""
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()

View File

@ -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