1
2
3
4
5
6
7
8
9
10 import pilas
11 from pilas.actores import Texto
12 from pilas import colores
13
15 """Representa un contador de tiempo con cuenta regresiva.
16
17 Por ejemplo:
18
19 >>> t = pilas.actores.Temporizador()
20 >>> def hola_mundo():
21 ... pilas.avisar("Hola mundo, pasaron 10 segundos...")
22 ...
23 >>> t.ajustar(10, hola_mundo)
24 >>> t.iniciar()
25
26 """
28 """Inicializa el temporizador.
29
30 :param x: Posición horizontal.
31 :param y: Posición vertical.
32 :param color: El color que tendrá el texto.
33 """
34 Texto.__init__(self, '0', x=x, y=y, fuente=fuente)
35 self.ajustar(1, self.funcion_vacia)
36 self.color = color
37
38
41
42 - def definir_tiempo_texto(self, variable):
43 """Define el texto a mostrar en el temporizador.
44
45 :param variable: La cadena de texto a mostrar.
46 """
47 self.texto = str(variable)
48
49
50
51 - def ajustar(self, tiempo=1, funcion=None):
52 """Indica una funcion para ser invocada en el tiempo indicado.
53
54 La función no tiene que recibir parámetros, y luego de
55 ser indicada se tiene que iniciar el temporizador.
56 """
57
58 self.tiempo = tiempo
59 self.definir_tiempo_texto(self.tiempo)
60
61 if funcion == None:
62 self.funcion = self.funcion_vacia()
63 else:
64 self.funcion = funcion
65
67 if self.tiempo != 0:
68 self.tiempo -= 1
69 self.definir_tiempo_texto(self.tiempo)
70 return True
71
76