mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #1210 from pypeclub/feature/basic_save_catch_settings_ui
Catch exceptions on save in settings ui
This commit is contained in:
commit
0ed283fe65
1 changed files with 30 additions and 1 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue