fwarren

Pidgin dDus Notification TrayIcon

Jan 13th, 2016
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. #
  2. # simple d-busified pidgin message notifier
  3. #
  4. # displays a tray icon in the notification area
  5. # and will flash the icon when a new message comes in
  6. # until the tryicon is clicked
  7. #
  8. # Adapted from Thomas Perl <[email protected]> 2007-03-28
  9. #
  10. # See http://thpinfo.com/2007/hacks/ for updates
  11. #
  12. # See http://askubuntu.com/questions/108764/how-do-i-send-text-messages-to-the-notification-bubbles
  13. # for notes on python3
  14. #
  15. # See https://github.com/kholidfu/githon/blob/master/notifikasi_kurs.py for desktop notification
  16.  
  17. import dbus
  18. import dbus.glib
  19. import dbus.decorators
  20. import pynotify
  21. import gobject
  22. import gtk
  23. import os
  24. import os.path
  25. import glob
  26. import random
  27. import time
  28. import sys
  29.  
  30. pynotify.init('purple-imrecvd')
  31. notification = None
  32. flash_icon_timer = 0
  33.  
  34. bus = dbus.SessionBus()
  35.  
  36. icon = gtk.StatusIcon()
  37. icon.set_visible( True)
  38. icon.set_from_icon_name( 'user-invisible')
  39. icon.set_tooltip( 'No new messages')
  40.  
  41. def update_tooltip(show_notification = True):
  42.     global notification, icon, flash_icon_timer
  43.     message = 'You have new IM messages'
  44.     notification = pynotify.Notification( 'New IM received!', message)
  45.     icon.set_from_icon_name('user-available')
  46.     icon.set_blinking(True)
  47.     icon.set_tooltip( 'New messages received')
  48.     flash_icon_timer = gobject.timeout_add(5000, flash_icon)
  49.     return False
  50.  
  51. def flash_icon():
  52.     global flash_icon_timer, icon
  53.     gobject.source_remove(flash_icon_timer)
  54.     icon.set_blinking(False)
  55.  
  56. def messaeg_received(account, sender, message, conversation, flags):
  57.     global notification
  58.     gobject.idle_add(update_tooltip)
  59.  
  60. def message_read(): # this code never run
  61.     global notification, icon
  62.     update_tooltip()
  63.     gobject.idle_add( update_tooltip, False)
  64.  
  65. def activate(icon):
  66.     global notification
  67.     if icon.get_tooltip_text() == 'New messages received':
  68.         icon.set_blinking(False)
  69.         icon.set_tooltip('No new messages')
  70.         icon.set_from_icon_name( 'user-invisible')
  71.  
  72. def destroyer(dialogobj, response_id, data=None):
  73.     global loop, dialog
  74.     if response_id == gtk.RESPONSE_OK:
  75.         loop.quit()
  76.     else:
  77.         dialog.hide()
  78.  
  79. def popup(button, widget, data=None):
  80.     global icon, dialog
  81.     dialog = gtk.MessageDialog(
  82.              parent = None,
  83.              flags = gtk.DIALOG_DESTROY_WITH_PARENT,
  84.              type = gtk.MESSAGE_INFO,
  85.              buttons = gtk.BUTTONS_OK_CANCEL,
  86.              message_format = "Do you want to Exit?")
  87.     dialog.set_title('Popup Window')
  88.     dialog.connect('response', destroyer)
  89.     dialog.show()
  90.  
  91. icon.connect("activate", activate)
  92. icon.connect("popup_menu", popup)
  93.  
  94. bus.add_signal_receiver( messaeg_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
  95. bus.add_signal_receiver( messaeg_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedChatMsg")
  96.  
  97. loop = gobject.MainLoop()
  98. loop.run()
Add Comment
Please, Sign In to add comment