diff --git a/i3pystatus/batterychecker.py b/i3pystatus/batterychecker.py index 38ae486..3f05190 100644 --- a/i3pystatus/batterychecker.py +++ b/i3pystatus/batterychecker.py @@ -42,8 +42,10 @@ class BatteryChecker(IntervalModule): battery status """ - def __init__(self, battery_ident="BAT0"): - self.battery_ident = battery_ident + settings = ("battery_ident",) + battery_ident = "BAT0" + + def init(self): self.base_path = "/sys/class/power_supply/{0}/uevent".format(self.battery_ident) def run(self): diff --git a/i3pystatus/clock.py b/i3pystatus/clock.py index 13a3263..40a1e06 100644 --- a/i3pystatus/clock.py +++ b/i3pystatus/clock.py @@ -9,23 +9,25 @@ class Clock(IntervalModule): """ This class shows a clock """ - - def __init__(self, format_string=None): + + settings = ("format",) + format = None + + def init(self): lang = os.environ.get('LANG', None) if lang: locale.setlocale(locale.LC_ALL, lang) - if not format_string: + if self.format is not None: lang = locale.getlocale()[0] if lang == 'en_US': # MDY format - United States of America - format_string = "%a %b %-d %X" + self.format = "%a %b %-d %X" else: # DMY format - almost all other countries - format_string = "%a %-d %b %X" - self.format_string = format_string + self.format = "%a %-d %b %X" def run(self): - full_text = datetime.datetime.now().strftime(self.format_string) + full_text = datetime.datetime.now().strftime(self.format) self.output = { "full_text": full_text, "name": "pyclock", diff --git a/i3pystatus/mailchecker.py b/i3pystatus/mailchecker.py index 8b12d57..2f52b77 100644 --- a/i3pystatus/mailchecker.py +++ b/i3pystatus/mailchecker.py @@ -15,25 +15,22 @@ class MailChecker(IntervalModule): functionality is implemented in the subclass MailChecker.MailServer """ - settings = { - "color": "#ff0000", - "servers": [] - } + settings = ("color", "servers") + required = ("servers",) + color = "#ff0000" - def __init__(self, settings = None): - self.settings.update(settings) - - self.servers = list(map(MailChecker.MailServer, settings["servers"])) + def init(self): + self.server_list = list(map(MailChecker.MailServer, self.servers)) def run(self): - unread = sum(map(lambda server: server.get_unread_count(), self.servers)) + unread = sum(map(lambda server: server.get_unread_count(), self.server_list)) if unread: self.output = { "full_text" : "%d new email%s" % (unread, ("s" if unread > 1 else "")), "name" : "newmail", "urgent" : "true", - "color" : self.settings["color"] + "color" : self.color } class MailServer: diff --git a/i3pystatus/modsde.py b/i3pystatus/modsde.py index 5df718c..23fc3ad 100644 --- a/i3pystatus/modsde.py +++ b/i3pystatus/modsde.py @@ -17,20 +17,20 @@ class ModsDeChecker(IntervalModule): unread posts in any bookmark in the mods.de forums. """ + settings = ("color", "offset", "format", "username", "password") + required = ("username", "password") + + color = "#7181fe" + offset = 0 + format = "%d new posts in bookmarks" + login_url = "http://login.mods.de/" bookmark_url = "http://forum.mods.de/bb/xml/bookmarks.php" opener = None cj = None logged_in = False - - settings = { - "color": "#7181fe", - "offset": 0, - "format": "%d new posts in bookmarks" - } - def __init__(self, settings = None): - self.settings.update(settings) + def init(self): self.cj = http.cookiejar.CookieJar() self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cj)) @@ -41,10 +41,10 @@ class ModsDeChecker(IntervalModule): self.output = None else: self.output = { - "full_text" : self.settings["format"] % unread, + "full_text" : self.format % unread, "name" : "modsde", "urgent" : "true", - "color" : self.settings["color"] + "color" : self.color } def get_unread_count(self): @@ -54,7 +54,7 @@ class ModsDeChecker(IntervalModule): try: f = self.opener.open(self.bookmark_url) root = ET.fromstring(f.read()) - return int(root.attrib["newposts"]) - self.settings["offset"] + return int(root.attrib["newposts"]) - self.offset except Exception: self.cj.clear() self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cj)) @@ -62,8 +62,8 @@ class ModsDeChecker(IntervalModule): def login(self): data = urllib.parse.urlencode({ - "login_username": self.settings["username"], - "login_password": self.settings["password"], + "login_username": self.username, + "login_password": self.password, "login_lifetime": "31536000" }) diff --git a/i3pystatus/notmuchmail.py b/i3pystatus/notmuchmail.py index ccf7032..18b13b8 100644 --- a/i3pystatus/notmuchmail.py +++ b/i3pystatus/notmuchmail.py @@ -15,10 +15,7 @@ class NotmuchMailChecker(IntervalModule): and "unread" """ - db_path = "" - - def __init__(self, db_path): - self.db_path = db_path + settings = required = ("db_path",) def run(self): db = notmuch.Database(self.db_path) diff --git a/i3pystatus/regex.py b/i3pystatus/regex.py index dd3e872..0f930c0 100644 --- a/i3pystatus/regex.py +++ b/i3pystatus/regex.py @@ -15,10 +15,10 @@ class Regex(IntervalModule): flags = 0 format = "{0}" + settings = ("format", "regex", "file") + required = ("regex", "file") - def __init__(self, settings): - self.__dict__.update(settings) - + def init(self): self.re = re.compile(self.regex, self.flags) def run(self): diff --git a/i3pystatus/thunderbird.py b/i3pystatus/thunderbird.py index 3336a5c..80ed27c 100644 --- a/i3pystatus/thunderbird.py +++ b/i3pystatus/thunderbird.py @@ -23,16 +23,13 @@ class ThunderbirdMailChecker(IntervalModule): the dbus-sender extension for thunderbird. """ - settings = { - "format": "%d new email" - } + settings = ("format",) + unread = set() interval = 1 + format = "%d new mail" - def __init__(self, settings=None): - if settings is not None: - self.settings.update(settings) - + def init(self): dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() bus.add_signal_receiver(self.new_msg,