mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-25 15:06:38 +02:00
[commands] add higher-level error catching on undo/redo
This commit is contained in:
parent
5d549e9155
commit
8b2224609c
1 changed files with 18 additions and 11 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
import traceback
|
||||||
from PySide2.QtWidgets import QUndoCommand, QUndoStack
|
from PySide2.QtWidgets import QUndoCommand, QUndoStack
|
||||||
from PySide2.QtCore import Property, Signal
|
from PySide2.QtCore import Property, Signal
|
||||||
from meshroom.core.graph import Node, ListAttribute
|
from meshroom.core.graph import Node, ListAttribute
|
||||||
|
@ -14,12 +16,18 @@ class UndoCommand(QUndoCommand):
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
return
|
return
|
||||||
self.redoImpl()
|
try:
|
||||||
|
self.redoImpl()
|
||||||
|
except Exception:
|
||||||
|
logging.error("Error while redoing command '{}': \n{}".format(self.text(), traceback.format_exc()))
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
return
|
return
|
||||||
self.undoImpl()
|
try:
|
||||||
|
self.undoImpl()
|
||||||
|
except Exception:
|
||||||
|
logging.error("Error while undoing command '{}': \n{}".format(self.text(), traceback.format_exc()))
|
||||||
|
|
||||||
def redoImpl(self):
|
def redoImpl(self):
|
||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
|
@ -42,13 +50,16 @@ class UndoStack(QUndoStack):
|
||||||
|
|
||||||
def tryAndPush(self, command):
|
def tryAndPush(self, command):
|
||||||
# type: (UndoCommand) -> bool
|
# type: (UndoCommand) -> bool
|
||||||
if command.redoImpl():
|
try:
|
||||||
|
res = command.redoImpl()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Error while trying command '{}': \n{}".format(command.text(), traceback.format_exc()))
|
||||||
|
res = False
|
||||||
|
if res:
|
||||||
command.setEnabled(False)
|
command.setEnabled(False)
|
||||||
self.push(command) # takes ownership
|
self.push(command) # takes ownership
|
||||||
command.setEnabled(True)
|
command.setEnabled(True)
|
||||||
return True
|
return res
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Redeclare QUndoStack signal since original ones can not be used for properties notifying
|
# Redeclare QUndoStack signal since original ones can not be used for properties notifying
|
||||||
_cleanChanged = Signal()
|
_cleanChanged = Signal()
|
||||||
|
@ -135,11 +146,7 @@ class AddEdgeCommand(GraphCommand):
|
||||||
self.setText("Connect '{}'->'{}'".format(self.srcAttr, self.dstAttr))
|
self.setText("Connect '{}'->'{}'".format(self.srcAttr, self.dstAttr))
|
||||||
|
|
||||||
def redoImpl(self):
|
def redoImpl(self):
|
||||||
try:
|
self.graph.addEdge(self.graph.attribute(self.srcAttr), self.graph.attribute(self.dstAttr))
|
||||||
self.graph.addEdge(self.graph.attribute(self.srcAttr),
|
|
||||||
self.graph.attribute(self.dstAttr))
|
|
||||||
except RuntimeError:
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def undoImpl(self):
|
def undoImpl(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue