# HG changeset patch # User paulb # Date 1127493112 0 # Node ID ca83893acc40823976fffd117b4fefea19916a4a # Parent 2f9c5f4def5afa0eeabebee099a9a0e7f9cfba8d [project @ 2005-09-23 16:31:52 by paulb] Initial revision diff -r 2f9c5f4def5a -r ca83893acc40 desktop.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop.py Fri Sep 23 16:31:52 2005 +0000 @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +"Simple desktop integration for Python." + +import os +import subprocess + +def open(url, desktop=None): + + """ + Open the 'url' in the current desktop's preferred file browser. If the + optional 'desktop' parameter is specified then attempt to use that + 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". + """ + + if 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] + + elif desktop == "GNOME" or \ + desktop is None and (os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or + os.environ.has_key("GNOME_KEYRING_SOCKET")): + + cmd = ["gnome-open", url] + + else: + os.startfile(url) + return + + subprocess.Popen(cmd) + +# vim: tabstop=4 expandtab shiftwidth=4