diff options
| author | Adrien Lemaire <lemaire.adrien@gmail.com> | 2013-04-15 20:40:27 +0900 |
|---|---|---|
| committer | Adrien Lemaire <lemaire.adrien@gmail.com> | 2013-04-15 20:40:27 +0900 |
| commit | 6b526bdc46cebb7d5f3df7d06eb2d723888ab854 (patch) | |
| tree | 60ef841f6fc18946083b66495a42993f88eeffff /examples | |
| parent | 01372d6e638dc2bfa206be09fc3082c03f1fc56f (diff) | |
plugin now working with keys to start/stop/pause
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/pomodoro.py | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/examples/pomodoro.py b/examples/pomodoro.py index 143adf5..7af996b 100644 --- a/examples/pomodoro.py +++ b/examples/pomodoro.py @@ -1,17 +1,31 @@ +""" +REQUIREMENTS +------------ +* libnotify +* python-gobject + + +INSTALLATION +------------ +Please add the following lines in your ~/.i3/config file:: + + bindsym $mod+minus exec echo "stop" > ~/.i3/pomodoro.log + bindsym $mod+equal exec echo "pause" > ~/.i3/pomodoro.log + bindsym $mod+plus exec echo "start" > ~/.i3/pomodoro.log + +""" from datetime import timedelta from gi.repository import Notify import os.path from time import time -#from time import sleep -#from watchdog.observers import Observer -#from watchdog.events import LoggingEventHandler -POMO = 1500 # 60 * 25 -SHORT_REST = 300 # 60 * 5 +LOG_FILE = os.path.join(os.path.expanduser('~'), '.i3', 'pomodoro.log') LONG_REST = 1800 # 60 * 30 NB_REST = 4 -WATCHDOG_FILE = os.path.join(os.path.expanduser('~'), '.i3', 'watchdog.log') +POMO = 1500 # 60 * 25 +POSITION = 0 +SHORT_REST = 300 # 60 * 5 class Py3status: @@ -21,10 +35,14 @@ class Py3status: pomo = POMO rest = SHORT_REST nb_rest = NB_REST - default_response = { - 'full_text': '', - 'name': 'pomodoro', - } + + @property + def response(self): + return { + 'cached_until' : time(), + 'full_text': '', + 'name': 'pomodoro', + } def pomodoro(self, json, i3status_config): """ @@ -37,39 +55,41 @@ class Py3status: self.pomo = POMO self.rest = SHORT_REST self.nb_rest = NB_REST - return self.default_response - elif status == 'pause': - return self.default_response + return (POSITION, self.response) # Else run normally if not self.pomo: - self.rest -= 1 + if status != 'pause': + self.rest -= 1 timer = self.rest self.full_text = 'Break time' color = 'color_bad' else: - self.pomo -= 1 + if status != 'pause': + self.pomo -= 1 timer = self.pomo self.full_text = 'Pomodoro' color = 'color_degraded' + if status == 'pause': + color = 'color_good' + if not timer: # Pomodoro or Rest is finished, send notification self.send_notification() - response = self.default_response.copy() + response = self.response response.update({ - 'cached_until' : time(), 'color': i3status_config[color], 'full_text': '{}: {}'.format( self.full_text, str(timedelta(seconds=timer))[2:]), }) - return (0, response) + return (POSITION, response) def get_status(self): """ - Read the watchdog file and get the status value. Value is modifying via + Read the log file and get the status value. Value is modifying via i3 key mapping. Value can be: @@ -77,14 +97,14 @@ class Py3status: * pause * stop (default) """ - with open(WATCHDOG_FILE, 'r') as f: + with open(LOG_FILE, 'r') as f: status = f.read() - return status + return status.rstrip('\n') def send_notification(self): """ - :Requirements: libnotify, python-gobject + Print a visual message """ Notify.init('Pomodoro') @@ -105,16 +125,3 @@ class Py3status: # Number of small rest reached, go for long rest self.rest = LONG_REST self.nb_rest = NB_REST - - -#if __name__ == "__main__": - #event_handler = LoggingEventHandler() - #observer = Observer() - #observer.schedule(event_handler, path=WATCHDOG_FILE, recursive=True) - #observer.start() - #try: - #while True: - #sleep(1) - #except KeyboardInterrupt: - #observer.stop() - #observer.join() |
