pantalla 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pantalla/__init__.py +219 -0
- pantalla/__main__.py +253 -0
- pantalla/_figlet.py +269 -0
- pantalla/arte.py +122 -0
- pantalla/colores.py +198 -0
- pantalla/componentes.py +552 -0
- pantalla/dibujo.py +169 -0
- pantalla/disenos.py +101 -0
- pantalla/fuentes/3-d.flf +819 -0
- pantalla/fuentes/ansi_regular.flf +723 -0
- pantalla/fuentes/ansi_shadow.flf +723 -0
- pantalla/fuentes/banner3.flf +719 -0
- pantalla/fuentes/big.flf +972 -0
- pantalla/fuentes/big_money-ne.flf +1149 -0
- pantalla/fuentes/block.flf +972 -0
- pantalla/fuentes/bloody.flf +1025 -0
- pantalla/fuentes/calvin_s.flf +315 -0
- pantalla/fuentes/colossal.flf +1137 -0
- pantalla/fuentes/cyberlarge.flf +430 -0
- pantalla/fuentes/delta_corps_priest_1.flf +923 -0
- pantalla/fuentes/doom.flf +834 -0
- pantalla/fuentes/dos_rebel.flf +1138 -0
- pantalla/fuentes/electronic.flf +1233 -0
- pantalla/fuentes/epic.flf +936 -0
- pantalla/fuentes/graffiti.flf +618 -0
- pantalla/fuentes/isometric1.flf +1147 -0
- pantalla/fuentes/larry3d.flf +925 -0
- pantalla/fuentes/mini.flf +500 -0
- pantalla/fuentes/ogre.flf +627 -0
- pantalla/fuentes/puffy.flf +821 -0
- pantalla/fuentes/rectangles.flf +615 -0
- pantalla/fuentes/script.flf +854 -0
- pantalla/fuentes/shadow.flf +622 -0
- pantalla/fuentes/slant.flf +736 -0
- pantalla/fuentes/small.flf +618 -0
- pantalla/fuentes/smslant.flf +649 -0
- pantalla/fuentes/speed.flf +742 -0
- pantalla/fuentes/standard.flf +739 -0
- pantalla/fuentes/starwars.flf +720 -0
- pantalla/fuentes/sub-zero.flf +630 -0
- pantalla/herramientas.py +133 -0
- pantalla/juego.py +1033 -0
- pantalla/letras.py +157 -0
- pantalla/matrices.py +291 -0
- pantalla/raton.py +795 -0
- pantalla/spinners.py +344 -0
- pantalla/teclado.py +478 -0
- pantalla/terminal.py +340 -0
- pantalla/texto.py +134 -0
- pantalla-0.3.0.dist-info/METADATA +479 -0
- pantalla-0.3.0.dist-info/RECORD +55 -0
- pantalla-0.3.0.dist-info/WHEEL +5 -0
- pantalla-0.3.0.dist-info/entry_points.txt +2 -0
- pantalla-0.3.0.dist-info/licenses/LICENSE +21 -0
- pantalla-0.3.0.dist-info/top_level.txt +1 -0
pantalla/__init__.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pantalla: dibuja en la terminal de forma fácil.
|
|
3
|
+
|
|
4
|
+
import pantalla
|
|
5
|
+
|
|
6
|
+
pantalla.limpiar()
|
|
7
|
+
pantalla.rodear("=")
|
|
8
|
+
pantalla.centrar("¡Hola!", color="amarillo", negrita=True)
|
|
9
|
+
pantalla.gotoxy(5, 3)
|
|
10
|
+
print("Esto está en la columna 5, fila 3")
|
|
11
|
+
pantalla.esperar()
|
|
12
|
+
|
|
13
|
+
Las posiciones empiezan en 1: (1, 1) es la esquina de arriba a la izquierda,
|
|
14
|
+
x es la columna (hacia la derecha) e y la fila (hacia abajo).
|
|
15
|
+
|
|
16
|
+
Escribe pantalla.ayuda() para ver todo lo que se puede hacer.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .arte import CODIGOS_COLOR, arte
|
|
20
|
+
from .colores import colorear, lista_colores, poner_color, quitar_color
|
|
21
|
+
from .componentes import (barra_progreso, cabecera, calculando, cargando, elegir, mensaje, menu, pie,
|
|
22
|
+
tabla)
|
|
23
|
+
from .dibujo import ESTILOS, caja, linea, linea_vertical, punto, rellenar, rodear
|
|
24
|
+
from .disenos import diseno
|
|
25
|
+
from .herramientas import depurar, regla
|
|
26
|
+
from .juego import Sprite, cada, fotograma, jugar, pulsada, sprites
|
|
27
|
+
from .letras import grande, lista_fuentes, texto_grande
|
|
28
|
+
from .raton import (activar_raton, boton, botones, bucle, desactivar_raton, esperar_clic,
|
|
29
|
+
leer_raton, posicion_raton, zona)
|
|
30
|
+
from .matrices import matriz, pedir_matriz
|
|
31
|
+
from .spinners import Spinner, lista_spinners, spinner
|
|
32
|
+
from .teclado import (confirmar, esperar, pedir, pedir_contrasena, pedir_numero, tecla,
|
|
33
|
+
tecla_pulsada, vaciar_teclado)
|
|
34
|
+
from .terminal import (alto, ancho, centro, gotoxy, guardar_posicion, iniciar, ir_a, limpiar,
|
|
35
|
+
limpiar_linea, mostrar_cursor, ocultar_cursor, pausa, pitido, tamano,
|
|
36
|
+
terminar, titulo_ventana, volver_a_posicion)
|
|
37
|
+
from .texto import centrar, escribir, escribir_derecha, escribir_lento
|
|
38
|
+
|
|
39
|
+
__version__ = "0.3.0"
|
|
40
|
+
|
|
41
|
+
from .terminal import _abrir_en_consola_si_idle as _abrir
|
|
42
|
+
|
|
43
|
+
if _abrir():
|
|
44
|
+
raise SystemExit
|
|
45
|
+
del _abrir
|
|
46
|
+
|
|
47
|
+
_GRUPOS = [
|
|
48
|
+
("Pantalla y cursor", ["limpiar", "limpiar_linea", "gotoxy", "ir_a", "ancho", "alto",
|
|
49
|
+
"tamano", "centro", "ocultar_cursor", "mostrar_cursor",
|
|
50
|
+
"guardar_posicion", "volver_a_posicion", "titulo_ventana",
|
|
51
|
+
"pitido", "pausa", "iniciar", "terminar"]),
|
|
52
|
+
("Escribir", ["escribir", "centrar", "escribir_derecha", "escribir_lento", "grande",
|
|
53
|
+
"texto_grande", "lista_fuentes", "cabecera", "pie"]),
|
|
54
|
+
("Colores", ["colorear", "poner_color", "quitar_color", "lista_colores"]),
|
|
55
|
+
("Dibujar", ["rodear", "caja", "linea", "linea_vertical", "rellenar", "punto", "arte"]),
|
|
56
|
+
("Teclado", ["tecla", "tecla_pulsada", "vaciar_teclado", "esperar", "pedir",
|
|
57
|
+
"pedir_numero", "pedir_contrasena", "confirmar"]),
|
|
58
|
+
("Cosas ya hechas", ["menu", "elegir", "mensaje", "tabla", "barra_progreso", "cargando",
|
|
59
|
+
"calculando", "spinner", "lista_spinners"]),
|
|
60
|
+
("Juegos", ["jugar", "Sprite", "sprites", "cada", "fotograma", "pulsada"]),
|
|
61
|
+
("Matrices", ["matriz", "pedir_matriz"]),
|
|
62
|
+
("Ratón", ["activar_raton", "desactivar_raton", "esperar_clic", "leer_raton",
|
|
63
|
+
"posicion_raton", "zona", "boton", "botones", "bucle"]),
|
|
64
|
+
("Diseñar y ver posiciones", ["diseno", "regla", "depurar"]),
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
__all__ = [nombre for _, nombres in _GRUPOS for nombre in nombres] + ["ayuda", "Spinner", "ESTILOS", "CODIGOS_COLOR"]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
_PARECIDAS = {
|
|
71
|
+
"borrar": "limpiar", "cls": "limpiar", "clear": "limpiar", "borrar_pantalla": "limpiar",
|
|
72
|
+
"print": "escribir", "imprimir": "escribir", "mostrar": "escribir", "poner": "escribir",
|
|
73
|
+
"texto": "escribir", "input": "pedir", "leer": "pedir", "preguntar": "pedir",
|
|
74
|
+
"sleep": "pausa", "dormir": "pausa", "esperar_segundos": "pausa", "wait": "pausa",
|
|
75
|
+
"color": "poner_color", "colores": "lista_colores", "fuentes": "lista_fuentes",
|
|
76
|
+
"posicion": "gotoxy", "mover": "gotoxy", "cursor": "gotoxy", "goto": "gotoxy",
|
|
77
|
+
"rectangulo": "caja", "cuadro": "caja", "recuadro": "caja", "marco": "rodear", "borde": "rodear",
|
|
78
|
+
"titulo": "cabecera", "letras_grandes": "grande", "teclado": "tecla", "getch": "tecla",
|
|
79
|
+
"clic": "esperar_clic", "click": "esperar_clic", "raton": "activar_raton",
|
|
80
|
+
"juego": "jugar", "bucle_juego": "jugar", "progreso": "barra_progreso", "barra": "barra_progreso",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _normalizar(nombre):
|
|
85
|
+
import unicodedata
|
|
86
|
+
|
|
87
|
+
sin_tildes = unicodedata.normalize("NFD", nombre)
|
|
88
|
+
return "".join(c for c in sin_tildes if unicodedata.category(c) != "Mn").lower()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _buscar(nombre):
|
|
92
|
+
"""El nombre de verdad si lo has escrito con tildes, ñ o mayúsculas (tamaño -> tamano)."""
|
|
93
|
+
buscado = _normalizar(nombre)
|
|
94
|
+
for de_verdad in __all__:
|
|
95
|
+
if _normalizar(de_verdad) == buscado:
|
|
96
|
+
return de_verdad
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def __getattr__(nombre):
|
|
101
|
+
if nombre.startswith("_"):
|
|
102
|
+
raise AttributeError("module 'pantalla' has no attribute %r" % nombre)
|
|
103
|
+
de_verdad = _buscar(nombre)
|
|
104
|
+
if de_verdad is not None:
|
|
105
|
+
return globals()[de_verdad]
|
|
106
|
+
import difflib
|
|
107
|
+
|
|
108
|
+
parecidas = []
|
|
109
|
+
if _normalizar(nombre) in _PARECIDAS:
|
|
110
|
+
parecidas.append(_PARECIDAS[_normalizar(nombre)])
|
|
111
|
+
for p in difflib.get_close_matches(_normalizar(nombre), __all__, n=3, cutoff=0.6):
|
|
112
|
+
if p not in parecidas:
|
|
113
|
+
parecidas.append(p)
|
|
114
|
+
aviso = "pantalla no tiene ninguna función que se llame '%s'." % nombre
|
|
115
|
+
if parecidas:
|
|
116
|
+
aviso += " ¿Querías decir " + " o ".join("pantalla.%s" % p for p in parecidas[:3]) + "?"
|
|
117
|
+
aviso += " Para ver todas: pantalla.ayuda()"
|
|
118
|
+
raise AttributeError(aviso)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _primera_linea(nombre):
|
|
122
|
+
return (globals()[nombre].__doc__ or "").strip().split("\n")[0]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _explicacion(funcion):
|
|
126
|
+
texto = (funcion.__doc__ or "(sin explicación)").strip("\n")
|
|
127
|
+
lineas = texto.split("\n")
|
|
128
|
+
sangria = min([len(l) - len(l.lstrip()) for l in lineas[1:] if l.strip()] or [0])
|
|
129
|
+
return [lineas[0].strip()] + [l[sangria:] for l in lineas[1:]]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _ayuda_interactiva():
|
|
133
|
+
from .terminal import _estado
|
|
134
|
+
from .teclado import _modo, _activar_modo_teclas, _desactivar_modo_teclas
|
|
135
|
+
|
|
136
|
+
ya_aparte = _estado["pantalla_aparte"]
|
|
137
|
+
ya_teclas = _modo["original"] is not None
|
|
138
|
+
if not ya_aparte:
|
|
139
|
+
iniciar(cursor=True)
|
|
140
|
+
else:
|
|
141
|
+
_activar_modo_teclas()
|
|
142
|
+
titulos = [t for t, _ in _GRUPOS]
|
|
143
|
+
resumen = {t: ", ".join(n) for t, n in _GRUPOS}
|
|
144
|
+
seccion = titulos[0]
|
|
145
|
+
elegida = None
|
|
146
|
+
try:
|
|
147
|
+
while True:
|
|
148
|
+
if elegida is None:
|
|
149
|
+
limpiar()
|
|
150
|
+
cabecera("pantalla %s · ayuda" % __version__)
|
|
151
|
+
pie("Elige un tema · Enter entrar · Esc salir")
|
|
152
|
+
seccion = menu(titulos, titulo="Temas", ayudas=resumen, inicial=seccion)
|
|
153
|
+
if seccion is None:
|
|
154
|
+
return
|
|
155
|
+
nombres = dict(_GRUPOS)[seccion]
|
|
156
|
+
limpiar()
|
|
157
|
+
cabecera("pantalla %s · ayuda · %s" % (__version__, seccion))
|
|
158
|
+
pie("Elige una función y pulsa Enter para ver cómo se usa · Esc volver a los temas")
|
|
159
|
+
elegida = menu(nombres, titulo=seccion, inicial=elegida or 0,
|
|
160
|
+
ayudas={n: _primera_linea(n) for n in nombres})
|
|
161
|
+
if elegida is None:
|
|
162
|
+
continue
|
|
163
|
+
limpiar()
|
|
164
|
+
cabecera("pantalla." + elegida)
|
|
165
|
+
fila = 3
|
|
166
|
+
for linea_texto in _explicacion(globals()[elegida]):
|
|
167
|
+
if fila >= alto() - 1:
|
|
168
|
+
break
|
|
169
|
+
es_codigo = linea_texto.startswith(" ")
|
|
170
|
+
escribir(linea_texto, 3, fila, color="verde claro" if es_codigo else None,
|
|
171
|
+
negrita=fila == 3)
|
|
172
|
+
fila = fila + 1
|
|
173
|
+
pie("Pulsa una tecla para volver a la lista")
|
|
174
|
+
tecla()
|
|
175
|
+
finally:
|
|
176
|
+
if not ya_aparte:
|
|
177
|
+
terminar()
|
|
178
|
+
elif not ya_teclas:
|
|
179
|
+
_desactivar_modo_teclas()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def ayuda(funcion=None):
|
|
183
|
+
"""Enseña todas las funciones de pantalla, o la explicación de una.
|
|
184
|
+
|
|
185
|
+
pantalla.ayuda() # en una terminal: un menú para ir mirándolas
|
|
186
|
+
pantalla.ayuda("caja") # cómo se usa caja
|
|
187
|
+
pantalla.ayuda(pantalla.caja)
|
|
188
|
+
|
|
189
|
+
Fuera de una terminal (por ejemplo en IDLE), escribe la lista entera.
|
|
190
|
+
"""
|
|
191
|
+
import sys
|
|
192
|
+
|
|
193
|
+
from .terminal import _es_terminal
|
|
194
|
+
|
|
195
|
+
if funcion is not None:
|
|
196
|
+
if isinstance(funcion, str):
|
|
197
|
+
funcion = _buscar(funcion.strip().replace("pantalla.", "").rstrip("()")) or funcion
|
|
198
|
+
if funcion not in __all__ or funcion in ("ESTILOS", "CODIGOS_COLOR"):
|
|
199
|
+
print("No hay ninguna función que se llame %r. Mira la lista con pantalla.ayuda()" % funcion)
|
|
200
|
+
return
|
|
201
|
+
funcion = globals()[funcion]
|
|
202
|
+
print("pantalla.%s" % funcion.__name__)
|
|
203
|
+
print()
|
|
204
|
+
print("\n".join(_explicacion(funcion)))
|
|
205
|
+
return
|
|
206
|
+
if _es_terminal(sys.stdin) and _es_terminal(sys.stdout):
|
|
207
|
+
_ayuda_interactiva()
|
|
208
|
+
return
|
|
209
|
+
print("pantalla %s · todo lo que puedes usar:" % __version__)
|
|
210
|
+
for titulo, nombres in _GRUPOS:
|
|
211
|
+
print()
|
|
212
|
+
print(" " + titulo.upper())
|
|
213
|
+
for nombre in nombres:
|
|
214
|
+
print(" pantalla.%-18s %s" % (nombre, _primera_linea(nombre)))
|
|
215
|
+
print()
|
|
216
|
+
print("Para ver cómo se usa una: pantalla.ayuda(\"caja\")")
|
|
217
|
+
print("Colores: " + ", ".join(lista_colores()))
|
|
218
|
+
print("Estilos de borde: " + ", ".join(ESTILOS) + ", o un carácter como \"=\"")
|
|
219
|
+
print("Para ver una demostración, escribe en la terminal: python -m pantalla")
|
pantalla/__main__.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Demostración de todo lo que hace pantalla. Se abre con: python -m pantalla
|
|
3
|
+
Míralo también por dentro: cada parte es un ejemplo de cómo se usa.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import pantalla
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def portada():
|
|
10
|
+
pantalla.limpiar()
|
|
11
|
+
pantalla.rodear("doble", color="cian", titulo="pantalla " + pantalla.__version__)
|
|
12
|
+
pantalla.grande("PANTALLA", y=2, color="amarillo")
|
|
13
|
+
pantalla.centrar("Dibuja en la terminal de forma fácil", y=8, color="blanco", negrita=True)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def demo_colores():
|
|
17
|
+
pantalla.limpiar()
|
|
18
|
+
pantalla.rodear("simple", color="gris", titulo="Colores")
|
|
19
|
+
y = 3
|
|
20
|
+
for nombre in pantalla.lista_colores():
|
|
21
|
+
pantalla.escribir(nombre.ljust(16), 4, y)
|
|
22
|
+
pantalla.escribir(" texto ", 21, y, color=nombre)
|
|
23
|
+
pantalla.escribir(" fondo ", 32, y, color="negro", fondo=nombre)
|
|
24
|
+
y = y + 1
|
|
25
|
+
pantalla.escribir("negrita", 46, 3, negrita=True)
|
|
26
|
+
pantalla.escribir("tenue", 46, 4, tenue=True)
|
|
27
|
+
pantalla.escribir("cursiva", 46, 5, cursiva=True)
|
|
28
|
+
pantalla.escribir("subrayado", 46, 6, subrayado=True)
|
|
29
|
+
pantalla.escribir("tachado", 46, 7, tachado=True)
|
|
30
|
+
pantalla.escribir("invertido", 46, 8, invertido=True)
|
|
31
|
+
pantalla.escribir("#ff8800 en hexadecimal", 46, 10, color="#ff8800")
|
|
32
|
+
pantalla.escribir("(0, 200, 120) en RGB", 46, 11, color=(0, 200, 120))
|
|
33
|
+
pantalla.esperar("Pulsa una tecla para volver", 4, pantalla.alto() - 1, color="gris")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def demo_cajas():
|
|
37
|
+
pantalla.limpiar()
|
|
38
|
+
x = 3
|
|
39
|
+
for estilo in ["simple", "doble", "grueso", "redondo", "ascii", "*"]:
|
|
40
|
+
pantalla.caja(x, 2, 12, 5, estilo=estilo, titulo=estilo)
|
|
41
|
+
x = x + 13
|
|
42
|
+
pantalla.caja(3, 8, 30, 7, estilo="redondo", color="verde", titulo="Con color")
|
|
43
|
+
pantalla.escribir("Las cajas pueden tener\ntítulo, color y relleno.", 5, 10)
|
|
44
|
+
pantalla.rellenar(36, 8, 20, 7, fondo="azul")
|
|
45
|
+
pantalla.escribir("rellenar()", 41, 11, color="blanco", fondo="azul", negrita=True)
|
|
46
|
+
pantalla.linea(16, "=", color="amarillo")
|
|
47
|
+
pantalla.linea(17, "doble", x=3, largo=40, color="morado")
|
|
48
|
+
for i in range(10):
|
|
49
|
+
pantalla.punto(60 + i * 2, 9 + i % 4, "●", color="rojo claro")
|
|
50
|
+
pantalla.esperar("Pulsa una tecla para volver", 3, pantalla.alto() - 1, color="gris")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def demo_teclas():
|
|
54
|
+
pantalla.limpiar()
|
|
55
|
+
pantalla.rodear("redondo", color="gris", titulo="Teclado")
|
|
56
|
+
pantalla.escribir("Pulsa teclas y te digo cuál es. Esc para salir.", 4, 3, color="amarillo")
|
|
57
|
+
y = 5
|
|
58
|
+
while True:
|
|
59
|
+
t = pantalla.tecla()
|
|
60
|
+
if y > pantalla.alto() - 2:
|
|
61
|
+
pantalla.rellenar(3, 5, pantalla.ancho() - 4, pantalla.alto() - 6)
|
|
62
|
+
y = 5
|
|
63
|
+
pantalla.escribir("pantalla.tecla() devolvió: ", 4, y)
|
|
64
|
+
pantalla.escribir(repr(t), 31, y, color="verde", negrita=True)
|
|
65
|
+
y = y + 1
|
|
66
|
+
if t == "esc":
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def demo_mover():
|
|
71
|
+
pantalla.limpiar()
|
|
72
|
+
pantalla.rodear("simple", color="azul", titulo="Mueve la @ con las flechas · Esc salir")
|
|
73
|
+
x, y = pantalla.centro()
|
|
74
|
+
pantalla.ocultar_cursor()
|
|
75
|
+
while True:
|
|
76
|
+
pantalla.punto(x, y, "@", color="amarillo")
|
|
77
|
+
t = pantalla.tecla()
|
|
78
|
+
pantalla.punto(x, y, " ")
|
|
79
|
+
if t == "arriba" and y > 2:
|
|
80
|
+
y = y - 1
|
|
81
|
+
elif t == "abajo" and y < pantalla.alto() - 1:
|
|
82
|
+
y = y + 1
|
|
83
|
+
elif t == "izquierda" and x > 2:
|
|
84
|
+
x = x - 1
|
|
85
|
+
elif t == "derecha" and x < pantalla.ancho() - 1:
|
|
86
|
+
x = x + 1
|
|
87
|
+
elif t == "esc":
|
|
88
|
+
pantalla.mostrar_cursor()
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def demo_cosas():
|
|
93
|
+
pantalla.limpiar()
|
|
94
|
+
pantalla.escribir("tabla():", 3, 2, color="amarillo")
|
|
95
|
+
pantalla.tabla([["Ana", 8.5], ["Luis", 6], ["Marta", 9.75]], ["Nombre", "Nota"], x=3, y=3)
|
|
96
|
+
pantalla.escribir("barra_progreso():", 3, 11, color="amarillo")
|
|
97
|
+
pantalla.ocultar_cursor()
|
|
98
|
+
for i in range(101):
|
|
99
|
+
pantalla.barra_progreso(i, 100, 3, 12, ancho=40)
|
|
100
|
+
pantalla.pausa(0.015)
|
|
101
|
+
pantalla.escribir("cargando():", 3, 14, color="amarillo")
|
|
102
|
+
pantalla.cargando(2, "Pensando", 3, 15)
|
|
103
|
+
pantalla.escribir_lento("escribir_lento(): como una máquina de escribir...", 3, 17, velocidad=0.03)
|
|
104
|
+
pantalla.mostrar_cursor()
|
|
105
|
+
pantalla.mensaje("Y esto es mensaje().\nSirve para avisos.", titulo="¡Hola!")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def demo_pedir():
|
|
109
|
+
pantalla.limpiar()
|
|
110
|
+
pantalla.rodear("redondo", color="verde", titulo="Pedir datos")
|
|
111
|
+
nombre = pantalla.pedir("¿Cómo te llamas? ", 4, 3, color="cian")
|
|
112
|
+
edad = pantalla.pedir_numero("¿Cuántos años tienes? ", 4, 5, minimo=0, maximo=120, color="cian")
|
|
113
|
+
pantalla.escribir("¿Te gusta Python? (s/n) ", 4, 8, color="cian")
|
|
114
|
+
gusta = pantalla.confirmar("", 28, 8)
|
|
115
|
+
texto = "Hola, %s. Tienes %d años" % (nombre or "persona misteriosa", edad)
|
|
116
|
+
if gusta:
|
|
117
|
+
texto = texto + "\ny te gusta Python. ¡Bien!"
|
|
118
|
+
else:
|
|
119
|
+
texto = texto + "\ny no te gusta Python... todavía."
|
|
120
|
+
pantalla.mensaje(texto, titulo="Resultado", color_borde="verde")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def demo_menus():
|
|
124
|
+
pantalla.limpiar()
|
|
125
|
+
pantalla.cabecera("Menús")
|
|
126
|
+
pantalla.escribir("1) Un menú normal, con ayuda abajo e iconos:", 3, 3, color="amarillo")
|
|
127
|
+
r = pantalla.menu(["Jugar", "Opciones", "Salir"], titulo="Juego", x=6, y=5,
|
|
128
|
+
ayudas={"Jugar": "Empieza una partida nueva", "Opciones": "Sonido y dificultad",
|
|
129
|
+
"Salir": "Vuelve a la demo"},
|
|
130
|
+
iconos={"Jugar": "►", "Opciones": "*", "Salir": "×"})
|
|
131
|
+
pantalla.escribir("Has elegido: %r" % r, 6, 12, color="verde")
|
|
132
|
+
pantalla.escribir("2) elegir(), en una sola línea:", 3, 14, color="amarillo")
|
|
133
|
+
r = pantalla.elegir("¿Dificultad?", ["Fácil", "Normal", "Difícil"], 6, 16)
|
|
134
|
+
pantalla.escribir("Has elegido: %r" % r, 6, 17, color="verde")
|
|
135
|
+
pantalla.esperar("Pulsa una tecla para ver el menú con secciones", 3, 19, color="gris")
|
|
136
|
+
pantalla.limpiar()
|
|
137
|
+
pantalla.cabecera("Menú con secciones")
|
|
138
|
+
r = pantalla.menu({"Operaciones": ["Sumar", "Restar", "Multiplicar"],
|
|
139
|
+
"Determinantes": ["Determinante", "Inversa"],
|
|
140
|
+
"Otros": ["Historial", "Ajustes", "Volver"]},
|
|
141
|
+
ayudas={"Sumar": "Suma dos matrices del mismo tamaño", "Volver": "Vuelve a la demo"},
|
|
142
|
+
iconos={"Sumar": "+", "Restar": "-", "Multiplicar": "×", "Determinante": "|A|",
|
|
143
|
+
"Inversa": "A⁻¹", "Historial": "≡", "Ajustes": "*", "Volver": "←"},
|
|
144
|
+
titulo="Como en el proyecto de matrices", y=3)
|
|
145
|
+
pantalla.escribir("Has elegido: %r" % r, 3, pantalla.alto() - 2, color="verde")
|
|
146
|
+
pantalla.esperar(" Pulsa una tecla para volver", color="gris")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def demo_fuentes():
|
|
150
|
+
fuentes = pantalla.lista_fuentes()
|
|
151
|
+
i = 0
|
|
152
|
+
texto = "Hola"
|
|
153
|
+
while True:
|
|
154
|
+
pantalla.limpiar()
|
|
155
|
+
pantalla.cabecera("Fuentes ASCII · %d de %d" % (i + 1, len(fuentes)))
|
|
156
|
+
pantalla.escribir('pantalla.grande("%s", fuente="%s")' % (texto, fuentes[i]), 3, 3, color="verde")
|
|
157
|
+
pantalla.grande(texto, x=3, y=5, color="amarillo", fuente=fuentes[i])
|
|
158
|
+
pantalla.pie("← → otra fuente · Enter cambiar el texto · Esc volver")
|
|
159
|
+
t = pantalla.tecla()
|
|
160
|
+
if t == "esc":
|
|
161
|
+
return
|
|
162
|
+
if t in ("derecha", "abajo", "espacio"):
|
|
163
|
+
i = (i + 1) % len(fuentes)
|
|
164
|
+
elif t in ("izquierda", "arriba"):
|
|
165
|
+
i = (i - 1) % len(fuentes)
|
|
166
|
+
elif t == "enter":
|
|
167
|
+
nuevo = pantalla.pedir("Texto: ", 3, pantalla.alto() - 2, color="cian")
|
|
168
|
+
texto = nuevo or texto
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def demo_matrices():
|
|
172
|
+
pantalla.limpiar()
|
|
173
|
+
pantalla.cabecera("Matrices")
|
|
174
|
+
A = pantalla.pedir_matriz("A")
|
|
175
|
+
if A is None:
|
|
176
|
+
return
|
|
177
|
+
pantalla.calculando()
|
|
178
|
+
pantalla.cabecera("Matrices")
|
|
179
|
+
pantalla.escribir("pantalla.matriz() la dibuja así:", 3, 3, color="amarillo")
|
|
180
|
+
ancho, alto = pantalla.matriz(A, 3, 5, nombre="A")
|
|
181
|
+
pantalla.matriz(A, 3 + ancho + 4, 5, nombre="|A|", det=True, color="cian")
|
|
182
|
+
pantalla.escribir("Y en Python es esta lista: %r" % (A,), 3, 5 + alto + 1, color="verde")
|
|
183
|
+
pantalla.pie("Pulsa una tecla para volver")
|
|
184
|
+
pantalla.tecla()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def main():
|
|
188
|
+
import sys
|
|
189
|
+
|
|
190
|
+
if len(sys.argv) > 1 and sys.argv[1] in ("depurar", "debug"):
|
|
191
|
+
pantalla.depurar()
|
|
192
|
+
return
|
|
193
|
+
if len(sys.argv) > 1 and sys.argv[1] == "ayuda":
|
|
194
|
+
pantalla.ayuda()
|
|
195
|
+
return
|
|
196
|
+
|
|
197
|
+
secciones = {
|
|
198
|
+
"Lo básico": ["Colores", "Cajas y dibujos", "Fuentes ASCII", "Teclado"],
|
|
199
|
+
"Cosas ya hechas": ["Menús", "Tablas, barras y mensajes", "Pedir datos"],
|
|
200
|
+
"Más": ["Matrices", "Mover una @", "Ver posiciones", "Salir"],
|
|
201
|
+
}
|
|
202
|
+
ayudas = {
|
|
203
|
+
"Colores": "Todos los colores y estilos de texto",
|
|
204
|
+
"Cajas y dibujos": "caja, rodear, rellenar, linea, punto",
|
|
205
|
+
"Fuentes ASCII": "grande() con las 32 fuentes de lista_fuentes()",
|
|
206
|
+
"Teclado": "Pulsa teclas y mira qué devuelve pantalla.tecla()",
|
|
207
|
+
"Menús": "menu() con ayudas e iconos, elegir() y el menú con secciones",
|
|
208
|
+
"Tablas, barras y mensajes": "tabla, barra_progreso, cargando, mensaje",
|
|
209
|
+
"Pedir datos": "pedir, pedir_numero y confirmar",
|
|
210
|
+
"Matrices": "pedir_matriz() con las flechas y matriz() para dibujarla",
|
|
211
|
+
"Mover una @": "Un juego mínimo con las flechas",
|
|
212
|
+
"Ver posiciones": "pantalla.depurar(): mueve una cruz y mira x e y",
|
|
213
|
+
"Salir": "Hasta luego",
|
|
214
|
+
}
|
|
215
|
+
iconos = {
|
|
216
|
+
"Colores": "■", "Cajas y dibujos": "┌┐", "Fuentes ASCII": "A", "Teclado": "Aa", "Menús": "≡",
|
|
217
|
+
"Tablas, barras y mensajes": "▤", "Pedir datos": "?", "Matrices": "[ ]",
|
|
218
|
+
"Mover una @": "@", "Ver posiciones": "╋", "Salir": "←",
|
|
219
|
+
}
|
|
220
|
+
pantalla.iniciar(titulo="pantalla · demo")
|
|
221
|
+
try:
|
|
222
|
+
elegida = "Colores"
|
|
223
|
+
while True:
|
|
224
|
+
portada()
|
|
225
|
+
elegida = pantalla.menu(secciones, ayudas=ayudas, iconos=iconos, y=10, inicial=elegida)
|
|
226
|
+
if elegida is None or elegida == "Salir":
|
|
227
|
+
break
|
|
228
|
+
if elegida == "Colores":
|
|
229
|
+
demo_colores()
|
|
230
|
+
elif elegida == "Cajas y dibujos":
|
|
231
|
+
demo_cajas()
|
|
232
|
+
elif elegida == "Fuentes ASCII":
|
|
233
|
+
demo_fuentes()
|
|
234
|
+
elif elegida == "Teclado":
|
|
235
|
+
demo_teclas()
|
|
236
|
+
elif elegida == "Menús":
|
|
237
|
+
demo_menus()
|
|
238
|
+
elif elegida == "Tablas, barras y mensajes":
|
|
239
|
+
demo_cosas()
|
|
240
|
+
elif elegida == "Pedir datos":
|
|
241
|
+
demo_pedir()
|
|
242
|
+
elif elegida == "Matrices":
|
|
243
|
+
demo_matrices()
|
|
244
|
+
elif elegida == "Mover una @":
|
|
245
|
+
demo_mover()
|
|
246
|
+
elif elegida == "Ver posiciones":
|
|
247
|
+
pantalla.depurar()
|
|
248
|
+
finally:
|
|
249
|
+
pantalla.terminar()
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
if __name__ == "__main__":
|
|
253
|
+
main()
|