diff options
Diffstat (limited to 'scudcloud-1.1/lib/notifier.py')
-rw-r--r-- | scudcloud-1.1/lib/notifier.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scudcloud-1.1/lib/notifier.py b/scudcloud-1.1/lib/notifier.py new file mode 100644 index 0000000..a67ef5c --- /dev/null +++ b/scudcloud-1.1/lib/notifier.py @@ -0,0 +1,35 @@ +from dbus.exceptions import DBusException +try: + from gi.repository import Notify +except ImportError: + import notify2 + Notify = None + +class Notifier(object): + + def __init__(self, app_name, icon): + self.icon = icon + try: + if Notify is not None: + Notify.init(app_name) + self.notifier = Notify + else: + notify2.init(app_name) + self.notifier = notify2 + self.enabled = True + except DBusException: + print("WARNING: No notification daemon found! " + "Notifications will be ignored.") + self.enabled = False + + def notify(self, title, message, icon=None): + if not self.enabled: + return + if icon is None: + icon = self.icon + if Notify is not None: + notice = self.notifier.Notification.new(title, message, icon) + else: + notice = notify2.Notification(title, message, icon) + notice.set_hint_string('x-canonical-append', '') + notice.show() |