[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:
Yann Lanthony 2018-01-10 14:12:48 +01:00
parent 22c54bd1c5
commit 4ea793be74
2 changed files with 19 additions and 8 deletions

View file

@ -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)