[kupfer] notification: A simple plugin to show notifications



commit d49caaea8685eb40a731eb4b57e887a99b3a546e
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Jan 16 21:51:53 2010 +0100

    notification: A simple plugin to show notifications
    
    For now, this plugin uses pynotify. Notifications will eventually go
    into Kupfer's core and then we will reevaluate a solution.

 kupfer/plugin/notification.py |   46 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/notification.py b/kupfer/plugin/notification.py
new file mode 100644
index 0000000..60c6a13
--- /dev/null
+++ b/kupfer/plugin/notification.py
@@ -0,0 +1,46 @@
+from kupfer.objects import Action
+from kupfer.objects import TextLeaf
+from kupfer import textutils
+
+__kupfer_name__ = _("Show Notification")
+__kupfer_actions__ = (
+		"ShowNotification",
+	)
+__description__ = ""
+__version__ = ""
+__author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
+
+import pynotify
+
+
+def show_notification(title, body, icon_name=None, critical=False):
+	if not pynotify.is_initted():
+		pynotify.init("kupfer")
+	notification = pynotify.Notification(title)
+	if body:
+		notification.set_property("body", body)
+	if icon_name:
+		notification.set_property("icon-name", icon_name)
+	if critical:
+		notification.set_urgency(pynotify.URGENCY_CRITICAL)
+	notification.show()
+
+
+class ShowNotification (Action):
+	def __init__(self):
+		Action.__init__(self, _("Show Notification"))
+
+	def activate(self, leaf):
+		title, body = textutils.extract_title_body(leaf.object)
+		if body:
+			show_notification(title, body, icon_name=self.get_icon_name())
+		else:
+			show_notification(title, None)
+
+	def item_types(self):
+		#if plugin_support.has_capability("NOTIFICATION"):
+		yield TextLeaf
+
+	def get_icon_name(self):
+		return "gtk-bold"
+



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