diff options
| author | Adrien Lemaire <lemaire.adrien@gmail.com> | 2013-04-15 18:51:09 +0900 |
|---|---|---|
| committer | Adrien Lemaire <lemaire.adrien@gmail.com> | 2013-04-15 18:51:09 +0900 |
| commit | 0fcec20db1bc974e098debdf2986ead27cf3cd7d (patch) | |
| tree | 481018f6d5e80034d6920ad894f8cfd8e5cb5ee8 /examples | |
| parent | 0fc30d5178c929c7cdee8ae1c95f294059875c5a (diff) | |
adding new pomodoro plugin
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/pomodoro.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/examples/pomodoro.py b/examples/pomodoro.py new file mode 100644 index 0000000..86ffdb6 --- /dev/null +++ b/examples/pomodoro.py @@ -0,0 +1,65 @@ +""" +:Requirements: libnotify, python-gobject +""" +from datetime import timedelta +from gi.repository import Notify +from time import time + +POMO = 1500 # 60 * 25 +SHORT_REST = 300 # 60 * 5 +LONG_REST = 1800 # 60 * 30 +NB_REST = 4 + + +class Py3status: + """ + Pomodoro method + """ + pomo = POMO + rest = SHORT_REST + nb_rest = NB_REST + + def pomodoro(self, json, i3status_config): + """ + This function will update a timer in the i3status bar for 25 minutes, + then print a red "Break time" message for 5 minutes. + """ + if not self.pomo: + self.rest -= 1 + timer = self.rest + full_text = 'Break time' + color = 'color_bad' + else: + self.pomo -= 1 + timer = self.pomo + full_text = 'Pomodoro' + color = 'color_degraded' + + if not timer: + # Pomodoro or Rest is finished, send notification + Notify.init('Pomodoro') + notification = Notify.Notification.new ( + '<b>Attention:</b>', + '{} is finished'.format(full_text), + 'dialog-information', + ) + notification.show() + if not self.rest: + # Rest is finished, reinitialize data + self.nb_rest -= 1 + self.pomo = POMO + self.rest = SHORT_REST + if not self.nb_rest: + # Number of small rest reached, go for long rest + self.rest = LONG_REST + self.nb_rest = NB_REST + + response = { + 'cached_until' : time(), + 'color': i3status_config[color], + 'full_text': '{}: {}'.format( + full_text, str(timedelta(seconds=timer))[2:]), + 'name': 'pomodoro', + } + + return (0, response) |
