89 lines
2.5 KiB
Python
Executable File
89 lines
2.5 KiB
Python
Executable File
|
|
import gtk
|
|
import gobject
|
|
import imaplib
|
|
|
|
class Window(object):
|
|
def __init__(self, title, conf):
|
|
self.conf = conf
|
|
self.connection = None
|
|
|
|
if not 'width' in self.conf:
|
|
self.conf['width'] = 32
|
|
if not 'height' in self.conf:
|
|
self.conf['height'] = 32
|
|
if not 'mailbox' in self.conf:
|
|
self.conf['mailbox'] = 'Inbox'
|
|
sticky = True
|
|
if 'sticky' in self.conf:
|
|
sticky = self.conf['sticky']
|
|
|
|
self.window = gtk.Window()
|
|
self.window.set_title(title)
|
|
self.window.set_decorated(False)
|
|
if sticky:
|
|
self.window.stick()
|
|
self.window.connect('destroy', self.destroy_event)
|
|
self.window.connect('button-release-event', self.button_release)
|
|
self.window.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
|
|
|
|
self.label = gtk.Label('-')
|
|
|
|
self.window.add(self.label)
|
|
|
|
self.connect()
|
|
|
|
self.window.show_all()
|
|
|
|
if 'x' in self.conf and 'y' in self.conf:
|
|
self.window.move(self.conf['x'], self.conf['y'])
|
|
self.window.resize(self.conf['width'], self.conf['height'])
|
|
|
|
def run(self):
|
|
gtk.main()
|
|
|
|
def connect(self):
|
|
try:
|
|
self.connection = imaplib.IMAP4_SSL(
|
|
self.conf['server'], self.conf['port'])
|
|
self.connection.login(self.conf['user'], self.conf['password'])
|
|
self.update()
|
|
gobject.timeout_add(5000, self.update)
|
|
except:
|
|
self.connection = None
|
|
|
|
def disconnect(self):
|
|
if self.connection is not None:
|
|
self.connection = None
|
|
|
|
def update_conf(self):
|
|
w, h = self.window.get_size()
|
|
self.conf['width'] = w
|
|
self.conf['height'] = h
|
|
x, y = self.window.get_position()
|
|
self.conf['x'] = x
|
|
self.conf['y'] = y
|
|
|
|
def update(self):
|
|
if self.connection is not None:
|
|
try:
|
|
self.connection.select(self.conf['mailbox'])
|
|
msgs = self.connection.search(None, 'UnSeen')[1][0].split()
|
|
count = len(msgs)
|
|
self.label.set_text(str(count))
|
|
except:
|
|
self.connection = None
|
|
self.label.set_text('-')
|
|
return self.connection is not None
|
|
|
|
def destroy_event(self):
|
|
self.disconnect()
|
|
self.update_conf()
|
|
gtk.main_quit()
|
|
return False
|
|
|
|
def button_release(self, widget, event):
|
|
if event.button == 3:
|
|
self.destroy_event()
|
|
return True
|