[core] add optional 'name' argument to addNewNode method

allow to create a new node with a target name, that will get prefixed if not unique
This commit is contained in:
Yann Lanthony 2017-12-19 14:59:12 +01:00
parent 474e18ef4c
commit d2417e4ac6

View file

@ -1128,16 +1128,21 @@ class Graph(BaseObject):
return inEdges, outEdges return inEdges, outEdges
@Slot(str, result=Node) def addNewNode(self, nodeDesc, name=None, **kwargs):
def addNewNode(self, nodeType, **kwargs):
""" """
Create and add a new node to the graph.
:param nodeType: Args:
:param kwargs: nodeDesc (desc.Node): the node description to use.
:return: name (str): if specified, the desired name for this node. If not unique, will be prefixed (_N).
:rtype: Node **kwargs: keyword arguments to initialize node's attributes
Returns:
The newly created node.
""" """
n = self.addNode(Node(nodeDesc=nodeType, **kwargs)) if name and name in self._nodes.keys():
name = self._createUniqueNodeName(name)
n = self.addNode(Node(nodeDesc=nodeDesc, **kwargs), uniqueName=name)
n.updateInternals() n.updateInternals()
return n return n