-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_check_box.py
executable file
·88 lines (68 loc) · 1.84 KB
/
test_check_box.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
#!/usr/bin/env python3
import pygame
import thorpy
tamano = (400, 400)
pygame.init()
pantalla = pygame.display.set_mode(tamano)
pantalla.fill((255, 255, 255))
class MenuSeleccion:
def __init__(self, opciones=[]):
self.checkers = {}
for opcion in opciones:
self.addChecker(opcion)
self.last_checked = None
def addChecker(self, nombre):
self.checkers[nombre] = thorpy.Checker(nombre, value=False)
def check(self, nombre):
self.uncheckAll()
for _nombre, checker in self.checkers.items():
if _nombre == nombre:
#self.checkers[_nombre].value = True
#print(self.checkers[_nombre].value)
self.checkers[_nombre].check()
self.last_checked = _nombre
def uncheckAll(self):
for checker in self.checkers.values():
checker.set_value(False)
def getChecked(self):
for nombre, checker in self.checkers.items():
if checker.get_value() == True:
return nombre
def to_caja(self):
elementos = []
for checker in self.checkers.values():
elementos.append(checker)
return thorpy.Box(elements=elementos)
def update(self):
for _nombre, checker in self.checkers.items():
if _nombre == self.last_checked:
continue
elif checker.get_value():
self.check(_nombre)
break
checker.total_unblit()
menu_s = MenuSeleccion(opciones=["suma", "resta",
"producto punto", "producto vectorial"])
"""
menu_s.addChecker("suma")
menu_s.addChecker("resta")
menu_s.addChecker("producto punto")
menu_s.addChecker("producto vectorial")
"""
caja = menu_s.to_caja()
menu = thorpy.Menu()
menu.add_to_population(caja)
for elemento in menu.get_population():
elemento.surface = pantalla
caja.blit()
caja.update()
corriendo = True
while corriendo:
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
corriendo = False
menu.react(evento)
menu_s.update()
print(menu_s.getChecked())
pygame.display.flip()
pygame.quit()