fwarren icon

Tray Icon for Finch

fwarren | PRO | 08/16/16 08:01:39 PM UTC | 0 ⭐ | 314 👁️ | Never ⏰ | []
Python |

3.76 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/python2
#
# simple d-busified evolution mail notifier
#
# notifies you about incoming mail with a sound and 
# displays a tray icon in the notification area until
# you read some message in evolution again
#
# Thomas Perl <[email protected]> 2007-03-28
#
# See http://thpinfo.com/2007/hacks/ for updates
#
# Changes:
#
# 2007-04-20
#   + Better unread tracking
#   + new_mail_folders handling
#   + Use pynotify for neat notifications
#   + Customizable wave sounds
#
# 2007-08-29
#   + Add wave file playing limit
#
# 2007-09-13
#   + Add support for getting X11 idle time
#     -> skip sound playback when idle
#   + Add support for getting X11 focused window class
#     -> skip notification display when evolution is focused
#
# http://www.pygtk.org/pygtk2reference/
 
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')
    if flash_icon_timer != 0:
        gobject.source_remove(flash_icon_timer)
        flash_icon_timer = 0
    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)
    flash_icon_timer = 0
    icon.set_blinking(False)
 
# fired when new IM comes in via dBus
def message_received(account, sender, message, conversation, flags):
    global notification
    gobject.idle_add(update_tooltip)
 
# fired when new IM is sent
def message_sent(account, message, id):
    global icon
    activate(icon);
 
def newmail_read(): # this code never run
    global notification, icon
    update_tooltip()
    gobject.idle_add( update_tooltip, False)
 
# stop flashing or indication that a message has been received
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( message_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
bus.add_signal_receiver( message_received, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedChatMsg")
bus.add_signal_receiver( message_sent, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="SendingImMsg")
bus.add_signal_receiver( message_sent, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="SendingChatMsg")
loop = gobject.MainLoop()
loop.run()

Comments