[kupfer] Introduce uiutils.show_notification



commit 8f3d36a3c2d28912667642c36003093e51aed75f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Feb 13 15:38:50 2010 +0100

    Introduce uiutils.show_notification
    
    Use D-Bus API to use the org.freedesktop.Notifications service.

 kupfer/uiutils.py |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/uiutils.py b/kupfer/uiutils.py
index 047afb4..49a609c 100644
--- a/kupfer/uiutils.py
+++ b/kupfer/uiutils.py
@@ -10,6 +10,7 @@ import glib
 import gtk
 import pango
 
+from kupfer import pretty
 from kupfer import config, version
 from kupfer.ui import keybindings
 
@@ -171,3 +172,26 @@ def show_large_type(text):
 	window.show_all()
 	window.present_with_time(_get_current_event_time())
 
+SERVICE_NAME = "org.freedesktop.Notifications"
+OBJECT_PATH = "/org/freedesktop/Notifications"
+IFACE_NAME = "org.freedesktop.Notifications"
+def _get_notification_iface():
+	"we will activate it over d-bus (start if not running)"
+	import dbus
+	try:
+		bus = dbus.SessionBus()
+		proxy_obj = bus.get_object(SERVICE_NAME, OBJECT_PATH)
+	except dbus.DBusException, e:
+		pretty.print_debug(__name__, e)
+		return
+	iface_obj = dbus.Interface(proxy_obj, IFACE_NAME)
+	return iface_obj
+
+def show_notification(title, text="", icon_name=""):
+	notifications = _get_notification_iface()
+	if not notifications:
+		return None
+	rid = notifications.Notify("kupfer", 0, icon_name, title, text, (), {}, -1)
+	return rid
+
+



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