[r22949]Bug 7017 GUI stuck when external viewer launched
Use a Glib timeout event to poll the open process and handle any error returns svn: r22952
This commit is contained in:
parent
00d233a3c5
commit
449d1366b1
@ -328,6 +328,34 @@ class ProgressMeter(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 QuestionDialog 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
|
||||||
@ -340,6 +368,7 @@ def open_file_with_default_application( file_path ):
|
|||||||
@return: nothing
|
@return: nothing
|
||||||
"""
|
"""
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
|
errstrings = None
|
||||||
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"))
|
||||||
@ -356,11 +385,20 @@ def open_file_with_default_application( file_path ):
|
|||||||
utility = '/usr/bin/open'
|
utility = '/usr/bin/open'
|
||||||
else:
|
else:
|
||||||
utility = 'xdg-open'
|
utility = 'xdg-open'
|
||||||
|
errstrings = {1:'Error in command line syntax.',
|
||||||
|
2:'One of the files passed on the command line did not exist.',
|
||||||
|
3:' A required tool could not be found.',
|
||||||
|
4:'The action failed.'}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output([utility, norm_path], stderr=subprocess.STDOUT)
|
subprocess.check_output([utility, norm_path], stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
ErrorDialog(_("Error Opening File"), err.output)
|
ErrorDialog(_("Error Opening File"), err.output)
|
||||||
|
|
||||||
|
proc = subprocess.Popen([utility, norm_path], stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
from gobject import timout_add
|
||||||
|
timeout_add(1000, poll_external, (proc, errstrings))
|
||||||
return
|
return
|
||||||
|
|
||||||
def process_pending_events(max_count=10):
|
def process_pending_events(max_count=10):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user