-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
78 lines (64 loc) · 2.47 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import logging
import threading
import time
from lib.screens import core, task_list, task_timer, timer_done
from lib.service import todoist
logging.basicConfig(level=logging.DEBUG)
class Application(core.App):
""" The core application """
service: todoist.Todoist
current_screen: core.Screen = None
__thread: threading.Thread
tasks_changed: bool
pomodoro_duration_s: int
def __init__(self, api, project_id, pomodoro_duration):
self.service = todoist.Todoist(api_key=api, project_id=project_id)
self.pomodoro_duration_s = pomodoro_duration * 60
self.tasks_changed = False
self.__redraw = False
self.__task_list = task_list.TaskListScreen(self, self.service)
self.__task_timer = task_timer.TaskTimerScreen(self, self.service)
self.__timer_done = timer_done.TimerDoneScreen(self, self.service)
self.__thread = None
self.__timer_end_time = 0
def start(self):
self.current_screen = self.task_list
return self.current_screen.draw()
def handle_click(self, click):
# The XY are reported for portrait orientation and with (0,0) in the lower left
point = core.Point(y=(core.SCREEN_HEIGHT-click.X[0]), x=click.Y[0], s=click.S[0])
self.current_screen = self.current_screen.handle_click(point)
return self.current_screen.draw()
def draw(self):
return self.current_screen.draw()
@property
def task_list(self) -> core.Screen:
if self.__thread and self.__thread.is_alive():
self.__thread.cancel()
if self.tasks_changed:
self.__task_list.refresh()
self.tasks_changed = False
return self.__task_list
@property
def task_timer(self) -> core.Screen:
self.__timer_end_time = time.time() + self.pomodoro_duration_s
self.__task_timer.end_time = self.__timer_end_time
self.update_timer()
return self.__task_timer
@property
def timer_done(self) -> core.Screen:
return self.__timer_done
@property
def redraw(self):
redraw = self.__redraw
self.__redraw = False
return redraw
def request_redraw(self):
self.__redraw = True
def update_timer(self):
if time.time() >= self.__timer_end_time:
self.current_screen = self.timer_done
self.request_redraw()
self.__thread = threading.Timer(60, self.update_timer)
self.__thread.start()
self.request_redraw()