All pastes #1807231 Raw Edit

fer

public python v1 · immutable
#1807231 ·published 2010-02-23 20:00 UTC
rendered paste body
#!/usr/bin/env python import gobjectimport gtk import subprocessclass StatusIcc:     # activate callback     def activate( self, widget, data=None): 	subprocess.Popen (["emacs", "-f", "notmuch"])	self.reader_opened_at = self.notmuch.get_unread_mail_count ()        self.staticon.set_visible(False)     def update_count (self):	if notmuch.get_unread_mail_count () > 0 and self.notmuch.get_unread_mail_count () != self.reader_opened_at:		self.staticon.set_visible(True)		self.staticon.set_tooltip ("%s messages in Inbox, %s Unread" % (self.notmuch.get_inbox_mail_count (), self.notmuch.get_unread_mail_count ()))	else:		self.staticon.set_visible(False)	return True	    def __init__(self, notmuch):         # create a new Status Icon         self.staticon = gtk.StatusIcon()         self.staticon.set_from_stock(gtk.STOCK_ABOUT)         self.staticon.connect("activate", self.activate)         self.staticon.set_visible(False) 	self.notmuch = notmuch	self.reader_opened_at = 0        # invoking the main() 	id = gobject.timeout_add (1000, self.update_count)        gtk.main() class NotMuch:	def get_mail(self):		state = "INIT"		while True:			if state == "INIT":				self.getmail = subprocess.Popen("getmail", shell = True)				state = "GETMAIL_RUNNING"			if state == "GETMAIL_RUNNING":				self.getmail.poll()				if self.getmail.returncode is not None:					state = "GETMAIL_DONE"			if state == "GETMAIL_DONE":				self.notmuch_new = subprocess.Popen(["notmuch", "new"])				state = "NOTMUCH_NEW_RUNNING"			if state == "NOTMUCH_NEW_RUNNING":				self.notmuch_new.poll()				if self.notmuch_new.returncode is not None:					state = "NOTMUCH_NEW_DONE"			if state == "NOTMUCH_NEW_DONE":				self.notmuch_count = subprocess.Popen(["notmuch", "count", "tag:inbox"], stdout = subprocess.PIPE)				state = "NOTMUCH_COUNT_RUNNING"			if state == "NOTMUCH_COUNT_RUNNING":				self.inbox_email_count = self.notmuch_count.communicate()[0].rstrip()				if self.notmuch_count.returncode is not None:					state = "NOTMUCH_COUNT_DONE"			if state == "NOTMUCH_COUNT_DONE":				self.notmuch_count2 = subprocess.Popen(["notmuch", "count", "tag:inbox", "AND", "tag:unread"], stdout = subprocess.PIPE)				state = "NOTMUCH_COUNT2_RUNNING"			if state == "NOTMUCH_COUNT2_RUNNING":				self.unread_email_count = self.notmuch_count2.communicate()[0].rstrip()				if self.notmuch_count2.returncode is not None:					state = "DONE"			if state == "DONE":				return True	def get_inbox_mail_count (self):		return self.inbox_email_count	def get_unread_mail_count (self):		return self.unread_email_count			def __init__(self):		self.new_mail_count = 0		self.unred_mail_count = 0		self.get_mail ()		id = gobject.timeout_add (60000, self.get_mail)		if __name__ == "__main__": 	notmuch = NotMuch ()	statusicon = StatusIcc (notmuch)