mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-19 20:16:30 +02:00
[ui] return command result after pushing it to the undo stack
this allows to directly retrieve, for instance, the node created by UIGraph.addNode method
This commit is contained in:
parent
22c54bd1c5
commit
4ea793be74
2 changed files with 19 additions and 8 deletions
|
@ -57,7 +57,7 @@ class UndoStack(QUndoStack):
|
|||
except Exception as e:
|
||||
logging.error("Error while trying command '{}': \n{}".format(command.text(), traceback.format_exc()))
|
||||
res = False
|
||||
if res:
|
||||
if res is not False:
|
||||
command.setEnabled(False)
|
||||
self.push(command) # takes ownership
|
||||
command.setEnabled(True)
|
||||
|
@ -84,15 +84,17 @@ class GraphCommand(UndoCommand):
|
|||
|
||||
|
||||
class AddNodeCommand(GraphCommand):
|
||||
def __init__(self, graph, nodeType, parent=None):
|
||||
def __init__(self, graph, nodeType, parent=None, **kwargs):
|
||||
super(AddNodeCommand, self).__init__(graph, parent)
|
||||
self.nodeType = nodeType
|
||||
self.nodeName = None
|
||||
self.kwargs = kwargs
|
||||
|
||||
def redoImpl(self):
|
||||
self.nodeName = self.graph.addNewNode(self.nodeType).name
|
||||
node = self.graph.addNewNode(self.nodeType, **self.kwargs)
|
||||
self.nodeName = node.name
|
||||
self.setText("Add Node {}".format(self.nodeName))
|
||||
return True
|
||||
return node
|
||||
|
||||
def undoImpl(self):
|
||||
self.graph.removeNode(self.nodeName)
|
||||
|
|
|
@ -210,7 +210,7 @@ class UIGraph(QObject):
|
|||
Args:
|
||||
command (commands.UndoCommand): the command to push
|
||||
"""
|
||||
self._undoStack.tryAndPush(command)
|
||||
return self._undoStack.tryAndPush(command)
|
||||
|
||||
def groupedGraphModification(self, title):
|
||||
""" Get a GroupedGraphModification for this Reconstruction.
|
||||
|
@ -223,9 +223,18 @@ class UIGraph(QObject):
|
|||
"""
|
||||
return commands.GroupedGraphModification(self._graph, self._undoStack, title)
|
||||
|
||||
@Slot(str)
|
||||
def addNode(self, nodeType):
|
||||
self.push(commands.AddNodeCommand(self._graph, nodeType))
|
||||
@Slot(str, result=QObject)
|
||||
def addNode(self, nodeType, **kwargs):
|
||||
""" [Undoable]
|
||||
Create a new Node of type 'nodeType' and returns it.
|
||||
|
||||
Args:
|
||||
nodeType (str): the type of the Node to create.
|
||||
**kwargs: optional node attributes values
|
||||
Returns:
|
||||
Node: the created node
|
||||
"""
|
||||
return self.push(commands.AddNodeCommand(self._graph, nodeType, **kwargs))
|
||||
|
||||
@Slot(graph.Node)
|
||||
def removeNode(self, node):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue