fwarren icon

Pidgin dDus Notification TrayIcon

fwarren | PRO | 01/13/16 07:29:06 PM UTC | 0 ⭐ | 253 👁️ | Never ⏰ | []
Python |

2.91 KB

|

None

|

0 👍

/

0 👎

#
# simple d-busified pidgin message notifier
#
# displays a tray icon in the notification area 
# and will flash the icon when a new message comes in
# until the tryicon is clicked
#
# Adapted from Thomas Perl <[email protected]> 2007-03-28
#
# See http://thpinfo.com/2007/hacks/ for updates
#
# See http://askubuntu.com/questions/108764/how-do-i-send-text-messages-to-the-notification-bubbles 
# for notes on python3
#
# See https://github.com/kholidfu/githon/blob/master/notifikasi_kurs.py for desktop notification
 
import dbus
import dbus.glib
import dbus.decorators
import pynotify
import gobject
import gtk
import os
import os.path
import glob
import random
import time
import sys
 
pynotify.init('purple-imrecvd')
notification = None
flash_icon_timer = 0
 
bus = dbus.SessionBus()
 
icon = gtk.StatusIcon()
icon.set_visible( True)
icon.set_from_icon_name( 'user-invisible')
icon.set_tooltip( 'No new messages')
 
def update_tooltip(show_notification = True):
    global notification, icon, flash_icon_timer
    message = 'You have new IM messages'
    notification = pynotify.Notification( 'New IM received!', message)
    icon.set_from_icon_name('user-available')
    icon.set_blinking(True)
    icon.set_tooltip( 'New messages received')
    flash_icon_timer = gobject.timeout_add(5000, flash_icon)
    return False
 
def flash_icon():
    global flash_icon_timer, icon
    gobject.source_remove(flash_icon_timer)
    icon.set_blinking(False)
 
def messaeg_received(account, sender, message, conversation, flags):
    global notification
    gobject.idle_add(update_tooltip)
 
def message_read(): # this code never run
    global notification, icon
    update_tooltip()
    gobject.idle_add( update_tooltip, False)
 
def activate(icon):
    global notification 
    if icon.get_tooltip_text() == 'New messages received':
        icon.set_blinking(False)
        icon.set_tooltip('No new messages')
        icon.set_from_icon_name( 'user-invisible')
 
def destroyer(dialogobj, response_id, data=None):
    global loop, dialog
    if response_id == gtk.RESPONSE_OK:
        loop.quit()
    else:
        dialog.hide()
 
def popup(button, widget, data=None):
    global icon, dialog
    dialog = gtk.MessageDialog(
             parent = None,
             flags = gtk.DIALOG_DESTROY_WITH_PARENT,
             type = gtk.MESSAGE_INFO,
             buttons = gtk.BUTTONS_OK_CANCEL,
             message_format = "Do you want to Exit?")
    dialog.set_title('Popup Window')
    dialog.connect('response', destroyer)
    dialog.show()
 
icon.connect("activate", activate)
icon.connect("popup_menu", popup)
 
bus.add_signal_receiver( messaeg_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
bus.add_signal_receiver( messaeg_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedChatMsg")
 
loop = gobject.MainLoop()
loop.run()

Comments