[modules/pomodoro] update to latest API
This commit is contained in:
parent
b36b37d94f
commit
e63f267803
1 changed files with 28 additions and 28 deletions
|
@ -20,43 +20,42 @@ from __future__ import absolute_import
|
||||||
import datetime
|
import datetime
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
import bumblebee.input
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
import core.input
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import util.cli
|
||||||
def __init__(self, engine, config):
|
|
||||||
widgets = bumblebee.output.Widget(full_text=self.text)
|
|
||||||
|
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
class Module(core.module.Module):
|
||||||
|
def __init__(self, config):
|
||||||
|
super().__init__(config, core.widget.Widget(self.text))
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
self._work_period = int(self.parameter('work', 25))
|
self.__work_period = int(self.parameter('work', 25))
|
||||||
self._break_period = int(self.parameter('break', 5))
|
self.__break_period = int(self.parameter('break', 5))
|
||||||
self._time_format = self.parameter('format', '%m:%s')
|
self.__time_format = self.parameter('format', '%m:%s')
|
||||||
self._notify_cmd = self.parameter('notify', '')
|
self.__notify_cmd = self.parameter('notify', '')
|
||||||
|
|
||||||
# TODO: Handle time formats more gracefully. This is kludge.
|
# TODO: Handle time formats more gracefully. This is kludge.
|
||||||
self.display_seconds_p = False
|
self.display_seconds_p = False
|
||||||
self.display_minutes_p = False
|
self.display_minutes_p = False
|
||||||
if '%s' in self._time_format:
|
if '%s' in self.__time_format:
|
||||||
self.display_seconds_p = True
|
self.display_seconds_p = True
|
||||||
if '%m' in self._time_format:
|
if '%m' in self.__time_format:
|
||||||
self.display_minutes_p = True
|
self.display_minutes_p = True
|
||||||
|
|
||||||
self.remaining_time = datetime.timedelta(minutes=self._work_period)
|
self.remaining_time = datetime.timedelta(minutes=self.__work_period)
|
||||||
|
|
||||||
self.time = None
|
self.time = None
|
||||||
self.pomodoro = { 'state':'OFF', 'type': ''}
|
self.pomodoro = { 'state':'OFF', 'type': ''}
|
||||||
self._text = self.remaining_time_str() + self.pomodoro['type']
|
self.__text = self.remaining_time_str() + self.pomodoro['type']
|
||||||
|
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
core.input.register(self, button=core.input.LEFT_MOUSE,
|
||||||
cmd=self.timer_play_pause)
|
cmd=self.timer_play_pause)
|
||||||
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE,
|
core.input.register(self, button=core.input.RIGHT_MOUSE,
|
||||||
cmd=self.timer_reset)
|
cmd=self.timer_reset)
|
||||||
|
|
||||||
def remaining_time_str(self):
|
def remaining_time_str(self):
|
||||||
|
|
||||||
if self.display_seconds_p and self.display_minutes_p:
|
if self.display_seconds_p and self.display_minutes_p:
|
||||||
minutes, seconds = divmod(self.remaining_time.seconds, 60)
|
minutes, seconds = divmod(self.remaining_time.seconds, 60)
|
||||||
if not self.display_seconds_p:
|
if not self.display_seconds_p:
|
||||||
|
@ -68,12 +67,12 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
minutes = '{:2d}'.format(minutes)
|
minutes = '{:2d}'.format(minutes)
|
||||||
seconds = '{:02d}'.format(seconds)
|
seconds = '{:02d}'.format(seconds)
|
||||||
return self._time_format.replace('%m',minutes).replace('%s',seconds)+' '
|
return self.__time_format.replace('%m',minutes).replace('%s',seconds)+' '
|
||||||
|
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
return '{}'.format(self._text)
|
return '{}'.format(self.__text)
|
||||||
|
|
||||||
def update(self, widget):
|
def update(self):
|
||||||
if self.pomodoro['state'] == 'ON':
|
if self.pomodoro['state'] == 'ON':
|
||||||
timediff = (datetime.datetime.now() - self.time)
|
timediff = (datetime.datetime.now() - self.time)
|
||||||
if timediff.seconds >= 0:
|
if timediff.seconds >= 0:
|
||||||
|
@ -84,21 +83,21 @@ class Module(bumblebee.engine.Module):
|
||||||
self.notify()
|
self.notify()
|
||||||
if self.pomodoro['type'] == 'Work':
|
if self.pomodoro['type'] == 'Work':
|
||||||
self.pomodoro['type'] = 'Break'
|
self.pomodoro['type'] = 'Break'
|
||||||
self.remaining_time = datetime.timedelta(minutes=self._break_period)
|
self.remaining_time = datetime.timedelta(minutes=self.__break_period)
|
||||||
elif self.pomodoro['type'] == 'Break':
|
elif self.pomodoro['type'] == 'Break':
|
||||||
self.pomodoro['type'] = 'Work'
|
self.pomodoro['type'] = 'Work'
|
||||||
self.remaining_time = datetime.timedelta(minutes=self._work_period)
|
self.remaining_time = datetime.timedelta(minutes=self.__work_period)
|
||||||
|
|
||||||
self._text = self.remaining_time_str() + self.pomodoro['type']
|
self.__text = self.remaining_time_str() + self.pomodoro['type']
|
||||||
|
|
||||||
def notify(self):
|
def notify(self):
|
||||||
if self._notify_cmd:
|
if self.__notify_cmd:
|
||||||
bumblebee.util.execute(self._notify_cmd)
|
util.cli.execute(self.__notify_cmd)
|
||||||
|
|
||||||
def timer_play_pause(self, widget):
|
def timer_play_pause(self, widget):
|
||||||
if self.pomodoro['state'] == 'OFF':
|
if self.pomodoro['state'] == 'OFF':
|
||||||
self.pomodoro = {'state': 'ON', 'type': 'Work'}
|
self.pomodoro = {'state': 'ON', 'type': 'Work'}
|
||||||
self.remaining_time = datetime.timedelta(minutes=self._work_period)
|
self.remaining_time = datetime.timedelta(minutes=self.__work_period)
|
||||||
self.time = datetime.datetime.now()
|
self.time = datetime.datetime.now()
|
||||||
elif self.pomodoro['state'] == 'ON':
|
elif self.pomodoro['state'] == 'ON':
|
||||||
self.pomodoro['state'] = 'PAUSED'
|
self.pomodoro['state'] = 'PAUSED'
|
||||||
|
@ -111,7 +110,7 @@ class Module(bumblebee.engine.Module):
|
||||||
def timer_reset(self, widget):
|
def timer_reset(self, widget):
|
||||||
if self.pomodoro['state'] == 'ON' or self.pomodoro['state'] == 'PAUSED':
|
if self.pomodoro['state'] == 'ON' or self.pomodoro['state'] == 'PAUSED':
|
||||||
self.pomodoro = {'state':'OFF', 'type': '' }
|
self.pomodoro = {'state':'OFF', 'type': '' }
|
||||||
self.remaining_time = datetime.timedelta(minutes=self._work_period)
|
self.remaining_time = datetime.timedelta(minutes=self.__work_period)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
state = [];
|
state = [];
|
||||||
|
@ -120,3 +119,4 @@ class Module(bumblebee.engine.Module):
|
||||||
state.append(self.pomodoro['type'].lower())
|
state.append(self.pomodoro['type'].lower())
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue