-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendario.py
111 lines (80 loc) · 3.88 KB
/
calendario.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
from general_functions import *
class Calendario():
def __init__(self,screen,sw,sh,ciclo=10,dia=1,mes=1,ano=1969):
self.dia = 1
self.dias = [
"Segunda-Feira","Terça-Feira","Quarta-Feira","Quinta-Feira","Sexta-Feira",
"Sábado","Domingo"
]
self.dia_pos = 0
self.mes = 1
self.semana = 0
self.meses = ["Janeiro","Fevereiro","Março","Abril","Maio","Junho",
"Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"]
self.ano = ano
self.ciclo= ciclo
self.ciclo_pos = ciclo
self.pause = False
self.lista_x = []
self.reload_x(screen,sw,sh)
#Define a velocidad de atualização:
def set_vel(self,vel):
if vel > 0:
self.pause = False
self.ciclo = 10//vel
else:
self.pause = True
self.ciclo = 0
#Atualização dos dados a cada frame
def update(self,screen,sw,sh):
if self.pause == False:
self.ciclo_pos -= 1
if self.ciclo_pos == 0:
if self.dia_pos == 6:
self.dia_pos = 0
self.semana += 1
else:
self.dia_pos += 1
if self.dia == 28:
self.mes += 1
self.dia = 1
self.semana = 0
self.lista_x = []
else:
self.dia += 1
if self.mes == 13:
self.ano += 1
self.mes = 1
self.ciclo_pos = self.ciclo
pygame.draw.rect(screen,preto,[swi(sw,.01),shi(sh,.47),swi(sw,.205),int(swi(sw,.2)*1.036)])
screen.blit(self.img_calend,(swi(sw,.01),shi(sh,.47)))
x_dia=swi(sw,.025) + swi(sw,.0265)*self.dia_pos
y_dia = shi(sh,.556) + shi(sw,.023)*self.semana
draw_text("O",verde,screen,x=x_dia,y=y_dia,tamanho=swi(sw,.019))
if len(self.lista_x)== 0 or self.lista_x[-1] != (x_dia,y_dia):
self.lista_x.append((x_dia,y_dia))
for x in self.lista_x[0:-1]:
draw_text("X",vermelho,screen,x=x[0],y=x[1], tamanho=swi(sw,.019))
#Recarrega a posição do X no calend - caso ocorra mudança de res
def reload_x(self,screen,sw,sh):
temp = []
#Recarrega o calendário em si
img_calend = pygame.image.load("imgs/calend2.png",).convert_alpha()
self.img_calend = pygame.transform.scale(img_calend, (swi(sw,.205),int(swi(sw,.2)*1.036)))
if len(self.lista_x) > 0:
for x in self.lista_x:
semana = self.lista_x.index(x)//7
dia_pos = self.lista_x.index(x)-semana*7
x_dia=swi(sw,.025) + swi(sw,.0265)*dia_pos
y_dia = shi(sh,.556) + shi(sw,.023)*semana
temp.append((x_dia,y_dia))
self.lista_x = temp
#Representação visual do calendário na tela
def rep_visual(self,screen,sw,sh):
draw_text(self.meses[self.mes-1]+" - "+str(self.ano),preto,screen,x=swi(sw,.018),y=shi(sh,.495))
draw_text("Dia - "+str(self.dia),branco,screen,x=swi(sw,.023),y=shi(sh,.73))
draw_text("Velocidade - "+str(self.ciclo)+"tpd",branco,screen,x=swi(sw,.023),y=shi(sh,.795))
#Print dos valores atuais
def __repr__(self):
return f""" {self.dias[self.dia_pos]} - Dia: {self.dia}\
{self.meses[self.mes-1]} - Mês: {self.mes} Ano: {self.ano} """