From ff2794fa3dea2256b7c7684d1a8f70121a8b8678 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Mon, 5 Jan 2015 19:45:44 +0100 Subject: [PATCH 1/2] WIP --- .gitignore | 1 + i3pystatus/mail/__init__.py | 7 +++++++ i3pystatus/mail/notmuchmail.py | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ec3c9b5..89a63b8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ build/* dist/* *.egg-info/* *~ +.i3pystatus-* ci-build diff --git a/i3pystatus/mail/__init__.py b/i3pystatus/mail/__init__.py index ff69b50..a5f088c 100644 --- a/i3pystatus/mail/__init__.py +++ b/i3pystatus/mail/__init__.py @@ -6,6 +6,10 @@ class Backend(SettingsBase): """Handles the details of checking for mail""" unread = 0 + # required = ("account", ) + + # account = "Default account" + """Number of unread mails You'll probably implement that as a property""" @@ -40,6 +44,9 @@ class Mail(IntervalModule): on_leftclick = "open_client" + current_unread = 0 + current_backend = 0 + def init(self): for backend in self.backends: pass diff --git a/i3pystatus/mail/notmuchmail.py b/i3pystatus/mail/notmuchmail.py index bd3ffe3..750650f 100644 --- a/i3pystatus/mail/notmuchmail.py +++ b/i3pystatus/mail/notmuchmail.py @@ -20,7 +20,12 @@ class Notmuch(Backend): ("db_path", "Path to the directory of your notmuch database"), ) + required = tuple( ("account", "Name available to formatter"), ) + db_path = None + query = "tag:unread and tag:inbox" + + account = "Default account" def init(self): if not self.db_path: @@ -38,7 +43,7 @@ class Notmuch(Backend): @property def unread(self): db = notmuch.Database(self.db_path) - result = notmuch.Query(db, "tag:unread and tag:inbox").count_messages() + result = notmuch.Query(db, self.query).count_messages() db.close() return result From b9e23b18a7638bc89b3545771c18b12028de6ec1 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Tue, 6 Jan 2015 00:37:16 +0100 Subject: [PATCH 2/2] Add the possibility to display per backend unread mail along with the total number of unread mails (default). The displayed backend can be set via callbacks (on mousewheel events by default) --- i3pystatus/mail/__init__.py | 26 ++++++++++++++++++++------ i3pystatus/mail/notmuchmail.py | 6 ++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/i3pystatus/mail/__init__.py b/i3pystatus/mail/__init__.py index a5f088c..d924dac 100644 --- a/i3pystatus/mail/__init__.py +++ b/i3pystatus/mail/__init__.py @@ -6,9 +6,10 @@ class Backend(SettingsBase): """Handles the details of checking for mail""" unread = 0 + settings = ("account", ) # required = ("account", ) - # account = "Default account" + account = "Default account" """Number of unread mails @@ -38,13 +39,14 @@ class Mail(IntervalModule): color = "#ffffff" color_unread = "#ff0000" format = "{unread} new email" - format_plural = "{unread} new emails" + format_plural = "{account} : {current_unread}/{unread} new emails" hide_if_null = True email_client = None on_leftclick = "open_client" + on_upscroll = ["scroll_backend", 1] + on_downscroll = ["scroll_backend", -1] - current_unread = 0 current_backend = 0 def init(self): @@ -55,8 +57,14 @@ class Mail(IntervalModule): """ Returns the sum of unread messages across all registered backends """ - - unread = sum(map(lambda backend: backend.unread, self.backends)) + unread = 0 + current_unread = 0 + for id, backend in enumerate(self.backends): + temp = backend.unread + unread = unread + backend.unread + if id == self.current_backend: + current_unread = temp + # unread = sum(map(lambda backend: backend.unread, self.backends)) if not unread: color = self.color @@ -72,12 +80,18 @@ class Mail(IntervalModule): if unread > 1: format = self.format_plural + account_name = getattr(self.backends[self.current_backend], "account", "No name") + + # TODO pass account name as well, as setting or via the dict self.output = { - "full_text": format.format(unread=unread), + "full_text": format.format(unread=unread, current_unread=current_unread, account=account_name), "urgent": urgent, "color": color, } + def scroll_backend(self, step): + self.current_backend = (self.current_backend + step) % len(self.backends) + def open_client(self): if self.email_client: retcode, _, stderr = run_through_shell(self.email_client) diff --git a/i3pystatus/mail/notmuchmail.py b/i3pystatus/mail/notmuchmail.py index 750650f..55cfdd6 100644 --- a/i3pystatus/mail/notmuchmail.py +++ b/i3pystatus/mail/notmuchmail.py @@ -18,14 +18,16 @@ class Notmuch(Backend): settings = ( ("db_path", "Path to the directory of your notmuch database"), + ("query", "Same query notmuch would accept, by default 'tag:unread and tag:inbox'"), + ("account", "Account name"), ) - required = tuple( ("account", "Name available to formatter"), ) + # required = tuple( ("account", "Name available to formatter"), ) db_path = None query = "tag:unread and tag:inbox" - account = "Default account" + account = "Default" def init(self): if not self.db_path: