From 2c7b0fcef92efccb53a7c37b9ff08b20c26c70b1 Mon Sep 17 00:00:00 2001 From: enkore Date: Fri, 15 Feb 2013 21:06:52 +0100 Subject: [PATCH] Added yet another module type, fixed notmuch module (Yeah, I'm really lazy today) --- i3pystatus/__init__.py | 12 ++++++++++++ i3pystatus/{notmuchmailchecker.py => notmuch.py} | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) rename i3pystatus/{notmuchmailchecker.py => notmuch.py} (90%) diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index c6cccff..ffeee6f 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -4,6 +4,7 @@ import sys import json import urllib.request, urllib.error, urllib.parse from threading import Thread +import time class BaseModule: output = None @@ -26,6 +27,17 @@ class AsyncModule(BaseModule): def mainloop(self): """This is run in a separate daemon-thread""" +class IntervalModule(AsyncModule): + interval = 5 # seconds + + def run(self): + """Called every self.interval seconds""" + + def mainloop(self): + while True: + self.run() + time.sleep(self.interval) + class I3statusHandler: modules = [] diff --git a/i3pystatus/notmuchmailchecker.py b/i3pystatus/notmuch.py similarity index 90% rename from i3pystatus/notmuchmailchecker.py rename to i3pystatus/notmuch.py index 51e59b0..2633bd9 100644 --- a/i3pystatus/notmuchmailchecker.py +++ b/i3pystatus/notmuch.py @@ -6,7 +6,9 @@ import notmuch import json -class NotmuchMailChecker(object): +from i3pystatus import IntervalModule + +class NotmuchMailChecker(IntervalModule): """ This class uses the notmuch python bindings to check for the number of messages in the notmuch database with the tags "inbox" @@ -18,7 +20,7 @@ class NotmuchMailChecker(object): def __init__(self, db_path): self.db_path = db_path - def output(self): + def run(self): db = notmuch.Database(self.db_path) unread = notmuch.Query(db, 'tag:unread and tag:inbox').count_messages()