Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions pyqtgraph/parametertree/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,43 @@ def __init__(self, **opts):
syncExpanded If True, the `expanded` state of this Parameter is
synchronized with all ParameterTrees it is displayed in.
(default=False)
title (str or None) If specified, then the parameter will be
displayed to the user using this string as its name.
However, the parameter will still be referred to
title (str or None) If specified, then the parameter will be
displayed to the user using this string as its name.
However, the parameter will still be referred to
internally using the *name* specified above. Note that
this option is not compatible with renamable=True.
(default=None; added in version 0.9.9)
context Specifies items for a context menu shown on right-click
and inside the ctrl button menu. Accepts a dict, list,
or tuple; nested structures produce submenus. See
:func:`~pyqtgraph.parametertree.ParameterItem.build_menu_from_iterable`
for the accepted format. Clicking an item emits
sigContextMenu with the full path tuple to that item.
(default=None)
ctrlActions A set of strings controlling which built-in actions
appear in the ctrl button menu (the gear icon shown by
widget-based parameter types). Valid values:
``'default'`` (Reset to default), ``'setDefault'``
(Set as default), ``'enabled'`` (Enable/Disable
toggle), ``'readonly'`` (Lock/Unlock toggle),
``'rename'``, ``'remove'``. Including ``'rename'`` or
``'remove'`` here is equivalent to setting
``renamable=True`` / ``removable=True``.
(default: {'default', 'setDefault', 'enabled',
'readonly'})
icon An icon to display next to the parameter name in a
ParameterTree. Accepts a QIcon instance, a file path
string, or a QIcon.StandardPixmap value. Pass None to
remove the icon. See also :meth:`setIcon`.
(default=None)
showCtrlButton If False, the ctrl button (gear icon) will be hidden
for widget-based parameter types. The button can be
shown again later via ``setOpts(showCtrlButton=True)``.
(default=True)
movable If True, the parameter item can be dragged within a
ParameterTree (sets ItemIsDragEnabled). (default=False)
dropEnabled If True, the parameter item accepts drops from other
items (sets ItemIsDropEnabled). (default=False)
======================= =========================================================
"""
super().__init__()
Expand Down
13 changes: 11 additions & 2 deletions pyqtgraph/parametertree/ParameterItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ def populateCtrlMenu(self):
self.ctrlMenu.addSeparator()
self._buildParamMenu(self.ctrlMenu, show_rename, show_remove)

def updateDefaultBtn(self):
def updateCtrlButton(self):
"""Refresh the ctrl button menu to reflect current parameter state.

Called automatically on value and opts changes. Override in a subclass
to add custom refresh logic; call ``super().updateDefaultBtn()`` to
to add custom refresh logic; call ``super().updateCtrlButton()`` to
retain the built-in menu refresh.

When the menu is currently visible (e.g. a persistent action was just
Expand All @@ -414,6 +414,15 @@ def updateDefaultBtn(self):
if hasattr(self, 'ctrlMenu') and not self.ctrlMenu.isVisible():
self.populateCtrlMenu()

def updateDefaultBtn(self):
"""Deprecated. Use :meth:`updateCtrlButton` instead."""
warnings.warn(
"updateDefaultBtn is deprecated; use updateCtrlButton instead.",
DeprecationWarning,
stacklevel=2,
)
self.updateCtrlButton()

def defaultClicked(self):
self.param.setToDefault()

Expand Down
15 changes: 10 additions & 5 deletions pyqtgraph/parametertree/parameterTypes/basetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, param, depth):
self.addChild(self.subItem)

self.ctrlBtn = self.makeCtrlButton()
if not param.opts.get('showCtrlButton', True):
self.ctrlBtn.hide()

self.displayLabel = QtWidgets.QLabel()

Expand Down Expand Up @@ -65,7 +67,7 @@ def __init__(self, param, depth):
## no starting value was given; use whatever the widget has
self.widgetValueChanged()

self.updateDefaultBtn()
self.updateCtrlButton()

self.optsChanged(self.param, self.param.opts)

Expand Down Expand Up @@ -136,7 +138,7 @@ def valueChanged(self, param, val, force=False):
self.widget.sigChanged.connect(self.widgetValueChanged)
self.param.sigValueChanged.connect(self.valueChanged)
self.updateDisplayLabel() ## always make sure label is updated, even if values match!
self.updateDefaultBtn()
self.updateCtrlButton()

def updateDisplayLabel(self, value=None):
"""Update the display label to reflect the value of the parameter."""
Expand Down Expand Up @@ -181,7 +183,7 @@ def limitsChanged(self, param, limits):
ParameterItem.limitsChanged(self, param, limits)

def defaultChanged(self, param, value):
self.updateDefaultBtn()
self.updateCtrlButton()

def treeWidgetChanged(self):
"""Called when this item is added or removed from a tree."""
Expand All @@ -205,11 +207,11 @@ def optsChanged(self, param, opts):
ParameterItem.optsChanged(self, param, opts)

if 'enabled' in opts:
self.updateDefaultBtn()
self.updateCtrlButton()
self.widget.setEnabled(opts['enabled'])

if 'readonly' in opts:
self.updateDefaultBtn()
self.updateCtrlButton()

if opts['readonly']:
self.displayLabel.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.TextSelectableByMouse)
Expand All @@ -221,6 +223,9 @@ def optsChanged(self, param, opts):
else:
self.widget.setEnabled(self.param.opts['enabled'] and not opts['readonly'])

if 'showCtrlButton' in opts:
self.ctrlBtn.setVisible(opts['showCtrlButton'])

if 'tip' in opts:
self.widget.setToolTip(opts['tip'])

Expand Down
4 changes: 2 additions & 2 deletions pyqtgraph/parametertree/parameterTypes/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def optsChanged(self, param, opts):
self.btnGrp.setExclusive(exclusive)
# "Limits" will force update anyway, no need to duplicate if it's present
if 'limits' not in opts and ('enabled' in opts or 'readonly' in opts):
self.updateDefaultBtn()
self.updateCtrlButton()

def expandedChangedEvent(self, expanded):
for btn in self.metaBtns.values():
btn.setVisible(expanded)

def valueChanged(self, param, val):
self.updateDefaultBtn()
self.updateCtrlButton()


class RadioParameterItem(BoolParameterItem):
Expand Down
4 changes: 2 additions & 2 deletions pyqtgraph/parametertree/parameterTypes/pen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, param, depth):

def optsChanged(self, param, opts):
if "enabled" in opts or "readonly" in opts:
self.updateDefaultBtn()
self.updateCtrlButton()

def treeWidgetChanged(self):
ParameterItem.treeWidgetChanged(self)
Expand All @@ -36,7 +36,7 @@ def treeWidgetChanged(self):
tw.setItemWidget(self, 1, self.itemWidget)

def valueChanged(self, param, val):
self.updateDefaultBtn()
self.updateCtrlButton()


def cap_first(s: str):
Expand Down
Loading