mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
refactor(stop_button): moved to top layer, plugin added
This commit is contained in:
@ -21,6 +21,7 @@ class Widgets(str, enum.Enum):
|
|||||||
BECStatusBox = "BECStatusBox"
|
BECStatusBox = "BECStatusBox"
|
||||||
RingProgressBar = "RingProgressBar"
|
RingProgressBar = "RingProgressBar"
|
||||||
ScanControl = "ScanControl"
|
ScanControl = "ScanControl"
|
||||||
|
StopButton = "StopButton"
|
||||||
TextBox = "TextBox"
|
TextBox = "TextBox"
|
||||||
VSCodeEditor = "VSCodeEditor"
|
VSCodeEditor = "VSCodeEditor"
|
||||||
WebsiteWidget = "WebsiteWidget"
|
WebsiteWidget = "WebsiteWidget"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from .stop_button.stop_button import StopButton
|
|
@ -12,8 +12,8 @@ from qtpy.QtWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from bec_widgets.utils import BECConnector
|
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.scan_control.scan_group_box import ScanGroupBox
|
||||||
|
from bec_widgets.widgets.stop_button.stop_button import StopButton
|
||||||
|
|
||||||
|
|
||||||
class ScanControl(BECConnector, QWidget):
|
class ScanControl(BECConnector, QWidget):
|
||||||
|
BIN
bec_widgets/widgets/stop_button/assets/stop.png
Normal file
BIN
bec_widgets/widgets/stop_button/assets/stop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
15
bec_widgets/widgets/stop_button/register_stop_button.py
Normal file
15
bec_widgets/widgets/stop_button/register_stop_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.stop_button.stop_button_plugin import StopButtonPlugin
|
||||||
|
|
||||||
|
QPyDesignerCustomWidgetCollection.addCustomWidget(StopButtonPlugin())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": # pragma: no cover
|
||||||
|
main()
|
@ -1,3 +1,4 @@
|
|||||||
|
from qtpy.QtCore import Slot
|
||||||
from qtpy.QtWidgets import QPushButton
|
from qtpy.QtWidgets import QPushButton
|
||||||
|
|
||||||
from bec_widgets.utils import BECConnector
|
from bec_widgets.utils import BECConnector
|
||||||
@ -12,21 +13,13 @@ class StopButton(BECConnector, QPushButton):
|
|||||||
|
|
||||||
self.get_bec_shortcuts()
|
self.get_bec_shortcuts()
|
||||||
self.setText("Stop")
|
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)
|
self.clicked.connect(self.stop_scan)
|
||||||
|
|
||||||
|
@Slot()
|
||||||
def stop_scan(self):
|
def stop_scan(self):
|
||||||
"""Stop the scan."""
|
"""Stop the scan."""
|
||||||
self.queue.request_scan_abortion()
|
self.queue.request_scan_abortion()
|
||||||
self.queue.request_queue_reset()
|
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_())
|
|
1
bec_widgets/widgets/stop_button/stop_button.pyproject
Normal file
1
bec_widgets/widgets/stop_button/stop_button.pyproject
Normal file
@ -0,0 +1 @@
|
|||||||
|
{'files': ['stop_button.py']}
|
57
bec_widgets/widgets/stop_button/stop_button_plugin.py
Normal file
57
bec_widgets/widgets/stop_button/stop_button_plugin.py
Normal 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()
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
import pytest
|
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
|
from .client_mocks import mocked_client
|
||||||
|
|
||||||
|
|
||||||
@ -18,7 +17,10 @@ def stop_button(qtbot, mocked_client):
|
|||||||
|
|
||||||
def test_stop_button(stop_button):
|
def test_stop_button(stop_button):
|
||||||
assert stop_button.text() == "Stop"
|
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()
|
stop_button.click()
|
||||||
assert stop_button.queue.request_scan_abortion.called
|
assert stop_button.queue.request_scan_abortion.called
|
||||||
assert stop_button.queue.request_queue_reset.called
|
assert stop_button.queue.request_queue_reset.called
|
||||||
|
Reference in New Issue
Block a user