diff --git a/modules/contrib/pomodoro.py b/modules/contrib/pomodoro.py index 4e23d37..09bf659 100644 --- a/modules/contrib/pomodoro.py +++ b/modules/contrib/pomodoro.py @@ -20,43 +20,42 @@ from __future__ import absolute_import import datetime from math import ceil -import bumblebee.input -import bumblebee.output -import bumblebee.engine +import core.module +import core.widget +import core.input -class Module(bumblebee.engine.Module): - def __init__(self, engine, config): - widgets = bumblebee.output.Widget(full_text=self.text) +import util.cli - 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 - self._work_period = int(self.parameter('work', 25)) - self._break_period = int(self.parameter('break', 5)) - self._time_format = self.parameter('format', '%m:%s') - self._notify_cmd = self.parameter('notify', '') + self.__work_period = int(self.parameter('work', 25)) + self.__break_period = int(self.parameter('break', 5)) + self.__time_format = self.parameter('format', '%m:%s') + self.__notify_cmd = self.parameter('notify', '') # TODO: Handle time formats more gracefully. This is kludge. self.display_seconds_p = False self.display_minutes_p = False - if '%s' in self._time_format: + if '%s' in self.__time_format: self.display_seconds_p = True - if '%m' in self._time_format: + if '%m' in self.__time_format: 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.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) - engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, + core.input.register(self, button=core.input.RIGHT_MOUSE, cmd=self.timer_reset) def remaining_time_str(self): - if self.display_seconds_p and self.display_minutes_p: minutes, seconds = divmod(self.remaining_time.seconds, 60) if not self.display_seconds_p: @@ -68,12 +67,12 @@ class Module(bumblebee.engine.Module): minutes = '{:2d}'.format(minutes) 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): - return '{}'.format(self._text) + return '{}'.format(self.__text) - def update(self, widget): + def update(self): if self.pomodoro['state'] == 'ON': timediff = (datetime.datetime.now() - self.time) if timediff.seconds >= 0: @@ -84,21 +83,21 @@ class Module(bumblebee.engine.Module): self.notify() if self.pomodoro['type'] == 'Work': 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': 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): - if self._notify_cmd: - bumblebee.util.execute(self._notify_cmd) + if self.__notify_cmd: + util.cli.execute(self.__notify_cmd) def timer_play_pause(self, widget): if self.pomodoro['state'] == 'OFF': 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() elif self.pomodoro['state'] == 'ON': self.pomodoro['state'] = 'PAUSED' @@ -111,7 +110,7 @@ class Module(bumblebee.engine.Module): def timer_reset(self, widget): if self.pomodoro['state'] == 'ON' or self.pomodoro['state'] == 'PAUSED': 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): state = []; @@ -120,3 +119,4 @@ class Module(bumblebee.engine.Module): state.append(self.pomodoro['type'].lower()) return state +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4