1 #!/usr/bin/env python 2 3 "Simple desktop integration for Python." 4 5 import os 6 import subprocess 7 8 def open(url, desktop=None): 9 10 """ 11 Open the 'url' in the current desktop's preferred file browser. If the 12 optional 'desktop' parameter is specified then attempt to use that 13 particular desktop environment's mechanisms to open the 'url' instead of 14 guessing or detecting which environment is being used. 15 16 Suggested values for 'desktop' are "KDE" and "GNOME". 17 """ 18 19 if desktop == "KDE" or \ 20 desktop is None and (os.environ.has_key("KDE_FULL_SESSION") or 21 os.environ.has_key("KDE_MULTIHEAD")): 22 23 cmd = ["kfmclient", "openURL", url] 24 25 elif desktop == "GNOME" or \ 26 desktop is None and (os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or 27 os.environ.has_key("GNOME_KEYRING_SOCKET")): 28 29 cmd = ["gnome-open", url] 30 31 else: 32 os.startfile(url) 33 return 34 35 subprocess.Popen(cmd) 36 37 # vim: tabstop=4 expandtab shiftwidth=4