# HG changeset patch # User paulb # Date 1127658018 0 # Node ID 7666526051387187fb0e8853e264081ed2fc1009 # Parent c81d5b8d261ac12a771c22a43c46524fb4fa332b [project @ 2005-09-25 14:20:18 by paulb] Added some documentation. Changed "kfmclient openURL" to "kfmclient exec". Added a "generic" option which uses the proposed OPENER environment variable. Added Mac OS X support. diff -r c81d5b8d261a -r 766652605138 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Sun Sep 25 14:20:18 2005 +0000 @@ -0,0 +1,10 @@ +Notes on desktop application/environment support: + +KDE Supports file and URL opening using kfmclient, where the openURL + command opens the resource and the exec command runs the + resource. + +GNOME Supports file and URL opening using gnome-open. + +ROX-Filer Supports file opening using "rox " but not URL + opening. diff -r c81d5b8d261a -r 766652605138 desktop.py --- a/desktop.py Sat Sep 24 16:30:47 2005 +0000 +++ b/desktop.py Sun Sep 25 14:20:18 2005 +0000 @@ -3,6 +3,7 @@ "Simple desktop integration for Python." import os +import sys import subprocess def open(url, desktop=None): @@ -13,18 +14,30 @@ particular desktop environment's mechanisms to open the 'url' instead of guessing or detecting which environment is being used. - Suggested values for 'desktop' are "KDE" and "GNOME". + Suggested values for 'desktop' are "KDE", "GNOME", "Mac OS X" and "generic", + where "generic" uses an OPENER environment variable to open the specified + 'url'. The process identifier of the "opener" (ie. viewer, editor, browser or program) associated with the 'url' is returned by this function. If the process identifier cannot be determined, None is returned. """ - if desktop == "KDE" or \ + if desktop == "generic" or \ + desktop is None and os.environ.has_key("OPENER"): + + try: + # NOTE: This may not handle sophisticated commands properly. + cmd = os.environ["OPENER"].split() + cmd.append(url) + except KeyError, exc: + raise OSError, "Desktop not supported (OPENER could not be used)" + + elif desktop == "KDE" or \ desktop is None and (os.environ.has_key("KDE_FULL_SESSION") or os.environ.has_key("KDE_MULTIHEAD")): - cmd = ["kfmclient", "openURL", url] + cmd = ["kfmclient", "exec", url] elif desktop == "GNOME" or \ desktop is None and (os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or @@ -32,6 +45,11 @@ cmd = ["gnome-open", url] + elif desktop == "Mac OS X" or \ + desktop is None and sys.platform == "darwin": + + cmd = ["open", url] + else: try: # NOTE: This returns None in current implementations.