From 7b70f50b9bd896792de5aebf7a69af4826117bd3 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Wed, 18 Mar 2015 17:17:58 +0000 Subject: Pomodoro module: display time as a progress bar --- py3status/modules/pomodoro.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'py3status/modules/pomodoro.py') diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 1a167b9..bbfae1e 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -6,6 +6,10 @@ Pomodoro countdown on i3bar originally written by @Fandekasp (Adrien Lemaire) from subprocess import call from time import time +# PROGRESS_BAR_ITEMS = u"▁▃▄▅▆▇█" +PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" +N_PROGRESS_BARS = 5 + class Py3status: @@ -15,10 +19,11 @@ class Py3status: timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - def __init__(self): + def __init__(self, display_bar=True): self.__setup('stop') self.alert = False self.run = False + self.display_bar = display_bar def on_click(self, i3s_output_list, i3s_config, event): """ @@ -42,9 +47,27 @@ class Py3status: """ Return the response full_text string """ - return { - 'full_text': '{} ({})'.format(self.prefix, self.timer) - } + if self.display_bar and self.status in ('start', 'pause'): + bar = u'' + items_cnt = len(PROGRESS_BAR_ITEMS) + bar = u'' + bar_val = float(self.timer) / self.time_window * N_PROGRESS_BARS + while bar_val > 0: + selector = int(bar_val * items_cnt) + selector = min(selector, items_cnt - 1) + bar += PROGRESS_BAR_ITEMS[selector] + bar_val -= 1 + + bar = bar.ljust(N_PROGRESS_BARS).encode('utf_8') + else: + bar = self.timer + + if self.run: + text = '{} [{}]'.format(self.prefix, bar) + else: + text = '{} ({})'.format(self.prefix, bar) + + return dict(full_text=text) def __setup(self, status): """ @@ -55,20 +78,24 @@ class Py3status: self.prefix = 'Pomodoro' self.status = 'stop' self.timer = self.timer_pomodoro + self.time_window = self.timer self.breaks = 1 elif status == 'start': self.prefix = 'Pomodoro' self.timer = self.timer_pomodoro + self.time_window = self.timer elif status == 'pause': self.prefix = 'Break #%d' % self.breaks if self.breaks > self.max_breaks: self.timer = self.timer_long_break + self.time_window = self.timer self.breaks = 1 else: self.breaks += 1 self.timer = self.timer_break + self.time_window = self.timer def __decrement(self): """ -- cgit v1.3 From c54b3a3d92c25bd5ee28e2d344a9efca86677063 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Wed, 18 Mar 2015 18:34:36 +0000 Subject: Pomodoro module: make progress bar configurable --- py3status/modules/pomodoro.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'py3status/modules/pomodoro.py') diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index bbfae1e..af42f08 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -8,22 +8,31 @@ from time import time # PROGRESS_BAR_ITEMS = u"▁▃▄▅▆▇█" PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" -N_PROGRESS_BARS = 5 class Py3status: + """ + Configuration parameters: + - max_breaks: maximum number of breaks + - timer_break: normal break time (seconds) + - timer_long_break: long break time (seconds) + - timer_pomodoro: pomodoro time (seconds) + - display_bar: display time in bars when True, otherwise in seconds + - num_progress_bars: number of progress bars + """ # available configuration parameters max_breaks = 4 timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 + display_bar = True + num_progress_bars = 5 - def __init__(self, display_bar=True): + def __init__(self): self.__setup('stop') self.alert = False self.run = False - self.display_bar = display_bar def on_click(self, i3s_output_list, i3s_config, event): """ @@ -51,14 +60,14 @@ class Py3status: bar = u'' items_cnt = len(PROGRESS_BAR_ITEMS) bar = u'' - bar_val = float(self.timer) / self.time_window * N_PROGRESS_BARS + bar_val = float(self.timer) / self.time_window * self.num_progress_bars while bar_val > 0: selector = int(bar_val * items_cnt) selector = min(selector, items_cnt - 1) bar += PROGRESS_BAR_ITEMS[selector] bar_val -= 1 - bar = bar.ljust(N_PROGRESS_BARS).encode('utf_8') + bar = bar.ljust(self.num_progress_bars).encode('utf_8') else: bar = self.timer -- cgit v1.3 From 786470a09ee1d7736c41dcd89db632657f9f87c7 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Thu, 19 Mar 2015 10:18:03 +0000 Subject: Pomodoro module: disable progress bar by default --- py3status/modules/pomodoro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py3status/modules/pomodoro.py') diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index af42f08..07e3087 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -26,7 +26,7 @@ class Py3status: timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - display_bar = True + display_bar = False num_progress_bars = 5 def __init__(self): -- cgit v1.3 From 78f09107102d36f3592a3e69409a2b58101e8704 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Thu, 19 Mar 2015 10:20:46 +0000 Subject: Pomodoro module: sort configuration parameters --- py3status/modules/pomodoro.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'py3status/modules/pomodoro.py') diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 07e3087..3041c56 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -13,21 +13,21 @@ PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" class Py3status: """ Configuration parameters: + - display_bar: display time in bars when True, otherwise in seconds - max_breaks: maximum number of breaks + - num_progress_bars: number of progress bars - timer_break: normal break time (seconds) - timer_long_break: long break time (seconds) - timer_pomodoro: pomodoro time (seconds) - - display_bar: display time in bars when True, otherwise in seconds - - num_progress_bars: number of progress bars """ # available configuration parameters + display_bar = False max_breaks = 4 + num_progress_bars = 5 timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - display_bar = False - num_progress_bars = 5 def __init__(self): self.__setup('stop') -- cgit v1.3