From 309133042019244b7f3e4baec1c2b4e3a3c4820d Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Tue, 21 Oct 2014 14:37:06 -0700 Subject: [PATCH 1/3] Add recursive submenu support for node library. --- pyqtgraph/flowchart/Flowchart.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pyqtgraph/flowchart/Flowchart.py b/pyqtgraph/flowchart/Flowchart.py index 878f86ae..7b8cda33 100644 --- a/pyqtgraph/flowchart/Flowchart.py +++ b/pyqtgraph/flowchart/Flowchart.py @@ -823,16 +823,20 @@ class FlowchartWidget(dockarea.DockArea): self.buildMenu() def buildMenu(self, pos=None): + def buildSubMenu(node, rootMenu, subMenus, pos=None): + for section, node in node.items(): + menu = QtGui.QMenu(section) + rootMenu.addMenu(menu) + if isinstance(node, OrderedDict): + buildSubMenu(node, menu, subMenus, pos=pos) + subMenus.append(menu) + else: + act = rootMenu.addAction(section) + act.nodeType = section + act.pos = pos self.nodeMenu = QtGui.QMenu() - self.subMenus = [] - for section, nodes in self.chart.library.getNodeTree().items(): - menu = QtGui.QMenu(section) - self.nodeMenu.addMenu(menu) - for name in nodes: - act = menu.addAction(name) - act.nodeType = name - act.pos = pos - self.subMenus.append(menu) + self.subMenus = [] + buildSubMenu(library.getNodeTree(), self.nodeMenu, self.subMenus, pos=pos) self.nodeMenu.triggered.connect(self.nodeMenuTriggered) return self.nodeMenu From 2ac343ac37de1355d9834566e409d5013009a3f4 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Mon, 27 Oct 2014 18:06:31 -0700 Subject: [PATCH 2/3] fixed missing namespace. --- pyqtgraph/flowchart/Flowchart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqtgraph/flowchart/Flowchart.py b/pyqtgraph/flowchart/Flowchart.py index 7b8cda33..ab5f4a82 100644 --- a/pyqtgraph/flowchart/Flowchart.py +++ b/pyqtgraph/flowchart/Flowchart.py @@ -836,7 +836,7 @@ class FlowchartWidget(dockarea.DockArea): act.pos = pos self.nodeMenu = QtGui.QMenu() self.subMenus = [] - buildSubMenu(library.getNodeTree(), self.nodeMenu, self.subMenus, pos=pos) + buildSubMenu(self.chart.library.getNodeTree(), self.nodeMenu, self.subMenus, pos=pos) self.nodeMenu.triggered.connect(self.nodeMenuTriggered) return self.nodeMenu From 85d6c86c677998aa10d642e4d505c147a954529c Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Fri, 14 Nov 2014 08:06:18 -0500 Subject: [PATCH 3/3] Test submenu creation in example --- examples/FlowchartCustomNode.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/FlowchartCustomNode.py b/examples/FlowchartCustomNode.py index 54c56622..1cf1ba10 100644 --- a/examples/FlowchartCustomNode.py +++ b/examples/FlowchartCustomNode.py @@ -127,7 +127,10 @@ class UnsharpMaskNode(CtrlNode): ## NodeLibrary: library = fclib.LIBRARY.copy() # start with the default node set library.addNodeType(ImageViewNode, [('Display',)]) -library.addNodeType(UnsharpMaskNode, [('Image',)]) +# Add the unsharp mask node to two locations in the menu to demonstrate +# that we can create arbitrary menu structures +library.addNodeType(UnsharpMaskNode, [('Image',), + ('Submenu_test','submenu2','submenu3')]) fc.setLibrary(library)