Pep8 formatting

This commit is contained in:
Sergei Turukin 2014-10-23 14:38:09 +03:00
parent c64e759b5a
commit 9a83f7117e

View File

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