mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 11:11:49 +02:00
feat(signal_proxy): added signal proxy for designer
This commit is contained in:
@ -0,0 +1 @@
|
||||
{'files': ['signal_proxy.py']}
|
@ -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.designer_signal_proxy.signal_proxy import DesignerSignalProxy
|
||||
|
||||
DOM_XML = """
|
||||
<ui language='c++'>
|
||||
<widget class='DesignerSignalProxy' name='designer_signal_proxy'>
|
||||
</widget>
|
||||
</ui>
|
||||
"""
|
||||
|
||||
|
||||
class DesignerSignalProxyPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._form_editor = None
|
||||
|
||||
def createWidget(self, parent):
|
||||
t = DesignerSignalProxy(parent)
|
||||
return t
|
||||
|
||||
def domXml(self):
|
||||
return DOM_XML
|
||||
|
||||
def group(self):
|
||||
return ""
|
||||
|
||||
def icon(self):
|
||||
return designer_material_icon(DesignerSignalProxy.ICON_NAME)
|
||||
|
||||
def includeFile(self):
|
||||
return "designer_signal_proxy"
|
||||
|
||||
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 "DesignerSignalProxy"
|
||||
|
||||
def toolTip(self):
|
||||
return "DesignerSignalProxy"
|
||||
|
||||
def whatsThis(self):
|
||||
return self.toolTip()
|
@ -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.designer_signal_proxy.designer_signal_proxy_plugin import DesignerSignalProxyPlugin
|
||||
|
||||
QPyDesignerCustomWidgetCollection.addCustomWidget(DesignerSignalProxyPlugin())
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
main()
|
56
bec_widgets/widgets/designer_signal_proxy/signal_proxy.py
Normal file
56
bec_widgets/widgets/designer_signal_proxy/signal_proxy.py
Normal file
@ -0,0 +1,56 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from qtpy.QtCore import Signal, Slot
|
||||
from qtpy.QtWidgets import QWidget
|
||||
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
|
||||
|
||||
class DesignerSignalProxy(BECWidget, QWidget):
|
||||
output = Signal((str,), (int,), (float,), (bool,), (list,), (dict,), (object,), (type(None),))
|
||||
|
||||
def __init__(self, parent=None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
QWidget.__init__(self, parent)
|
||||
|
||||
self.storage = defaultdict()
|
||||
self.input_objects = ["BECWaveformWidget", "DeviceComboBox"]
|
||||
|
||||
@Slot()
|
||||
@Slot(str)
|
||||
@Slot(int)
|
||||
@Slot(float)
|
||||
@Slot(bool)
|
||||
@Slot(list)
|
||||
@Slot(dict)
|
||||
@Slot(object)
|
||||
@Slot(type(None))
|
||||
def input(self, *args):
|
||||
sender_name = self.sender().__class__.__name__
|
||||
print(f"Input signal received from {sender_name}: {args}")
|
||||
self.storage[sender_name] = args
|
||||
self._check_for_all_signals()
|
||||
|
||||
def _check_for_all_signals(self):
|
||||
for obj in self.input_objects:
|
||||
if obj not in self.storage:
|
||||
return
|
||||
out = self._perform_aggregation()
|
||||
print(f"Output signal emitted: {out}")
|
||||
self.output.emit([self.storage[obj] for obj in self.input_objects])
|
||||
|
||||
self.storage.clear()
|
||||
|
||||
def _perform_aggregation(self):
|
||||
return [self.storage[obj] for obj in self.input_objects]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
widget = DesignerSignalProxy()
|
||||
widget.show()
|
||||
sys.exit(app.exec_())
|
Reference in New Issue
Block a user