diff --git a/i3pystatus/pomodoro.py b/i3pystatus/pomodoro.py index 932dcfd..0eb5a7c 100644 --- a/i3pystatus/pomodoro.py +++ b/i3pystatus/pomodoro.py @@ -11,80 +11,85 @@ from i3pystatus import IntervalModule class Pomodoro(IntervalModule): - """ - This plugin shows Pomodoro timer. - Left click starts/restarts timer. - Right click stops it. - """ + """ + This plugin shows Pomodoro timer. - settings = ( - ('sound', 'Path to sound file to play as alarm. Played by "aplay" utility'), - ('pomodoro_duration', 'Working (pomodoro) interval duration in seconds'), - ('break_duration', 'Short break duration in secods'), - ('long_break_duration', 'Long break duration in secods'), - ('short_break_count', 'Short break count before first long break'), - ) + Left click starts/restarts timer. + Right click stops it. + """ - color_stopped = '#2ECCFA' - color_running = '#FFFF00' - color_break = '#37FF00' - interval = 1 - short_break_count = 3 + settings = ( + ('sound', + 'Path to sound file to play as alarm. Played by "aplay" utility'), + ('pomodoro_duration', + 'Working (pomodoro) interval duration in seconds'), + ('break_duration', 'Short break duration in secods'), + ('long_break_duration', 'Long break duration in secods'), + ('short_break_count', 'Short break count before first long break'), + ) - pomodoro_duration = 25 * 60 - break_duration = 5 * 60 - long_break_duration = 15 * 60 + color_stopped = '#2ECCFA' + color_running = '#FFFF00' + color_break = '#37FF00' + interval = 1 + short_break_count = 3 - def init(self): - # state could be either running/break or stopped - self.state = 'stopped' - self.breaks = 0 - self.time = None + pomodoro_duration = 25 * 60 + break_duration = 5 * 60 + long_break_duration = 15 * 60 - def run(self): - if self.time and datetime.now() >= self.time: - if self.state == 'running': - self.state = 'break' - if self.breaks == self.short_break_count: - self.time = datetime.now() + timedelta(seconds=self.long_break_duration) - self.breaks = 0 + def init(self): + # state could be either running/break or stopped + self.state = 'stopped' + self.breaks = 0 + self.time = None + + def run(self): + if self.time and datetime.now() >= self.time: + if self.state == 'running': + self.state = 'break' + if self.breaks == self.short_break_count: + self.time = datetime.now() + \ + timedelta(seconds=self.long_break_duration) + self.breaks = 0 + else: + self.time = datetime.now() + \ + timedelta(seconds=self.break_duration) + text = 'Go for a break!' + self.breaks += 1 + else: + self.state = 'running' + self.time = datetime.now() + \ + timedelta(seconds=self.pomodoro_duration) + text = 'Back to work!' + self._alarm(text) + + if self.state == 'running' or self.state == 'break': + min, sec = divmod((self.time - datetime.now()).total_seconds(), 60) + text = '{:02}:{:02}'.format(int(min), int(sec)) + color = self.color_running if self.state == 'running' else self.color_break else: - self.time = datetime.now() + timedelta(seconds=self.break_duration) - text = 'Go for a break!' - self.breaks += 1 - else: + text = 'Stopped' + color = self.color_stopped + + self.output = { + 'full_text': text, + 'color': color + } + + def on_leftclick(self): self.state = 'running' self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration) - text = 'Back to work!' - self._alarm(text) - if self.state == 'running' or self.state == 'break': - min, sec = divmod((self.time - datetime.now()).total_seconds(), 60) - text = '{:02}:{:02}'.format(int(min), int(sec)) - color = self.color_running if self.state == 'running' else self.color_break - else: - text = 'Stopped' - color = self.color_stopped - - self.output = { - 'full_text': text, - 'color': color - } - - def on_leftclick(self): - self.state = 'running' - self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration) - - def on_rightclick(self): - self.state = 'stopped' - self.time = None - - def _alarm(self, text): - subprocess.call(['notify-send', - 'Alarm!', - text]) - subprocess.Popen(['aplay', - self.sound, - '-q'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + def on_rightclick(self): + self.state = 'stopped' + self.time = None + def _alarm(self, text): + subprocess.call(['notify-send', + 'Alarm!', + text]) + subprocess.Popen(['aplay', + self.sound, + '-q'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)