From 1c469d373086011daac423d51708f7396980ebe8 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 29 Mar 2021 16:12:18 +0200 Subject: [PATCH] catch exceptions on save in settings ui --- .../settings/settings/widgets/categories.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pype/tools/settings/settings/widgets/categories.py b/pype/tools/settings/settings/widgets/categories.py index 263012fa52..f1e154ee4d 100644 --- a/pype/tools/settings/settings/widgets/categories.py +++ b/pype/tools/settings/settings/widgets/categories.py @@ -260,14 +260,43 @@ class SettingsCategoryWidget(QtWidgets.QWidget): self.content_layout.addWidget(widget, 0) def save(self): - if self.items_are_valid(): + if not self.items_are_valid(): + return + + try: self.entity.save() + # NOTE There are relations to previous entities and C++ callbacks # so it is easier to just use new entity and recreate UI but # would be nice to change this and add cleanup part so this is # not required. self.reset() + except Exception as exc: + formatted_traceback = traceback.format_exception(*sys.exc_info()) + dialog = QtWidgets.QMessageBox(self) + msg = "Unexpected error happened!\n\nError: {}".format(str(exc)) + dialog.setText(msg) + dialog.setDetailedText("\n".join(formatted_traceback)) + dialog.setIcon(QtWidgets.QMessageBox.Critical) + + line_widths = set() + metricts = dialog.fontMetrics() + for line in formatted_traceback: + line_widths.add(metricts.width(line)) + max_width = max(line_widths) + + spacer = QtWidgets.QSpacerItem( + max_width, 0, + QtWidgets.QSizePolicy.Minimum, + QtWidgets.QSizePolicy.Expanding + ) + layout = dialog.layout() + layout.addItem( + spacer, layout.rowCount(), 0, 1, layout.columnCount() + ) + dialog.exec_() + def _create_root_entity(self): raise NotImplementedError( "`create_root_entity` method not implemented"