diff --git a/src/View/InitialConditions/Table.py b/src/View/InitialConditions/Table.py index 1f6e2e8a..c9db850f 100644 --- a/src/View/InitialConditions/Table.py +++ b/src/View/InitialConditions/Table.py @@ -38,7 +38,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel from View.InitialConditions.UndoCommand import ( SetCommand, AddCommand, DelCommand, SortCommand, MoveCommand, InsertCommand, - DuplicateCommand, GenerateCommand, + DuplicateCommand, GenerateCommand, ReplaceDataCommand, ) logger = logging.getLogger() @@ -267,8 +267,8 @@ class InitialConditionTableModel(PamhyrTableModel): ) self._undo.push( - InsertCommand( - self._lst, index, + ReplaceDataCommand( + self._lst, list( map( lambda d: self._lst.new_from_data(*d), diff --git a/src/View/InitialConditions/UndoCommand.py b/src/View/InitialConditions/UndoCommand.py index 64fb1a37..b2babd79 100644 --- a/src/View/InitialConditions/UndoCommand.py +++ b/src/View/InitialConditions/UndoCommand.py @@ -198,3 +198,25 @@ class GenerateCommand(QUndoCommand): self._param[1], self._option, self._param[2]) + + +class ReplaceDataCommand(QUndoCommand): + def __init__(self, ics, new_data): + QUndoCommand.__init__(self) + + self._ics = ics + self._copy = self._ics.data + self._new_data = new_data + self._rows = list(range(len(ics.data))) + self._new_rows = list(range(len(new_data))) + + def undo(self): + self._ics.delete_i(self._new_rows) + for row, el in enumerate(self._copy): + self._ics.insert(row, el) + + def redo(self): + self._ics.delete_i(self._rows) + for row, el in enumerate(self._new_data): + self._ics.insert(row, el) + diff --git a/src/View/InitialConditions/Window.py b/src/View/InitialConditions/Window.py index 58156cb1..c1717a37 100644 --- a/src/View/InitialConditions/Window.py +++ b/src/View/InitialConditions/Window.py @@ -276,11 +276,14 @@ class InitialConditionsWindow(PamhyrWindow): .replace(".BIN", "") def reading(): - self._tmp_results = solver.results( - self._study, - os.path.dirname(file_name), - name=name - ) + try: + self._tmp_results = solver.results( + self._study, + os.path.dirname(file_name), + name=name + ) + except: + pass dlg = ReadingResultsDialog( reading_fn=reading,