Advertisement
Guest User

notification.py

a guest
Mar 29th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. #Edited by Michele Bovo <madnessmike4ever@gmail.com>
  2. #Changed notification system for better integrating it into Gnome-shell
  3. from cloudsn import logger
  4. from cloudsn.core.sound import Sound
  5. from cloudsn.core import config
  6. from datetime import datetime
  7.  
  8. notifications = []
  9. disable = True
  10. notifying = False
  11. last_notify = tstart = datetime.now()
  12.  
  13. try:
  14.     import pynotify
  15.     if pynotify.init("Cloud Services Notifications"):
  16.         disable = False
  17.     else:
  18.         logger.error("Cannot initialize libnotify")
  19. except Exception, e:
  20.     logger.exception ("there was a problem initializing the pynotify module: %s" % (e))
  21.  
  22.  
  23. #def notify_closed_cb (n, data=None):
  24. #    global notifications, notifying
  25. #    notifying = False
  26. #    if n in notifications:
  27. #        notifications.remove (n)
  28. #    n = None
  29. #    notify_process()
  30.  
  31. def notify_process ():
  32.     global notifications, notifying, last_notify
  33.  
  34.     if len(notifications) == 0:
  35.         return;
  36.  
  37. #    if notifying == True:
  38. #        #See Bug #622021 on gnome
  39. #        diff = datetime.now() - last_notify
  40. #        if diff.seconds > 30:
  41. #            logger.debug("30 seconds from the last notification, reactivating")
  42. #            notifying = False
  43. #        else:
  44. #            return
  45.    
  46.     while len(notifications) > 0:
  47.         n = notifications.pop(0)
  48.         #n.connect("closed", notify_closed_cb)
  49.         n.show()
  50.  
  51.     notifying= True
  52.     last_notify = datetime.now()
  53.     #TODO Do it better and configuable
  54.     sound = Sound()
  55.     sound.play(config.add_data_prefix("drip.ogg"))
  56.  
  57. def notify (title, message, icon = None):
  58.     if disable == True:
  59.         raise NotificationError ("there was a problem initializing the pynotify module")
  60.  
  61.     global notifications
  62.     n = pynotify.Notification(title, message)
  63.     n.set_urgency(pynotify.URGENCY_LOW)
  64.     #n.set_timeout(3000)
  65.  
  66.     if icon:
  67.         n.set_icon_from_pixbuf(icon)
  68.  
  69.     notifications.append(n)
  70.     notify_process()
  71.  
  72. class NotificationError(Exception): pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement