diff --git a/gramps/gui/editors/displaytabs/gallerytab.py b/gramps/gui/editors/displaytabs/gallerytab.py index a9a099b00..c66eba580 100644 --- a/gramps/gui/editors/displaytabs/gallerytab.py +++ b/gramps/gui/editors/displaytabs/gallerytab.py @@ -67,8 +67,8 @@ _ = glocale.translation.gettext # # #------------------------------------------------------------------------- -def make_launcher(path): - return lambda x: open_file_with_default_application(path) +def make_launcher(path, uistate): + return lambda x: open_file_with_default_application(path, uistate) #------------------------------------------------------------------------- # @@ -140,12 +140,12 @@ class GalleryTab(ButtonTab, DbGUIElement): img = Gtk.Image() img.set_from_icon_name("gramps-viewmedia", Gtk.IconSize.MENU) item.set_image(img) - item.connect('activate', make_launcher(media_path)) + item.connect('activate', make_launcher(media_path, self.uistate)) item.show() self.menu.append(item) mfolder, mfile = os.path.split(media_path) item = Gtk.MenuItem(label=_('Open Containing _Folder')) - item.connect('activate', make_launcher(mfolder)) + item.connect('activate', make_launcher(mfolder, self.uistate)) item.show() self.menu.append(item) item = Gtk.SeparatorMenuItem() diff --git a/gramps/gui/editors/editmedia.py b/gramps/gui/editors/editmedia.py index e76b3b6cb..c5e4870f6 100644 --- a/gramps/gui/editors/editmedia.py +++ b/gramps/gui/editors/editmedia.py @@ -252,7 +252,7 @@ class EditMedia(EditPrimary): if ref_obj: media_path = media_path_full(self.dbstate.db, ref_obj.get_path()) - open_file_with_default_application(media_path) + open_file_with_default_application(media_path, self.uistate) def select_file(self, val): self.determine_mime() diff --git a/gramps/gui/editors/editmediaref.py b/gramps/gui/editors/editmediaref.py index 28931351a..e82623bc6 100644 --- a/gramps/gui/editors/editmediaref.py +++ b/gramps/gui/editors/editmediaref.py @@ -411,7 +411,7 @@ class EditMediaRef(EditReference): def button_press_event(self, obj, event): if event.button==1 and event.type == Gdk.EventType._2BUTTON_PRESS: photo_path = media_path_full(self.db, self.source.get_path()) - open_file_with_default_application(photo_path) + open_file_with_default_application(photo_path, self.uistate) def _update_addmedia(self, obj): """ diff --git a/gramps/gui/editors/editperson.py b/gramps/gui/editors/editperson.py index d029db264..a6f28c46b 100644 --- a/gramps/gui/editors/editperson.py +++ b/gramps/gui/editors/editperson.py @@ -663,7 +663,7 @@ class EditPerson(EditPrimary): object_handle = photo.get_reference_handle() ref_obj = self.db.get_media_from_handle(object_handle) photo_path = media_path_full(self.db, ref_obj.get_path()) - open_file_with_default_application(photo_path) + open_file_with_default_application(photo_path, self.uistate) def _popup_change_description(self, obj): """ diff --git a/gramps/gui/plug/_windows.py b/gramps/gui/plug/_windows.py index 53c53628e..a98337fde 100644 --- a/gramps/gui/plug/_windows.py +++ b/gramps/gui/plug/_windows.py @@ -661,8 +661,8 @@ class PluginStatus(ManagedWindow): pdata = self.__preg.get_plugin(id) if pdata.fpath and pdata.fname: open_file_with_default_application( - os.path.join(pdata.fpath, pdata.fname) - ) + os.path.join(pdata.fpath, pdata.fname), + self.uistate) #------------------------------------------------------------------------- # diff --git a/gramps/gui/plug/report/_bookdialog.py b/gramps/gui/plug/report/_bookdialog.py index f39755015..c9285cb72 100644 --- a/gramps/gui/plug/report/_bookdialog.py +++ b/gramps/gui/plug/report/_bookdialog.py @@ -1024,7 +1024,7 @@ class BookDialog(DocReportDialog): return if self.open_with_app.get_active(): - open_file_with_default_application(self.target_path) + open_file_with_default_application(self.target_path, self.uistate) def init_options(self, option_class): try: diff --git a/gramps/gui/plug/report/_reportdialog.py b/gramps/gui/plug/report/_reportdialog.py index 3856f02a0..19e1798b3 100644 --- a/gramps/gui/plug/report/_reportdialog.py +++ b/gramps/gui/plug/report/_reportdialog.py @@ -706,7 +706,7 @@ def report(dbstate, uistate, person, report_class, options_class, dialog.open_with_app.get_property('sensitive') == True and dialog.open_with_app.get_active()): out_file = dialog.options.get_output() - open_file_with_default_application(out_file) + open_file_with_default_application(out_file, self.uistate) except FilterError as msg: (msg1, msg2) = msg.messages() diff --git a/gramps/gui/utils.py b/gramps/gui/utils.py index 0c69d9a39..9a7b03b9d 100644 --- a/gramps/gui/utils.py +++ b/gramps/gui/utils.py @@ -357,7 +357,7 @@ class SystemFonts: # # #------------------------------------------------------------------------- -def display_error_dialog (index, errorstrings): +def display_error_dialog (index, errorstrings, uistate=None): """ Display a message box for errors resulting from xdg-open/open """ @@ -372,7 +372,8 @@ def display_error_dialog (index, errorstrings): else: error = errorstrings - ErrorDialog(_("Error from external program"), error) # TODO no-parent + ErrorDialog(_("Error from external program"), # parent-OK + error, parent=uistate.window) def poll_external (args): """ @@ -387,16 +388,16 @@ def poll_external (args): :return: bool returned to timeout_add_seconds: should this function be called again? """ - (proc, errorstrings) = args + (proc, errorstrings, uistate) = args resp = proc.poll() if resp is None: return True if resp != 0: - display_error_dialog(resp, errorstrings) + display_error_dialog(resp, errorstrings, uistate) return False -def open_file_with_default_application(path): +def open_file_with_default_application(path, uistate): """ Launch a program to open an arbitrary file. The file will be opened using whatever program is configured on the host as the default program for that @@ -412,14 +413,16 @@ def open_file_with_default_application(path): norm_path = os.path.normpath(path) if not os.path.exists(norm_path): - display_error_dialog(0, _("File %s does not exist") % norm_path) + display_error_dialog(0, _("File %s does not exist") % norm_path, + uistate) return if win(): try: os.startfile(norm_path) except WindowsError as msg: - display_error_dialog(0, str(msg)) + display_error_dialog(0, str(msg), + uistate) return @@ -435,7 +438,7 @@ def open_file_with_default_application(path): proc = subprocess.Popen([utility, norm_path], stderr=subprocess.STDOUT) from gi.repository import GLib - GLib.timeout_add_seconds(1, poll_external, (proc, errstrings)) + GLib.timeout_add_seconds(1, poll_external, (proc, errstrings, uistate)) return def process_pending_events(max_count=10): diff --git a/gramps/gui/widgets/photo.py b/gramps/gui/widgets/photo.py index 75060557d..08d8fd192 100644 --- a/gramps/gui/widgets/photo.py +++ b/gramps/gui/widgets/photo.py @@ -78,7 +78,7 @@ class Photo(Gtk.EventBox): Display the image with the default external viewer. """ if event.type == Gdk.EventType._2BUTTON_PRESS and event.button == 1: - open_file_with_default_application(self.full_path) + open_file_with_default_application(self.full_path, self.uistate) return True elif is_right_click(event): if self.handle and self.uistate: diff --git a/gramps/plugins/gramplet/mediapreview.py b/gramps/plugins/gramplet/mediapreview.py index f2c8f9382..e580a89c8 100644 --- a/gramps/plugins/gramplet/mediapreview.py +++ b/gramps/plugins/gramplet/mediapreview.py @@ -86,3 +86,4 @@ class MediaPreview(Gramplet): self.full_path = media_path_full(self.dbstate.db, media.get_path()) mime_type = media.get_mime_type() self.photo.set_image(self.full_path, mime_type) + self.photo.set_uistate(self.uistate, None) diff --git a/gramps/plugins/view/mediaview.py b/gramps/plugins/view/mediaview.py index 59a8deb76..c40939058 100644 --- a/gramps/plugins/view/mediaview.py +++ b/gramps/plugins/view/mediaview.py @@ -139,6 +139,7 @@ class MediaView(ListView): }) self.additional_uis.append(self.additional_ui()) + self.uistate = uistate def navigation_type(self): return 'Media' @@ -224,7 +225,7 @@ class MediaView(ListView): for handle in self.selected_handles(): ref_obj = self.dbstate.db.get_media_from_handle(handle) mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) - open_file_with_default_application(mpath) + open_file_with_default_application(mpath, self.uistate) def open_containing_folder(self, obj): """ @@ -235,7 +236,7 @@ class MediaView(ListView): mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) if mpath: mfolder, mfile = os.path.split(mpath) - open_file_with_default_application(mfolder) + open_file_with_default_application(mfolder, self.uistate) def get_stock(self): """ diff --git a/gramps/plugins/view/relview.py b/gramps/plugins/view/relview.py index 318338e38..f316aa2b8 100644 --- a/gramps/plugins/view/relview.py +++ b/gramps/plugins/view/relview.py @@ -673,7 +673,7 @@ class RelationshipView(NavigationView): Open this picture in the default picture viewer. """ photo_path = media_path_full(self.dbstate.db, photo.get_path()) - open_file_with_default_application(photo_path) + open_file_with_default_application(photo_path, self.uistate) def write_person_event(self, ename, event): if event: