[kupfer] utils: Show startup notification when launching Help Browser



commit 227edf60a0782464ece51f616bfff6e98846cd15
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 21 15:22:40 2011 +0100

    utils: Show startup notification when launching Help Browser
    
    Try at length to show a startup notification when the help browser is
    started. We check the system handler for ghelp: URLs and if it matches
    yelp.desktop, we notify.
    
    At the same time, introduce the function utils.lookup_exec_path to
    search the executable path.

 kupfer/kupferui.py       |    2 +-
 kupfer/plugin_support.py |    9 ++-------
 kupfer/utils.py          |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/kupfer/kupferui.py b/kupfer/kupferui.py
index a54739c..84eb392 100644
--- a/kupfer/kupferui.py
+++ b/kupfer/kupferui.py
@@ -9,7 +9,7 @@ def show_help():
 	"""
 	Show Kupfer help pages, if possible
 	"""
-	if not utils.show_url("ghelp:%s" % version.PACKAGE_NAME):
+	if not utils.show_help_url("ghelp:%s" % version.PACKAGE_NAME):
 		utils.show_url(version.HELP_WEBSITE)
 
 _about_dialog = None
diff --git a/kupfer/plugin_support.py b/kupfer/plugin_support.py
index 2fc39f2..7d3d6d6 100644
--- a/kupfer/plugin_support.py
+++ b/kupfer/plugin_support.py
@@ -12,7 +12,7 @@ from kupfer import pretty
 from kupfer import config
 from kupfer.core import settings
 from kupfer.core import plugins
-from kupfer import terminal
+from kupfer import utils
 
 __all__ = [
 	"UserNamePassword",
@@ -192,12 +192,7 @@ def _is_valid_terminal(term_dict):
 	if len(term_dict["argv"]) < 1:
 		return False
 	exe = term_dict["argv"][0]
-	# iterate over $PATH directories
-	PATH = os.environ.get("PATH") or os.defpath
-	for execdir in PATH.split(os.pathsep):
-		exepath = os.path.join(execdir, exe)
-		if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath):
-			return True
+	return bool(utils.lookup_exec_path(exe))
 
 
 _available_alternatives = {
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 64262be..8ccb7e9 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -265,6 +265,42 @@ def show_url(url):
 	except GError, exc:
 		pretty.print_error(__name__, "gtk.show_uri:", exc)
 
+def show_help_url(url):
+	"""
+	Try at length to display a startup notification for the help browser.
+
+	Return False if there is no handler for the help URL
+	"""
+	import gio
+	## Check that the system help viewer is Yelp,
+	## and if it is, launch its startup notification.
+	scheme = gio.File(url).get_uri_scheme()
+	default = gio.app_info_get_default_for_uri_scheme(scheme)
+	help_viewer_id = "yelp.desktop"
+	if not default:
+		return False
+	try:
+		yelp = gio.unix.DesktopAppInfo(help_viewer_id)
+	except RuntimeError:
+		return show_url(url)
+	cmd_path = lookup_exec_path(default.get_executable())
+	yelp_path = lookup_exec_path(yelp.get_executable())
+	if cmd_path and yelp_path and os.path.samefile(cmd_path, yelp_path):
+		try:
+			spawn_async_notify_as(help_viewer_id, [cmd_path, url])
+			return True
+		except SpawnError:
+			pass
+	return show_url(url)
+
+def lookup_exec_path(exename):
+	"Return path for @exename in $PATH or None"
+	PATH = os.environ.get("PATH") or os.defpath
+	for execdir in PATH.split(os.pathsep):
+		exepath = os.path.join(execdir, exename)
+		if os.access(exepath, os.R_OK|os.X_OK) and os.path.isfile(exepath):
+			return exepath
+
 def is_directory_writable(dpath):
 	"""If directory path @dpath is a valid destination to write new files?
 	"""



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]