-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
131 lines (102 loc) · 3.95 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
import pygame
from reloj import Reloj
from config import ConfigMenu
from alarmas import Alarmas
from buzzer import Buzzer
from setalarm import SetAlarm
from pygame.locals import *
# from datetime import date, datetime
import datetime
import json
class App:
def __init__(self):
self._running = True
self._display_surf = None
self.size = self.weight, self.height = 480, 320
self.actual = None
self.texto = None
self.config = {}
self.buzzerActivo = None
def test_alarm(self):
d1 = datetime.date.today()
t1 = datetime.datetime.today()
for i, a in enumerate(self.config['Alarmas']):
d2 = datetime.datetime.strptime(str(a["Last"]), "%Y-%m-%d").date()
if d1 > d2:
if t1.weekday() in a['Dias']:
if t1.hour == a["Hora"] and t1.minute == a["Minuto"]:
print("Es el momento de " + a["Nombre"])
self.config["Alarmas"][i]["Last"] = str(datetime.date.today())
print(self.config["Alarmas"][i]["Last"])
self.buzzerActivo = Buzzer(a, self)
def do_stopAlarm(self):
self.buzzerActivo = None
pass
def on_init(self):
pygame.init()
pygame.font.init()
pygame.mixer.init()
if os.path.exists('config.txt'):
with open('config.txt') as json_file:
self.config = json.load(json_file)
else:
self.config['Alarmas'] = [{"Nombre": "Alarma 1", "Hora": 13, "Minuto": 2, "Dias": [0, 2, 4, 6],
"Last": str(datetime.date.today()+datetime.timedelta(days=-1))},
{"Nombre": "Alarma 2", "Hora": 13, "Minuto": 3, "Dias": [1, 3, 5],
"Last": str(datetime.date.today()+datetime.timedelta(days=-1))},
{"Nombre": "Alarma 3", "Hora": 13, "Minuto": 4, "Dias": [0, 3, 5],
"Last": str(datetime.date.today()+datetime.timedelta(days=-1))}]
self.texto = pygame.font.Font("DroidSansMono.ttf", 48)
# self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
self._display_surf = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
self._running = True
self.actual = Reloj()
self.actual.on_init(self)
def on_event(self, event):
if event.type == pygame.QUIT:
self._running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if not self.buzzerActivo is None:
self.buzzerActivo.click()
self.actual.click()
def on_loop(self):
self.actual.doProc()
self.test_alarm()
if not (self.buzzerActivo is None):
self.buzzerActivo.doProc()
pass
def on_render(self):
self.actual.render()
if not (self.buzzerActivo is None):
self.buzzerActivo.render()
pygame.display.flip()
pass
def on_cleanup(self):
with open('config.txt', 'w') as outfile:
json.dump(self.config, outfile)
pygame.quit()
def go_configSCR(self):
self.actual = ConfigMenu()
self.actual.on_init(self)
def go_mainSCR(self):
self.actual = Reloj()
self.actual.on_init(self)
def go_alarmas(self):
self.actual = Alarmas()
self.actual.on_init(self)
def go_setAlarm(self,n):
self.actual = SetAlarm()
self.actual.on_init(self,n)
def on_execute(self):
if self.on_init() == False:
self._running = False
while self._running:
for event in pygame.event.get():
self.on_event(event)
self.on_loop()
self.on_render()
self.on_cleanup()
if __name__ == "__main__":
theApp = App()
theApp.on_execute()