1.1 --- a/desktop.py Fri Nov 11 12:09:35 2005 +0000
1.2 +++ b/desktop.py Fri Nov 11 12:27:29 2005 +0000
1.3 @@ -92,7 +92,18 @@
1.4
1.5 return os.environ.has_key("DESKTOP_LAUNCH")
1.6
1.7 -def open(url, desktop=None):
1.8 +def _wait(pid, block):
1.9 +
1.10 + """
1.11 + Perform a blocking Wait for the given process identifier, 'pid', if the
1.12 + 'block' flag is set to a true value. Return the process identifier.
1.13 + """
1.14 +
1.15 + if block:
1.16 + os.waitpid(pid, os.P_WAIT)
1.17 + return pid
1.18 +
1.19 +def open(url, desktop=None, wait=1):
1.20
1.21 """
1.22 Open the 'url' in the current desktop's preferred file browser. If the
1.23 @@ -108,6 +119,11 @@
1.24 The process identifier of the "opener" (ie. viewer, editor, browser or
1.25 program) associated with the 'url' is returned by this function. If the
1.26 process identifier cannot be determined, None is returned.
1.27 +
1.28 + An optional 'wait' parameter is also available for advanced usage and, if
1.29 + 'wait' is set to a false value, this function will not wait for the
1.30 + launching mechanism to complete before returning (as opposed to waiting and
1.31 + then returning, as is the default behaviour).
1.32 """
1.33
1.34 # Attempt to detect a desktop environment.
1.35 @@ -118,7 +134,7 @@
1.36
1.37 if (desktop is None or desktop == "standard") and is_standard():
1.38 arg = "".join([os.environ["DESKTOP_LAUNCH"], commands.mkarg(url)])
1.39 - return subprocess.Popen(arg, shell=1).pid
1.40 + return _wait(subprocess.Popen(arg, shell=1).pid, wait)
1.41
1.42 elif (desktop is None or desktop == "Windows") and detected == "Windows":
1.43 # NOTE: This returns None in current implementations.
1.44 @@ -140,6 +156,6 @@
1.45 else:
1.46 raise OSError, "Desktop not supported (neither DESKTOP_LAUNCH nor os.startfile could be used)"
1.47
1.48 - return subprocess.Popen(cmd).pid
1.49 + return _wait(subprocess.Popen(cmd).pid, wait)
1.50
1.51 # vim: tabstop=4 expandtab shiftwidth=4