[r22949]Bug 7017 GUI stuck when external viewer launched
subprocess.checked_call seems to wait on the process that xdg-open starts, but subprocess.wait doesn't. svn: r22951
This commit is contained in:
parent
649c105536
commit
1dc39d8c1c
@ -28,9 +28,7 @@
|
|||||||
# Standard python modules
|
# Standard python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
import os
|
||||||
_ = glocale.translation.gettext
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GTK/Gnome modules
|
# GTK/Gnome modules
|
||||||
@ -44,6 +42,8 @@ from gi.repository import Gdk
|
|||||||
# gramps modules
|
# gramps modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.gettext
|
||||||
from ..utils import open_file_with_default_application
|
from ..utils import open_file_with_default_application
|
||||||
from gramps.gen.lib import MediaObject, NoteType
|
from gramps.gen.lib import MediaObject, NoteType
|
||||||
from gramps.gen.db import DbTxn
|
from gramps.gen.db import DbTxn
|
||||||
|
@ -358,6 +358,34 @@ class SystemFonts(object):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
def poll_external ((proc, errorstrings)):
|
||||||
|
"""
|
||||||
|
Check the for completion of a task launched with
|
||||||
|
subprocess.Popen(). This function is intended to be passed to
|
||||||
|
GLib.timeout_add_seconds, so the arguments are in a tuple because that
|
||||||
|
function takes only a single data argument.
|
||||||
|
|
||||||
|
@proc the process, returned from subprocess.Popen()
|
||||||
|
@errorstrings a dict of possible response values and the corresponding messages to display.
|
||||||
|
@returns False when the function has completed.
|
||||||
|
"""
|
||||||
|
from .dialog import ErrorDialog
|
||||||
|
resp = proc.poll()
|
||||||
|
if resp is None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if resp != 0:
|
||||||
|
error = "The external program failed to launch or experienced an error"
|
||||||
|
if errorstrings:
|
||||||
|
try:
|
||||||
|
error = errorstrings[resp]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
ErrorDialog(_("Error from external program"), error)
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def open_file_with_default_application( file_path ):
|
def open_file_with_default_application( file_path ):
|
||||||
"""
|
"""
|
||||||
Launch a program to open an arbitrary file. The file will be opened using
|
Launch a program to open an arbitrary file. The file will be opened using
|
||||||
@ -369,7 +397,6 @@ def open_file_with_default_application( file_path ):
|
|||||||
@type file_path: string
|
@type file_path: string
|
||||||
@return: nothing
|
@return: nothing
|
||||||
"""
|
"""
|
||||||
from .dialog import ErrorDialog
|
|
||||||
norm_path = os.path.normpath( file_path )
|
norm_path = os.path.normpath( file_path )
|
||||||
if not os.path.exists(norm_path):
|
if not os.path.exists(norm_path):
|
||||||
ErrorDialog(_("Error Opening File"), _("File does not exist"))
|
ErrorDialog(_("Error Opening File"), _("File does not exist"))
|
||||||
@ -382,14 +409,20 @@ def open_file_with_default_application( file_path ):
|
|||||||
ErrorDialog(_("Error Opening File"), str(msg))
|
ErrorDialog(_("Error Opening File"), str(msg))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
errstrings = None
|
||||||
if mac():
|
if mac():
|
||||||
utility = '/usr/bin/open'
|
utility = '/usr/bin/open'
|
||||||
else:
|
else:
|
||||||
utility = 'xdg-open'
|
utility = 'xdg-open'
|
||||||
try:
|
errstrings = {1:'Error in command line syntax.',
|
||||||
subprocess.check_output([utility, norm_path], stderr=subprocess.STDOUT)
|
2:'One of the files passed on the command line did not exist.',
|
||||||
except subprocess.CalledProcessError as err:
|
3:' A required tool could not be found.',
|
||||||
ErrorDialog(_("Error Opening File"), err.output)
|
4:'The action failed.'}
|
||||||
|
|
||||||
|
proc = subprocess.Popen([utility, norm_path], stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
from gi.repository import GLib
|
||||||
|
GLib.timeout_add_seconds(1, poll_external, (proc, errstrings))
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_pending_events(max_count=10):
|
def process_pending_events(max_count=10):
|
||||||
|
Loading…
Reference in New Issue
Block a user