diff --git a/desktop/__init__.py b/desktop/__init__.py index d8bfcc8..49e4545 100755 --- a/desktop/__init__.py +++ b/desktop/__init__.py @@ -42,6 +42,7 @@ desktop.open("http://www.python.org", "KDE") # Insists on KDE desktop.open("http://www.python.org", "GNOME") # Insists on GNOME +desktop.open("http://www.python.org", "MATE") # Insists on MATE Without overriding using the desktop parameter, the open function will attempt to use the "standard" desktop opening mechanism which is controlled by the @@ -115,7 +116,7 @@ def _status(cmd, shell): opener.wait() return opener.poll() == 0 -import commands +import subprocess # Private functions. @@ -135,7 +136,7 @@ def _is_xfce(): # XFCE detection involves testing the output of a program. try: - return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).strip().endswith(' = "xfce4"') + return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).decode("utf-8").strip().endswith(' = "xfce4"') except OSError: return 0 @@ -143,7 +144,7 @@ def _is_x11(): "Return whether the X Window System is in use." - return os.environ.has_key("DISPLAY") + return "DISPLAY" in os.environ # Introspection functions. @@ -154,12 +155,15 @@ def get_desktop(): environment. If no environment could be detected, None is returned. """ - if os.environ.has_key("KDE_FULL_SESSION") or \ - os.environ.has_key("KDE_MULTIHEAD"): + if "KDE_FULL_SESSION" in os.environ or \ + "KDE_MULTIHEAD" in os.environ: return "KDE" - elif os.environ.has_key("GNOME_DESKTOP_SESSION_ID") or \ - os.environ.has_key("GNOME_KEYRING_SOCKET"): + elif "GNOME_DESKTOP_SESSION_ID" in os.environ or \ + "GNOME_KEYRING_SOCKET" in os.environ: return "GNOME" + elif "MATE_DESKTOP_SESSION_ID" in os.environ or \ + "MATE_KEYRING_SOCKET" in os.environ: + return "MATE" elif sys.platform == "darwin": return "Mac OS X" elif hasattr(os, "startfile"): @@ -167,7 +171,7 @@ def get_desktop(): elif _is_xfce(): return "XFCE" - # KDE, GNOME and XFCE run on X11, so we have to test for X11 last. + # KDE, GNOME, MATE and XFCE run on X11, so we have to test for X11 last. if _is_x11(): return "X11" @@ -200,6 +204,8 @@ def use_desktop(desktop): return "KDE" elif (desktop or detected) == "GNOME": return "GNOME" + elif (desktop or detected) == "MATE": + return "MATE" elif (desktop or detected) == "XFCE": return "XFCE" elif (desktop or detected) == "Mac OS X": @@ -216,7 +222,7 @@ def is_standard(): launching. """ - return os.environ.has_key("DESKTOP_LAUNCH") + return "DESKTOP_LAUNCH" in os.environ # Activity functions. @@ -228,11 +234,11 @@ def open(url, desktop=None, wait=0): particular desktop environment's mechanisms to open the 'url' instead of guessing or detecting which environment is being used. - Suggested values for 'desktop' are "standard", "KDE", "GNOME", "XFCE", - "Mac OS X", "Windows" where "standard" employs a DESKTOP_LAUNCH environment - variable to open the specified 'url'. DESKTOP_LAUNCH should be a command, - possibly followed by arguments, and must have any special characters - shell-escaped. + Suggested values for 'desktop' are "standard", "KDE", "GNOME", "GNOME", + "XFCE", "Mac OS X", "Windows" where "standard" employs a DESKTOP_LAUNCH + environment variable to open the specified 'url'. DESKTOP_LAUNCH should + be a command, possibly followed by arguments, and must have any special + characters shell-escaped. The process identifier of the "opener" (ie. viewer, editor, browser or program) associated with the 'url' is returned by this function. If the @@ -249,7 +255,7 @@ def open(url, desktop=None, wait=0): desktop_in_use = use_desktop(desktop) if desktop_in_use == "standard": - arg = "".join([os.environ["DESKTOP_LAUNCH"], commands.mkarg(url)]) + arg = "".join([os.environ["DESKTOP_LAUNCH"], subprocess.mkarg(url)]) return _run(arg, 1, wait) elif desktop_in_use == "Windows": @@ -257,24 +263,30 @@ def open(url, desktop=None, wait=0): return os.startfile(url) elif desktop_in_use == "KDE": - cmd = ["kfmclient", "exec", url] + cmd = ["xdg-open", url] elif desktop_in_use == "GNOME": - cmd = ["gnome-open", url] + cmd = ["xdg-open", url] + + elif desktop_in_use == "MATE": + cmd = ["xdg-open", url] elif desktop_in_use == "XFCE": - cmd = ["exo-open", url] + cmd = ["xdg-open", url] elif desktop_in_use == "Mac OS X": cmd = ["open", url] - elif desktop_in_use == "X11" and os.environ.has_key("BROWSER"): + elif desktop_in_use == "X11" and "BROWSER" in os.environ: cmd = [os.environ["BROWSER"], url] + elif desktop_in_use == "X11": + cmd = ["xdg-open", url] + # Finish with an error where no suitable desktop was identified. else: - raise OSError, "Desktop '%s' not supported (neither DESKTOP_LAUNCH nor os.startfile could be used)" % desktop_in_use + raise OSError("Desktop '%s' not supported (neither DESKTOP_LAUNCH nor os.startfile could be used)" % desktop_in_use) return _run(cmd, 0, wait) diff --git a/desktop/dialog.py b/desktop/dialog.py index 9525004..429ad06 100755 --- a/desktop/dialog.py +++ b/desktop/dialog.py @@ -35,6 +35,7 @@ question.open("KDE") # Insists on KDE question.open("GNOME") # Insists on GNOME +question.open("MATE") # Insists on MATE The dialogue box options are documented in each class's docstring. @@ -241,6 +242,7 @@ class Dialogue: commands = { "KDE" : "kdialog", "GNOME" : "zenity", + "MATE" : "zenity", "XFCE" : "zenity", # NOTE: Based on observations with Xubuntu. "X11" : "Xdialog" } @@ -256,7 +258,7 @@ def open(self, desktop=None): instead of guessing or detecting which environment is being used. Suggested values for 'desktop' are "standard", "KDE", "GNOME", - "Mac OS X", "Windows". + "MATE", "Mac OS X", "Windows". The result of the dialogue interaction may be a string indicating user input (for Input, Password, Menu, Pulldown), a list of strings @@ -278,7 +280,7 @@ def open(self, desktop=None): try: program = self.commands[desktop_in_use] except KeyError: - raise OSError, "Desktop '%s' not supported (no known dialogue box command could be suggested)" % desktop_in_use + raise OSError("Desktop '%s' not supported (no known dialogue box command could be suggested)" % desktop_in_use) # The handler is one of the functions communicating with the subprocess. # Some handlers return boolean values, others strings. @@ -473,7 +475,7 @@ class Pulldown(Menu): "Xdialog" : (_readvalue(_readfrom), ["--stdout", "--combobox", String("text"), Integer("height"), Integer("width"), Strings("items")]), } - item = unicode + item = str number_of_titles = 2 class Input(Simple): @@ -544,6 +546,6 @@ def __init__(self, filename, text="", width=None, height=None): # Supported desktop environments. -supported = Dialogue.commands.keys() +supported = list(Dialogue.commands.keys()) # vim: tabstop=4 expandtab shiftwidth=4 diff --git a/desktop/windows.py b/desktop/windows.py index 2b19e85..029ad34 100755 --- a/desktop/windows.py +++ b/desktop/windows.py @@ -141,7 +141,7 @@ def _get_descendant_handle_and_name(self, line): if match: return self._get_handle_and_name(line[:match.start()].strip()) else: - raise OSError, "Window information from %r did not contain window details." % line + raise OSError("Window information from %r did not contain window details." % line) def _descendants(self, s, fn): handles = [] @@ -258,7 +258,7 @@ def root(desktop=None): if _is_x11(): return Window(None) else: - raise OSError, "Desktop '%s' not supported" % use_desktop(desktop) + raise OSError("Desktop '%s' not supported" % use_desktop(desktop)) def find(callable, desktop=None):