-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.py
More file actions
57 lines (47 loc) · 1.49 KB
/
Copy pathMenu.py
File metadata and controls
57 lines (47 loc) · 1.49 KB
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
# -*- encoding: utf-8 -*-
from Opcion import Opcion
import os
import Interfaz
class Menu():
def __init__(self, objeto):
opcionQuit = Opcion('q', 'self.salir()', 'salir')
self.opciones = [opcionQuit]
self.debeCorrer = False
self.mensaje = []
self.objeto = objeto
self.dictOpciones = {'q': opcionQuit}
def salir(self):
self.debeCorrer = False
Interfaz.infog('\n..... bay.....\n')
def imprimirMenu(self):
lista = self.dictOpciones.items()
lista.sort()
for opcion in lista:
Interfaz.cyan(opcion[1].imprimir())
Interfaz.info("Atributos parseados:%i A procesar:%i" % (len(self.objeto.atributos) -1, len(self.objeto.atributosAProcesar)))
def imprimirOpcionInvalida(self):
Interfaz.err('Opcion Invalida')
def imprimirError(self,opcion):
Interfaz.err('hubo un error al ejecutar ' + self.dictOpciones[opcion].descripcion)
def correr(self):
self.debeCorrer = True
mensaje = ""
while self.debeCorrer:
self.imprimirMenu()
print(mensaje)
opcion = str(raw_input('Ingrese alguna de las opciones\n\n'))
self.ejecutar(opcion)
def getOpciones(self):
return self.opciones
def agregarOpcion(self, nombre,execs, descripcion="",ayuda=""):
opcion = Opcion(nombre,execs,descripcion,ayuda)
self.dictOpciones[opcion.getNombre()] = opcion
def ejecutar(self, opcion):
if opcion in self.dictOpciones.keys():
opcion = self.dictOpciones[opcion]
try:
exec(opcion.execs)
except Exception as inst:
Interfaz.err(str(inst))
else:
self.imprimirOpcionInvalida()