1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
import warnings
from ...Qt import QtCore
from .action import ParameterControlledButton
from .basetypes import GroupParameter, GroupParameterItem
from ..ParameterItem import ParameterItem
from ...Qt import QtCore, QtWidgets
class ActionGroupParameterItem(GroupParameterItem):
"""
Wraps a :class:`GroupParameterItem` to manage function parameters created by
an interactor. Provies a button widget which mimics an ``action`` parameter.
"""
def __init__(self, param, depth):
self.itemWidget = QtWidgets.QWidget()
self.button = ParameterControlledButton(parent=self.itemWidget)
self.button.clicked.connect(param.activate)
self.itemWidget.setLayout(layout := QtWidgets.QHBoxLayout())
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.button)
super().__init__(param, depth)
def treeWidgetChanged(self):
ParameterItem.treeWidgetChanged(self)
tw = self.treeWidget()
if tw is None:
return
tw.setItemWidget(self, 1, self.itemWidget)
def optsChanged(self, param, opts):
if "button" in opts:
buttonOpts = opts["button"] or dict(visible=False)
self.button.updateOpts(param, buttonOpts)
super().optsChanged(param, opts)
class ActionGroupParameter(GroupParameter):
itemClass = ActionGroupParameterItem
sigActivated = QtCore.Signal(object)
def __init__(self, **opts):
opts.setdefault("button", {})
super().__init__(**opts)
def activate(self):
self.sigActivated.emit(self)
self.emitStateChanged('activated', None)
def setButtonOpts(self, **opts):
"""
Update individual button options without replacing the entire
button definition.
"""
buttonOpts = self.opts.get("button", {}).copy()
buttonOpts.update(opts)
self.setOpts(button=buttonOpts)
class ActionGroup(ActionGroupParameter):
sigActivated = QtCore.Signal()
def __init__(self, **opts):
warnings.warn(
"`ActionGroup` is deprecated and will be removed in the first release after "
"January 2023. Use `ActionGroupParameter` instead. See "
"https://github.com/pyqtgraph/pyqtgraph/pull/2505 for details.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(**opts)
def activate(self):
self.sigActivated.emit()
|