From d86bb65520f92061814668cab937df36c2e0bfe5 Mon Sep 17 00:00:00 2001 From: 2xB <2xB@users.noreply.github.com> Date: Sat, 6 Jun 2020 15:52:55 +0200 Subject: [PATCH 1/2] ParameterTree: Fix custom context menu This issue was introduced in merging develop into #1175. While refactoring for the merge, the change in namespace was not correctly attributed, leading to the parameter `opts` to be assumed in local namespace when it isn't. --- pyqtgraph/parametertree/ParameterItem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqtgraph/parametertree/ParameterItem.py b/pyqtgraph/parametertree/ParameterItem.py index ecafd577..ab5fad96 100644 --- a/pyqtgraph/parametertree/ParameterItem.py +++ b/pyqtgraph/parametertree/ParameterItem.py @@ -117,7 +117,7 @@ class ParameterItem(QtGui.QTreeWidgetItem): self.contextMenu.addAction("Remove").triggered.connect(self.requestRemove) # context menu - context = opts.get('context', None) + context = self.param.opts.get('context', None) if isinstance(context, list): for name in context: self.contextMenu.addAction(name).triggered.connect( From 78929adbea2944d661cfdd3981ec582e1ba5fe4f Mon Sep 17 00:00:00 2001 From: 2xB <2xB@users.noreply.github.com> Date: Sat, 6 Jun 2020 16:04:05 +0200 Subject: [PATCH 2/2] ParameterItem: self.param.opts -> opts Using `opts` as alias for `self.param.opts`, following the style of `updateFlags`. --- pyqtgraph/parametertree/ParameterItem.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/parametertree/ParameterItem.py b/pyqtgraph/parametertree/ParameterItem.py index ab5fad96..b697b956 100644 --- a/pyqtgraph/parametertree/ParameterItem.py +++ b/pyqtgraph/parametertree/ParameterItem.py @@ -104,20 +104,22 @@ class ParameterItem(QtGui.QTreeWidgetItem): pass def contextMenuEvent(self, ev): - if not self.param.opts.get('removable', False) and not self.param.opts.get('renamable', False)\ - and "context" not in self.param.opts: + opts = self.param.opts + + if not opts.get('removable', False) and not opts.get('renamable', False)\ + and "context" not in opts: return ## Generate context menu for renaming/removing parameter self.contextMenu = QtGui.QMenu() # Put in global name space to prevent garbage collection self.contextMenu.addSeparator() - if self.param.opts.get('renamable', False): + if opts.get('renamable', False): self.contextMenu.addAction('Rename').triggered.connect(self.editName) - if self.param.opts.get('removable', False): + if opts.get('removable', False): self.contextMenu.addAction("Remove").triggered.connect(self.requestRemove) # context menu - context = self.param.opts.get('context', None) + context = opts.get('context', None) if isinstance(context, list): for name in context: self.contextMenu.addAction(name).triggered.connect(