From 9bb2bc5c0d1076264916ba7ffd9be48b6c5c0fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 8 Dec 2018 18:24:10 +0100 Subject: [PATCH] [preview] Dont crash on errors in other threads --- url_image_preview/url_image_preview.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/url_image_preview/url_image_preview.py b/url_image_preview/url_image_preview.py index 6fb2266..d18c6dd 100644 --- a/url_image_preview/url_image_preview.py +++ b/url_image_preview/url_image_preview.py @@ -379,12 +379,12 @@ class Base(object): width, height, GdkPixbuf.InterpType.BILINEAR) thumbnail.savev(thumbpath, 'png', [], []) except Exception as error: - dialogs.ErrorDialog( + GLib.idle_add( + self._raise_error_dialog, _('Could not save file'), _('Exception raised while saving thumbnail ' 'for image file (see error log for more ' - 'information)'), - transient_for=app.app.get_active_window()) + 'information)')) log.exception(error) return return thumbnail @@ -545,11 +545,11 @@ class Base(object): # Write file to harddisk self._write_file(filepath, mem) except Exception as e: - dialogs.ErrorDialog( + GLib.idle_add( + self._raise_error_dialog, _('Could not save file'), _('Exception raised while saving image file' - ' (see error log for more information)'), - transient_for=app.app.get_active_window()) + ' (see error log for more information)')) log.error(str(e)) # Create thumbnail, write it to harddisk and return it @@ -713,5 +713,12 @@ class Base(object): # menu.popup(None, None, None, event.button, event.time) menu.popup_at_pointer(event) + @staticmethod + def _raise_error_dialog(pritext, sectext): + # Used by methods that run in a different thread + dialogs.ErrorDialog(pritext, + sectext, + transient_for=app.app.get_active_window()) + def disconnect_from_chat_control(self): pass