diff options
| author | Ultrabug <ultrabug@ultrabug.net> | 2015-03-19 11:31:24 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@ultrabug.net> | 2015-03-19 11:31:24 +0100 |
| commit | 2c9ee598432d095fea1b24ba1cfe20f37487f9d5 (patch) | |
| tree | 4c8076eeb796f74b604038609781cabf8284a954 | |
| parent | 35e1037960e4136af93845743949a78aa4abe4cf (diff) | |
| parent | 78f09107102d36f3592a3e69409a2b58101e8704 (diff) | |
Merge pull request #79 from FedericoCeratto/pomodoro_with_bar
Pomodoro module allows to display time as a progress bar by @FedericoCeratto
| -rw-r--r-- | py3status/modules/pomodoro.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 1a167b9..3041c56 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -6,11 +6,25 @@ 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"▏▎▍▌▋▊▉" + 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) + """ # 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 @@ -42,9 +56,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 * 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(self.num_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 +87,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): """ |
