desktop

Changeset

4:766652605138
2005-09-25 paulb raw files shortlog changelog graph [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.
README.txt (file) desktop.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/README.txt	Sun Sep 25 14:20:18 2005 +0000
     1.3 @@ -0,0 +1,10 @@
     1.4 +Notes on desktop application/environment support:
     1.5 +
     1.6 +KDE           Supports file and URL opening using kfmclient, where the openURL
     1.7 +              command opens the resource and the exec command runs the
     1.8 +              resource.
     1.9 +
    1.10 +GNOME         Supports file and URL opening using gnome-open.
    1.11 +
    1.12 +ROX-Filer     Supports file opening using "rox <filename>" but not URL
    1.13 +              opening.
     2.1 --- a/desktop.py	Sat Sep 24 16:30:47 2005 +0000
     2.2 +++ b/desktop.py	Sun Sep 25 14:20:18 2005 +0000
     2.3 @@ -3,6 +3,7 @@
     2.4  "Simple desktop integration for Python."
     2.5  
     2.6  import os
     2.7 +import sys
     2.8  import subprocess
     2.9  
    2.10  def open(url, desktop=None):
    2.11 @@ -13,18 +14,30 @@
    2.12      particular desktop environment's mechanisms to open the 'url' instead of
    2.13      guessing or detecting which environment is being used.
    2.14  
    2.15 -    Suggested values for 'desktop' are "KDE" and "GNOME".
    2.16 +    Suggested values for 'desktop' are "KDE", "GNOME", "Mac OS X" and "generic",
    2.17 +    where "generic" uses an OPENER environment variable to open the specified
    2.18 +    'url'.
    2.19  
    2.20      The process identifier of the "opener" (ie. viewer, editor, browser or
    2.21      program) associated with the 'url' is returned by this function. If the
    2.22      process identifier cannot be determined, None is returned.
    2.23      """
    2.24  
    2.25 -    if desktop == "KDE" or \
    2.26 +    if desktop == "generic" or \
    2.27 +        desktop is None and os.environ.has_key("OPENER"):
    2.28 +
    2.29 +        try:
    2.30 +            # NOTE: This may not handle sophisticated commands properly.
    2.31 +            cmd = os.environ["OPENER"].split()
    2.32 +            cmd.append(url)
    2.33 +        except KeyError, exc:
    2.34 +            raise OSError, "Desktop not supported (OPENER could not be used)"
    2.35 +
    2.36 +    elif desktop == "KDE" or \
    2.37          desktop is None and (os.environ.has_key("KDE_FULL_SESSION") or
    2.38              os.environ.has_key("KDE_MULTIHEAD")):
    2.39  
    2.40 -        cmd = ["kfmclient", "openURL", url]
    2.41 +        cmd = ["kfmclient", "exec", url]
    2.42  
    2.43      elif desktop == "GNOME" or \
    2.44          desktop is None and (os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or
    2.45 @@ -32,6 +45,11 @@
    2.46  
    2.47          cmd = ["gnome-open", url]
    2.48  
    2.49 +    elif desktop == "Mac OS X" or \
    2.50 +        desktop is None and sys.platform == "darwin":
    2.51 +
    2.52 +        cmd = ["open", url]
    2.53 +
    2.54      else:
    2.55          try:
    2.56              # NOTE: This returns None in current implementations.