diff --git a/src/View/BoundaryCondition/Edit/Table.py b/src/View/BoundaryCondition/Edit/Table.py index d479ea46bc92bcb4f55c10b7597ceb141454e417..6536bd0d14a7e948e1f157a603ca6299da89c9b9 100644 --- a/src/View/BoundaryCondition/Edit/Table.py +++ b/src/View/BoundaryCondition/Edit/Table.py @@ -17,6 +17,7 @@ # -*- coding: utf-8 -*- import logging +import traceback from datetime import date, time, datetime, timedelta @@ -212,11 +213,15 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - self._undo.push( - SetDataCommand( - self._data, row, column, value + try: + self._undo.push( + SetDataCommand( + self._data, row, column, value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/BoundaryCondition/Edit/UndoCommand.py b/src/View/BoundaryCondition/Edit/UndoCommand.py index d2b063c9d74e94d7c4aeee5d457fbf61c96b06a7..4bb2605fc94213a2b70559807b79ca4e1425613c 100644 --- a/src/View/BoundaryCondition/Edit/UndoCommand.py +++ b/src/View/BoundaryCondition/Edit/UndoCommand.py @@ -33,7 +33,8 @@ class SetDataCommand(QUndoCommand): self._index = index self._column = column self._old = self._data.get_i(self._index)[self._column] - self._new = new_value + _type = self._data.get_type_column(self._column) + self._new = _type(new_value) def undo(self): self._data._set_i_c_v(self._index, self._column, self._old) diff --git a/src/View/BoundaryCondition/Table.py b/src/View/BoundaryCondition/Table.py index d1570c05695eed89cda7ac1ea33eb263551f5dc9..fd39a13aff69623acbfe805d358d8824cbc23b99 100644 --- a/src/View/BoundaryCondition/Table.py +++ b/src/View/BoundaryCondition/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from tools import trace, timer from PyQt5.QtCore import ( @@ -43,6 +46,8 @@ from View.BoundaryCondition.UndoCommand import ( ) from View.BoundaryCondition.translate import * +logger = logging.getLogger() + _translate = QCoreApplication.translate class ComboBoxDelegate(QItemDelegate): @@ -153,25 +158,29 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] == "name": - self._undo.push( - SetNameCommand( - self._bcs, self._tab,row, value + try: + if self._headers[column] == "name": + self._undo.push( + SetNameCommand( + self._bcs, self._tab,row, value + ) ) - ) - elif self._headers[column] == "type": - key = next(k for k, v in long_types.items() if v == value) - self._undo.push( - SetTypeCommand( - self._bcs, self._tab,row, BC_types[key] + elif self._headers[column] == "type": + key = next(k for k, v in long_types.items() if v == value) + self._undo.push( + SetTypeCommand( + self._bcs, self._tab,row, BC_types[key] + ) ) - ) - elif self._headers[column] == "node": - self._undo.push( - SetNodeCommand( - self._bcs, self._tab,row, self._data.node(value) + elif self._headers[column] == "node": + self._undo.push( + SetNodeCommand( + self._bcs, self._tab,row, self._data.node(value) + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/BoundaryCondition/UndoCommand.py b/src/View/BoundaryCondition/UndoCommand.py index 9f8600c487e04cda8d4b688bb5c26869e9a0d4f9..bbf8cb2c64ca351622b272af5ad94f8a10aa693f 100644 --- a/src/View/BoundaryCondition/UndoCommand.py +++ b/src/View/BoundaryCondition/UndoCommand.py @@ -34,7 +34,7 @@ class SetNameCommand(QUndoCommand): self._tab = tab self._index = index self._old = self._bcs.get(self._tab, self._index).name - self._new = new_value + self._new = str(new_value) def undo(self): self._bcs.get(self._tab, self._index).name = self._old diff --git a/src/View/Frictions/Table.py b/src/View/Frictions/Table.py index 8a6171da2227d564922c2ed4dd9b112882d304b3..ef9dc32f5cce327fc5e10efbc17520c7dbaa0cd3 100644 --- a/src/View/Frictions/Table.py +++ b/src/View/Frictions/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from tools import trace, timer from PyQt5.QtCore import ( @@ -40,6 +43,8 @@ from View.Frictions.UndoCommand import ( from View.Frictions.translate import * +logger = logging.getLogger() + _translate = QCoreApplication.translate class ComboBoxDelegate(QItemDelegate): @@ -148,36 +153,40 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] == "name": - self._undo.push( - SetNameCommand( - self._frictions, row, value + try: + if self._headers[column] == "name": + self._undo.push( + SetNameCommand( + self._frictions, row, value + ) ) - ) - elif self._headers[column] == "begin_kp": - self._undo.push( - SetBeginCommand( - self._frictions, row, value + elif self._headers[column] == "begin_kp": + self._undo.push( + SetBeginCommand( + self._frictions, row, value + ) ) - ) - elif self._headers[column] == "end_kp": - self._undo.push( - SetEndCommand( - self._frictions, row, value + elif self._headers[column] == "end_kp": + self._undo.push( + SetEndCommand( + self._frictions, row, value + ) ) - ) - elif self._headers[column] == "begin_strickler": - self._undo.push( - SetBeginStricklerCommand( - self._frictions, row, self._study.river.strickler(value) + elif self._headers[column] == "begin_strickler": + self._undo.push( + SetBeginStricklerCommand( + self._frictions, row, self._study.river.strickler(value) + ) ) - ) - elif self._headers[column] == "end_strickler": - self._undo.push( - SetEndStricklerCommand( - self._frictions, row, self._study.river.strickler(value) + elif self._headers[column] == "end_strickler": + self._undo.push( + SetEndStricklerCommand( + self._frictions, row, self._study.river.strickler(value) + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/Frictions/UndoCommand.py b/src/View/Frictions/UndoCommand.py index 911ded8a1de0d14a6ebc76eb92e692445b5d153d..ef902f07d55453daf9ae9e6e0830fb6b1915c23c 100644 --- a/src/View/Frictions/UndoCommand.py +++ b/src/View/Frictions/UndoCommand.py @@ -33,7 +33,7 @@ class SetNameCommand(QUndoCommand): self._frictions = frictions self._index = index self._old = self._frictions.get(self._index).name - self._new = new_value + self._new = str(new_value) def undo(self): self._frictions.get(self._index).name = self._old @@ -48,7 +48,7 @@ class SetBeginCommand(QUndoCommand): self._frictions = frictions self._index = index self._old = self._frictions.get(self._index).begin_kp - self._new = new_value + self._new = float(new_value) def undo(self): self._frictions.get(self._index).begin_kp = float(self._old) @@ -63,7 +63,7 @@ class SetEndCommand(QUndoCommand): self._frictions = frictions self._index = index self._old = self._frictions.get(self._index).end_kp - self._new = new_value + self._new = float(new_value) def undo(self): self._frictions.get(self._index).end_kp = float(self._old) diff --git a/src/View/Geometry/Profile/Table.py b/src/View/Geometry/Profile/Table.py index 3d5f72df22a8fdb02088244a2f57aee8b15b30a9..2de665aad935b2825dddde4388a9047f1ad790f0 100644 --- a/src/View/Geometry/Profile/Table.py +++ b/src/View/Geometry/Profile/Table.py @@ -17,6 +17,8 @@ # -*- coding: utf-8 -*- import numpy as np +import logging +import traceback from tools import timer, trace @@ -36,6 +38,8 @@ from Model.Geometry.ProfileXYZ import ProfileXYZ from View.Geometry.Profile.UndoCommand import * +logger = logging.getLogger() + _translate = QCoreApplication.translate @@ -148,38 +152,42 @@ class TableEditableModel(QAbstractTableModel): column = index.column() if role == Qt.EditRole: - if column == 0: - self._undo_stack.push( - SetXCommand( - self._profile, row, - self._profile.point(row).x, - value + try: + if column == 0: + self._undo_stack.push( + SetXCommand( + self._profile, row, + self._profile.point(row).x, + value + ) ) - ) - elif column == 1: - self._undo_stack.push( - SetYCommand( - self._profile, row, - self._profile.point(row).y, - value + elif column == 1: + self._undo_stack.push( + SetYCommand( + self._profile, row, + self._profile.point(row).y, + value + ) ) - ) - elif column == 2: - self._undo_stack.push( - SetZCommand( - self._profile, row, - self._profile.point(row).z, - value + elif column == 2: + self._undo_stack.push( + SetZCommand( + self._profile, row, + self._profile.point(row).z, + value + ) ) - ) - elif column == 3: - self._undo_stack.push( - SetNameCommand( - self._profile, row, - self._profile.point(row).name, - value + elif column == 3: + self._undo_stack.push( + SetNameCommand( + self._profile, row, + self._profile.point(row).name, + value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/Geometry/Profile/UndoCommand.py b/src/View/Geometry/Profile/UndoCommand.py index 166a004b1bbea7af6bd00acab85456bf3f942c2f..7f0cd1388973ca9461cb1d1b355fdc21193d69f2 100644 --- a/src/View/Geometry/Profile/UndoCommand.py +++ b/src/View/Geometry/Profile/UndoCommand.py @@ -32,9 +32,13 @@ class SetDataCommand(QUndoCommand): self._profile = profile self._index = index self._old = old_value - self._new = new_value + self._new = self.type(new_value) class SetXCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = float + super(SetXCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._profile.point(self._index).x = self._old @@ -42,6 +46,10 @@ class SetXCommand(SetDataCommand): self._profile.point(self._index).x = self._new class SetYCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = float + super(SetYCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._profile.point(self._index).y = self._old @@ -49,6 +57,10 @@ class SetYCommand(SetDataCommand): self._profile.point(self._index).y = self._new class SetZCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = float + super(SetZCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._profile.point(self._index).z = self._old @@ -56,6 +68,10 @@ class SetZCommand(SetDataCommand): self._profile.point(self._index).z = self._new class SetNameCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = str + super(SetNameCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._profile.point(self._index).name = self._old diff --git a/src/View/Geometry/Table.py b/src/View/Geometry/Table.py index 63ae8e455d8f69a5deb31ee67e0206da1700e892..1b055209d9fb4feeadd26d6ab40ea381f7acf24c 100644 --- a/src/View/Geometry/Table.py +++ b/src/View/Geometry/Table.py @@ -17,6 +17,8 @@ # -*- coding: utf-8 -*- import time +import logging +import traceback from tools import timer, trace @@ -37,6 +39,7 @@ from Model.Geometry import Reach from Model.Geometry.ProfileXYZ import ProfileXYZ from View.Geometry.UndoCommand import * +logger = logging.getLogger() _translate = QCoreApplication.translate @@ -114,23 +117,27 @@ class TableEditableModel(QAbstractTableModel): column = index.column() if role == Qt.EditRole and index.column() != 2: - if index.column() == 0: - self._undo_stack.push( - SetNameCommand( - self._reach, index.row(), - self._reach.profile(index.row()).name, - value + try: + if index.column() == 0: + self._undo_stack.push( + SetNameCommand( + self._reach, index.row(), + self._reach.profile(index.row()).name, + value + ) ) - ) - if index.column() == 1: - self._undo_stack.push( - SetKPCommand( - self._reach, index.row(), - self._reach.profile(index.row()).kp, + if index.column() == 1: + self._undo_stack.push( + SetKPCommand( + self._reach, index.row(), + self._reach.profile(index.row()).kp, value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) self.layoutChanged.emit() diff --git a/src/View/Geometry/UndoCommand.py b/src/View/Geometry/UndoCommand.py index 148f7db3d40fa09c886eb07fc561f564a8bc0061..1df9c58c87cd68a22ae8c90b8691196945b702f6 100644 --- a/src/View/Geometry/UndoCommand.py +++ b/src/View/Geometry/UndoCommand.py @@ -33,9 +33,13 @@ class SetDataCommand(QUndoCommand): self._reach = reach self._index = index self._old = old_value - self._new = new_value + self._new = self.type(new_value) class SetNameCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = str + super(SetNameCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._reach.profile(self._index).name = self._old @@ -43,6 +47,10 @@ class SetNameCommand(SetDataCommand): self._reach.profile(self._index).name = self._new class SetKPCommand(SetDataCommand): + def __init__(self, reach, index, old_value, new_value): + self.type = float + super(SetKPCommand, self).__init__(reach, index, old_value, new_value) + def undo(self): self._reach.profile(self._index).kp = self._old diff --git a/src/View/InitialConditions/Table.py b/src/View/InitialConditions/Table.py index ebb9af8570c05d4b40f0846dc1d2e3a27b3ac3b7..5e704ba921635b633a2c947cc0b922d8bfaa422d 100644 --- a/src/View/InitialConditions/Table.py +++ b/src/View/InitialConditions/Table.py @@ -16,6 +16,8 @@ # -*- coding: utf-8 -*- +import logging +import traceback from tools import trace, timer from PyQt5.QtCore import ( @@ -39,6 +41,8 @@ from View.InitialConditions.UndoCommand import ( from View.InitialConditions.translate import * +logger = logging.getLogger() + _translate = QCoreApplication.translate class ComboBoxDelegate(QItemDelegate): @@ -135,12 +139,16 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] is not None: - self._undo.push( - SetCommand( - self._ics, row, self._headers[column], value + try: + if self._headers[column] is not None: + self._undo.push( + SetCommand( + self._ics, row, self._headers[column], value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/InitialConditions/UndoCommand.py b/src/View/InitialConditions/UndoCommand.py index 9d93f78b5bc3386295065d38d24e0c7692bb9231..c96f90fa2f759800cf40fb713dc593c4db503610 100644 --- a/src/View/InitialConditions/UndoCommand.py +++ b/src/View/InitialConditions/UndoCommand.py @@ -34,7 +34,12 @@ class SetCommand(QUndoCommand): self._row = row self._column = column self._old = self._ics.get(self._row)[column] - self._new = new_value + + _type = float + if column == "name" or column == "comment": + _type = str + + self._new = _type(new_value) def undo(self): self._ics.get(self._row)[self._column] = self._old diff --git a/src/View/LateralContribution/Edit/Table.py b/src/View/LateralContribution/Edit/Table.py index 0fabd5cb702f6de01bbd16497443cc6dc5b02fff..e9e878fddc8fd623d18ee683674e1030ec5cb94e 100644 --- a/src/View/LateralContribution/Edit/Table.py +++ b/src/View/LateralContribution/Edit/Table.py @@ -17,6 +17,7 @@ # -*- coding: utf-8 -*- import logging +import traceback from datetime import date, time, datetime, timedelta from tools import trace, timer @@ -210,11 +211,15 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - self._undo.push( - SetDataCommand( - self._data, row, column, value + try: + self._undo.push( + SetDataCommand( + self._data, row, column, value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/LateralContribution/Edit/UndoCommand.py b/src/View/LateralContribution/Edit/UndoCommand.py index a0a602bc3acb2591b7d104672331aff2072f84ba..715683c944864f05411cc6c23825c15f8cdc6fa0 100644 --- a/src/View/LateralContribution/Edit/UndoCommand.py +++ b/src/View/LateralContribution/Edit/UndoCommand.py @@ -33,7 +33,8 @@ class SetDataCommand(QUndoCommand): self._index = index self._column = column self._old = self._data.get_i(self._index)[self._column] - self._new = new_value + _type = self._data.get_type_column(self._column) + self._new = _type(new_value) def undo(self): self._data._set_i_c_v(self._index, self._column, self._old) diff --git a/src/View/LateralContribution/Table.py b/src/View/LateralContribution/Table.py index f5a8bdf1810b3c16abdb0a71d4ad593404d34cfc..682bf00dc8a0ab23fbdcc7c53b5cb82a34855976 100644 --- a/src/View/LateralContribution/Table.py +++ b/src/View/LateralContribution/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from tools import trace, timer from PyQt5.QtCore import ( @@ -43,6 +46,8 @@ from Model.LateralContribution.LateralContributionTypes import ( ) from View.LateralContribution.translate import * +logger = logging.getLogger() + _translate = QCoreApplication.translate class ComboBoxDelegate(QItemDelegate): @@ -156,37 +161,41 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] == "name": - self._undo.push( - SetNameCommand( - self._lcs, self._tab, row, value + try: + if self._headers[column] == "name": + self._undo.push( + SetNameCommand( + self._lcs, self._tab, row, value + ) ) - ) - elif self._headers[column] == "type": - key = next(k for k, v in long_types.items() if v == value) - self._undo.push( - SetTypeCommand( - self._lcs, self._tab, row, LC_types[key] + elif self._headers[column] == "type": + key = next(k for k, v in long_types.items() if v == value) + self._undo.push( + SetTypeCommand( + self._lcs, self._tab, row, LC_types[key] + ) ) - ) - elif self._headers[column] == "edge": - self._undo.push( - SetEdgeCommand( - self._lcs, self._tab, row, self._data.edge(value) + elif self._headers[column] == "edge": + self._undo.push( + SetEdgeCommand( + self._lcs, self._tab, row, self._data.edge(value) + ) ) - ) - elif self._headers[column] == "begin_kp": - self._undo.push( - SetBeginCommand( - self._lcs, self._tab, row, value + elif self._headers[column] == "begin_kp": + self._undo.push( + SetBeginCommand( + self._lcs, self._tab, row, value + ) ) - ) - elif self._headers[column] == "end_kp": - self._undo.push( - SetEndCommand( - self._lcs, self._tab, row, value + elif self._headers[column] == "end_kp": + self._undo.push( + SetEndCommand( + self._lcs, self._tab, row, value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/LateralContribution/UndoCommand.py b/src/View/LateralContribution/UndoCommand.py index 6b6883941572d88cb5001a62fb1d473c5d76e734..3d8584368704fe6a23cb4fbaddc58cda6ea0a500 100644 --- a/src/View/LateralContribution/UndoCommand.py +++ b/src/View/LateralContribution/UndoCommand.py @@ -34,7 +34,7 @@ class SetNameCommand(QUndoCommand): self._tab = tab self._index = index self._old = self._lcs.get(self._tab, self._index).name - self._new = new_value + self._new = str(new_value) def undo(self): self._lcs.get(self._tab, self._index).name = self._old @@ -50,7 +50,7 @@ class SetBeginCommand(QUndoCommand): self._tab = tab self._index = index self._old = self._lcs.get(self._tab, self._index).begin_kp - self._new = new_value + self._new = float(new_value) def undo(self): self._lcs.get(self._tab, self._index).begin_kp = float(self._old) @@ -66,7 +66,7 @@ class SetEndCommand(QUndoCommand): self._tab = tab self._index = index self._old = self._lcs.get(self._tab, self._index).end_kp - self._new = new_value + self._new = float(new_value) def undo(self): self._lcs.get(self._tab, self._index).end_kp = float(self._old) diff --git a/src/View/Network/Table.py b/src/View/Network/Table.py index 1b7717799d052cac21f330c21dbfd01d10a79f76..b24865e8b15a6daf9671e4b05d9e017f19b1cb7d 100644 --- a/src/View/Network/Table.py +++ b/src/View/Network/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from Model.Network.Node import Node from Model.Network.Edge import Edge from Model.Network.Graph import Graph @@ -153,31 +156,35 @@ class GraphTableModel(QAbstractTableModel): def setData(self, index, value, role=Qt.EditRole): if index.isValid(): if role == Qt.EditRole: - if (self.headers[index.column()] == "node1" or - self.headers[index.column()] == "node2"): - node = self.graph.node(value) - self._undo.push( - SetNodeCommand( - self.graph, - self.rows[index.row()], - self.headers[index.column()], - node + try: + if (self.headers[index.column()] == "node1" or + self.headers[index.column()] == "node2"): + node = self.graph.node(value) + self._undo.push( + SetNodeCommand( + self.graph, + self.rows[index.row()], + self.headers[index.column()], + node + ) ) - ) - # elif self.headers[index.column()] == "enable": - # self._undo.push( - # EnableEdgeCommand( - # self.rows[index.row()], value - # ) - # ) - else: - self._undo.push( - SetCommand( - self.rows[index.row()], - self.headers[index.column()], - value + # elif self.headers[index.column()] == "enable": + # self._undo.push( + # EnableEdgeCommand( + # self.rows[index.row()], value + # ) + # ) + else: + self._undo.push( + SetCommand( + self.rows[index.row()], + self.headers[index.column()], + value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index, [Qt.DisplayRole]) self.layoutChanged.emit() diff --git a/src/View/SolverParameters/Table.py b/src/View/SolverParameters/Table.py index 9aa3b55bf14b0591ed599fb6b358709a756ef796..5aa488abacd2dde2293349e75f77f304f10b1d9e 100644 --- a/src/View/SolverParameters/Table.py +++ b/src/View/SolverParameters/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from tools import trace, timer from PyQt5.QtCore import ( @@ -97,16 +100,20 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] == "value": - if value in tr.r_yes_no: - value = tr.r_yes_no[value].lower() + try: + if self._headers[column] == "value": + if value in tr.r_yes_no: + value = tr.r_yes_no[value].lower() - self._undo.push( - SetCommand( - self._params, row, - "value", value + self._undo.push( + SetCommand( + self._params, row, + "value", value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/SolverParameters/UndoCommand.py b/src/View/SolverParameters/UndoCommand.py index 3c917e4fe8703a5c16b1cee4d639994ac65573d3..d3343d007ca17ad5c54a1398b92c1862c320e93b 100644 --- a/src/View/SolverParameters/UndoCommand.py +++ b/src/View/SolverParameters/UndoCommand.py @@ -33,7 +33,7 @@ class SetCommand(QUndoCommand): self._index = index self._column = column self._old = self._data.get(self._index)[column] - self._new = new_value + self._new = str(new_value) def undo(self): self._data.get(self._index)[self._column] = self._old diff --git a/src/View/Stricklers/Table.py b/src/View/Stricklers/Table.py index 31dd4d9b4323c7f9d48c8e7a3e13b32462d6649f..5d32cda51b19f49434c11360d6aa2973de57e44c 100644 --- a/src/View/Stricklers/Table.py +++ b/src/View/Stricklers/Table.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging +import traceback + from tools import trace, timer from PyQt5.QtCore import ( @@ -39,8 +42,9 @@ from View.Stricklers.UndoCommand import ( from View.Stricklers.translate import * -_translate = QCoreApplication.translate +logger = logging.getLogger() +_translate = QCoreApplication.translate class TableModel(QAbstractTableModel): def __init__(self, data=None, undo=None, tab=""): @@ -92,30 +96,34 @@ class TableModel(QAbstractTableModel): row = index.row() column = index.column() - if self._headers[column] == "name": - self._undo.push( - SetNameCommand( - self._data, row, value + try: + if self._headers[column] == "name": + self._undo.push( + SetNameCommand( + self._data, row, value + ) ) - ) - elif self._headers[column] == "comment": - self._undo.push( - SetCommentCommand( - self._data, row, value + elif self._headers[column] == "comment": + self._undo.push( + SetCommentCommand( + self._data, row, value + ) ) - ) - elif self._headers[column] == "minor": - self._undo.push( - SetMinorCommand( - self._data, row, value + elif self._headers[column] == "minor": + self._undo.push( + SetMinorCommand( + self._data, row, value + ) ) - ) - elif self._headers[column] == "medium": - self._undo.push( - SetMediumCommand( - self._data, row, value + elif self._headers[column] == "medium": + self._undo.push( + SetMediumCommand( + self._data, row, value + ) ) - ) + except Exception as e: + logger.info(e) + logger.debug(traceback.format_exc()) self.dataChanged.emit(index, index) return True diff --git a/src/View/Stricklers/UndoCommand.py b/src/View/Stricklers/UndoCommand.py index e7dc733e818baed2d718f07cfd68abcd5ed6267b..ee75cf99c9b2205a87853d86a0bc7ebfa8208ef6 100644 --- a/src/View/Stricklers/UndoCommand.py +++ b/src/View/Stricklers/UndoCommand.py @@ -33,7 +33,7 @@ class SetNameCommand(QUndoCommand): self._data = data self._index = index self._old = self._data.get(self._index).name - self._new = new_value + self._new = str(new_value) def undo(self): self._data.get(self._index).name = self._old @@ -48,7 +48,7 @@ class SetCommentCommand(QUndoCommand): self._data = data self._index = index self._old = self._data.get(self._index).comment - self._new = new_value + self._new = str(new_value) def undo(self): self._data.get(self._index).comment = self._old @@ -63,7 +63,7 @@ class SetMinorCommand(QUndoCommand): self._data = data self._index = index self._old = self._data.get(self._index).minor - self._new = new_value + self._new = float(new_value) def undo(self): self._data.get(self._index).minor = self._old @@ -78,7 +78,7 @@ class SetMediumCommand(QUndoCommand): self._data = data self._index = index self._old = self._data.get(self._index).medium - self._new = new_value + self._new = float(new_value) def undo(self): self._data.get(self._index).medium = self._old