def onExportToPackage(self): # check if category is not empty if self._rawNode._rawGraph.category == '': QMessageBox.information( None, "Warning", "Category is not set! Please step into compound and type category name." ) return packageNames = list(GET_PACKAGES().keys()) selectedPackageName, accepted = QInputDialog.getItem(None, "Select", "Select package", packageNames, editable=False) if accepted: packagePath = GET_PACKAGE_PATH(selectedPackageName) compoundsDir = os.path.join(packagePath, "Compounds") if not os.path.isdir(compoundsDir): os.mkdir(compoundsDir) self.onExport(root=compoundsDir) # refresh node box app = self.canvasRef().getApp() nodeBoxes = app.getRegisteredTools( classNameFilters=["NodeBoxTool"]) for nodeBox in nodeBoxes: nodeBox.refresh()
def onExportToPackage(self): packageNames = list(GET_PACKAGES().keys()) selectedPackageName, accepted = QInputDialog.getItem(None, "Select", "Select package", packageNames, editable=False) if accepted: packagePath = GET_PACKAGE_PATH(selectedPackageName) pyNodesDir = os.path.join(packagePath, "PyNodes") if not os.path.isdir(pyNodesDir): os.mkdir(pyNodesDir) self.onExport(root=pyNodesDir) # refresh node boxes app = self.canvasRef().getApp() nodeBoxes = app.getRegisteredTools(classNameFilters=["NodeBoxTool"]) for nodeBox in nodeBoxes: nodeBox.refresh()
def refresh(self, pattern='', pinDirection=None, pinStructure=PinStructure.Single): self.clear() self.categoryPaths = {} dataType = None if self.canvas.pressedPin is not None: dataType = self.canvas.pressedPin.dataType for package_name, package in GET_PACKAGES().items(): # annotated functions for libName, lib in package.GetFunctionLibraries().items(): foos = lib.getFunctions() for name, foo in foos.items(): foo = foo libName = foo.__annotations__["lib"] fooArgNames = getargspec(foo).args fooInpTypes = set() fooOutTypes = set() fooInpStructs = set() fooOutStructs = set() if foo.__annotations__['nodeType'] == NodeTypes.Callable: fooInpTypes.add('ExecPin') fooOutTypes.add('ExecPin') fooInpStructs.add(PinStructure.Single) fooOutStructs.add(PinStructure.Single) # consider return type if not None if foo.__annotations__['return'] is not None: fooOutTypes.add(foo.__annotations__['return'][0]) fooOutStructs.add( findStructFromValue( foo.__annotations__['return'][1])) for index in range(len(fooArgNames)): dType = foo.__annotations__[fooArgNames[index]] # if tuple - this means ref pin type (output) + default value # eg: (3, True) - bool with True default val fooInpTypes.add(dType[0]) fooInpStructs.add(findStructFromValue(dType[1])) nodeCategoryPath = "{0}|{1}".format( package_name, foo.__annotations__['meta']['Category']) keywords = foo.__annotations__['meta']['Keywords'] checkString = name + nodeCategoryPath + ''.join(keywords) if pattern.lower() in checkString.lower(): # create all nodes items if clicked on canvas if dataType is None: self.suggestionsEnabled = False self.insertNode(nodeCategoryPath, name, foo.__doc__, libName) else: self.suggestionsEnabled = True if pinDirection == PinDirection.Output: if pinStructure != PinStructure.Multi: hasMultiPins = PinStructure.Multi in fooInpStructs if dataType in fooInpTypes and ( pinStructure in fooInpStructs or hasMultiPins): self.insertNode( nodeCategoryPath, name, foo.__doc__, libName) elif dataType in fooInpTypes: self.insertNode(nodeCategoryPath, name, foo.__doc__, libName) else: if pinStructure != PinStructure.Multi: hasMultiPins = PinStructure.Multi in fooOutStructs if dataType in fooOutTypes and ( pinStructure in fooOutStructs or hasMultiPins): self.insertNode( nodeCategoryPath, name, foo.__doc__, libName) elif dataType in fooOutTypes: self.insertNode(nodeCategoryPath, name, foo.__doc__, libName) # class based nodes for node_class in package.GetNodeClasses().values(): if node_class.__name__ in ('setVar', 'getVar'): continue nodeCategoryPath = "{0}|{1}".format(package_name, node_class.category()) checkString = node_class.__name__ + nodeCategoryPath + ''.join( node_class.keywords()) if pattern.lower() not in checkString.lower(): continue if dataType is None: self.insertNode(nodeCategoryPath, node_class.__name__, node_class.description()) else: # if pressed pin is output pin # filter by nodes input types hints = node_class.pinTypeHints() if pinDirection == PinDirection.Output: if pinStructure != PinStructure.Multi: hasMultiPins = PinStructure.Multi in hints.inputStructs if dataType in hints.inputTypes and ( pinStructure in hints.inputStructs or hasMultiPins): self.insertNode(nodeCategoryPath, node_class.__name__, node_class.description()) elif dataType in hints.inputTypes: self.insertNode(nodeCategoryPath, node_class.__name__, node_class.description()) else: # if pressed pin is input pin # filter by nodes output types if pinStructure != PinStructure.Multi: hasMultiPins = PinStructure.Multi in hints.outputStructs if dataType in hints.outputTypes and ( pinStructure in hints.outputStructs or hasMultiPins): self.insertNode(nodeCategoryPath, node_class.__name__, node_class.description()) elif dataType in hints.outputTypes: self.insertNode(nodeCategoryPath, node_class.__name__, node_class.description()) # populate exported py nodes packagePath = GET_PACKAGE_PATH(package_name) pyNodesRoot = os.path.join(packagePath, "PyNodes") if os.path.exists(pyNodesRoot): for path, dirs, files in os.walk(pyNodesRoot): for f in files: pyNodeName, extension = os.path.splitext(f) if extension == ".pynode": p = os.path.normpath(path) folders = p.split(os.sep) index = folders.index("PyNodes") categorySuffix = '|'.join(folders[index:]) category = "{0}|{1}".format( package_name, categorySuffix) self.insertNode(category, pyNodeName, bPyNode=True) # populate exported compounds compoundNodesRoot = os.path.join(packagePath, "Compounds") if os.path.exists(compoundNodesRoot): for path, dirs, files in os.walk(compoundNodesRoot): for f in files: _, extension = os.path.splitext(f) if extension == ".compound": compoundsRoot = os.path.normpath(path) fullCompoundPath = os.path.join(compoundsRoot, f) with open(fullCompoundPath, 'r') as compoundFile: data = json.load(compoundFile) compoundCategoryName = data["category"] compoundNodeName = data["name"] category = "{0}|{1}|{2}".format( package_name, "Compounds", compoundCategoryName) self.insertNode(category, compoundNodeName, bCompoundNode=True) # expand all categories if dataType is not None: for categoryItem in self.categoryPaths.values(): categoryItem.setExpanded(True) self.sortItems(0, QtCore.Qt.AscendingOrder)