# -*- coding: cp1252 -*-
#--------------------------------------------
#Autor: GeSeM (S3KH) Grisolía Emilio.
# Se permite la modificación, y edición de jazzer. Dejando a la moral de cada uno el hecho de mantener o no los créditos.
#Prohibido distribuirlo compilado SIN el fichero de texto, puesto que es código abierto.
#Programado en Python 2.7.
#--
#Versión 2.0
# Espero, pueda servirles un poco...!
# Septiembre, 2011. Argentina.
#--------------------------------------------
print 'Cargando Jazzer...'
print 'Cargando datos... 100%'
ERROR01 = 'Error (Argumento invalido): '
ERROR02 = 'Error (Función inexistente): '
ERROR03 = 'Error (Dato/s invalido/s): '
VAR = 'VAR'
n = '-n'
endl = 'endl'
print 'Cargando (modulos)... 100%'
#--- MÓDULOS IMPORTADOS ---#
import os, time, math, cmath, sys
print 'Cargando ctypes... 100%'
from ctypes import *
#-- El uso de ctypes brinda la posibilidad de poder usar las APIs de Windows, entre demás prestaciones de C
#------------CONSTANTES (WIN32API)------------------------#
print 'Cargando jazzer (GENERIC_READ)... 100%'
#GENERIC_READ
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
#-- Tipos de dato C
print 'Cargando datos C... 100%'
Short = c_short
uShort = c_ushort
Long = c_long
#-- HWND (GetStdHandle)
print 'Cargando HWND_STD(IO)... 100%'
HWND_StdOut = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
HWND_StdIn = windll.kernel32.GetStdHandle(STD_INPUT_HANDLE)
#------------CONSTANTES (COLORES)--------------------------#
# Dados en formato hexadecimal #
#----------------------------------------------------------#
print 'Cargando colores... 100%'
FOREGROUND_BLACK = 0x0000
FOREGROUND_BLUE = 0x0001
FOREGROUND_GREEN = 0x0002
FOREGROUND_CYAN = 0x0003
FOREGROUND_RED = 0x0004
FOREGROUND_MAGENTA = 0x0005
FOREGROUND_YELLOW = 0x0006
FOREGROUND_GREY = 0x0007
FOREGROUND_INTENSITY = 0x0008 # Color de texto intensificado
BACKGROUND_BLACK = 0x0000
BACKGROUND_BLUE = 0x0010
BACKGROUND_GREEN = 0x0020
BACKGROUND_CYAN = 0x0030
BACKGROUND_RED = 0x0040
BACKGROUND_MAGENTA = 0x0050
BACKGROUND_YELLOW = 0x0060
BACKGROUND_GREY = 0x0070
BACKGROUND_INTENSITY = 0x0080 # Fondo de texto intensificado
#-------------------------------------------------------------#
#-------- Carácter de emisión de sonido
beep = chr(7)
#----- CONSTANTES (Gráficas) ----------------------------------#
print 'Constantes graficas... 100%'
#----- LÍNEAS (ASCII EXTENDIDO) -----#
# Usadas para la construccion de menúes
# formato de constante:
# Las constantes de las líneas se componen de un prefijo "l", seguido de una S o una D
# para indicar si es simple(S) o doble(D). Finalmente, un juego de 3 letras indica cuál caracter es:
#-- ES(I/D) = Esquina Superior (Izquierda o Derecha)
#-- EI(I/D) = Esquina Inferior (Izquierda o Derecha)
#-- HOR = HORizontal
#-- VER = VERtical
#-- CRZ = CRuZ
#-- T(DI/ID)= "T" (Derecha>Izquierda / Derecha<Izquierda) (Línea "T" que apunta hacia un lado)
#-- LT(B/A) = Línea T (Baja / Alta) (De abajo hacia arriba / De arriba hacia abajo)
#----------LÍNEAS DOBLES---------------------------#
lDESI = chr(201) #-- Esquina superior izquierda
lDESD = chr(187) #-- Esquina superior derecha
lDEID = chr(188) #-- Esquina inferior derecha
lDEII = chr(200) #-- Esquina inferior izquierda
lDVER = chr(186) #-- Línea doble vertical
lDHOR = chr(205) #-- Linea doble horizontal
lDLTA = chr(203) #-- Línea "T" (Arriba)
lDLTB = chr(202) #-- Línea "T" (Abajo)
lDTID = chr(185) #-- Línea "T" (Izquierda>Derecha)
lDTDI = chr(204) #-- Línea "T" (Derecha>Izquierda)
lDCRZ = chr(206) #-- Linea doble "cruz"
#----------LÍNEAS SIMPLES---------------------------#
lSEII = chr(192) #-- Esquina inferior izquierda
lSESI = chr(218) #-- Esquina superior izquierda
lSESD = chr(191) #-- Esquina superior derecha
lSEID = chr(217) #-- Esquina inferior derecha
lSVER = chr(179) #-- Línea vertical
lSHOR = chr(196) #-- Línea horizontal
lSTID = chr(195) #-- Línea "T" (Izquierda>Derecha)
lSLTB = chr(193) #-- Línea "T" (abajo)
lSLTA = chr(194) #-- Línea "T" (arriba)
lSTDI = chr(180) #-- Linea "T" (Derecha>Izquierda)
lSCRZ = chr(197) #-- Línea "cruz"
#----------------GRÁFICOS---------------------------#
# Carácteres que son usados para rellenar espacios
# o gráficos, animaciones, etc
#----------------------------------------------------#
fill_1 = chr(176) #-- Menos saturado
fill_2 = chr(177)
fill_3 = chr(178)
fill_4 = chr(219) #-- Mas saturado
#--
fill_5 = chr(220)
fill_6 = chr(221)
fill_7 = chr(222)
fill_8 = chr(223)
blank = ' '
P = '.'
D1, D2 = '<', '>'
line = chr(10)
print 'Secuencias (animaciones)... 100%'
#---------SECUENCIAS--------------------------------#
# Las animaciones son secuencias de carácteres
# que mostrados (respetando dicha secuencia)
# generan "imágenes" en movimiento.
# Se almacenan en listas, para ser impresas
# siguiendo el orden en ellas.
#----------------------------------------------------#
ANIM01 = [P, P*2, P*3] #Secuencia de 3 puntos suspensivos
ANIM02 = [D1, D1*2, D1*3] #Secuencia con los direccionales (<)
ANIM03 = [D2, D2*2, D2*3] #Secuencia con los direccionales (>)
ANIM04 = [fill_1, fill_2, fill_3, fill_4] #Secuencia con carácteres de relleno
ANIM05 = ['\\', lSVER*2, '/', lSHOR*2] #Secuencia de barra giratoria
ANIM06 = [blank, D1] #Prompt titilante
print 'Cargando controles... 100%'
#----------CONSTANTES DE CONTROLES------------------#
# Hay disponibles los siguientes "controles":
# Cajas de aviso
# Cajas de ingreso de datos
# Relojes (Numeración romana, occidenta (Analógica / Digital)
# Barras separadoras
#---------------------------------------------------#
# Próximamente (Barras de progreso, animaciones ASCII)
# Y mas...!
#--CAJAS DE TEXTO (Marco doble) (Argumentos)
DBox = 'DBox'
DDBox = 'DDBox'
DIBox = 'DIBox'
D1Box = 'D1Box'
D2Box = 'D2Box'
#--CAJAS DE TEXTO (Marco simple) (Argumentos)
SBox = 'SBox'
SDBox = 'SDBox'
SIBox = 'SIBox'
S1Box = 'S1Box'
S2Box = 'S2Box'
#Lista de cajas
Boxes = [DBox, DDBox, DIBox, D1Box, D2Box, SBox, SDBox, SIBox, S1Box, S2Box]
#------------- Relojes ----------------------#
CLOCK_OCC = 'CLOCK_OCC'
CLOCK_ROM = 'CLOCK_ROM'
DIGITAL = 'DIGITAL'
ANALOGIC = 'ANALOGIC'
FORM12 = 'FORM12' #Formato de 12horas
FORM24 = 'FORM24' #Formato de 24horas
sContext = 'sRecuadro' #Sin recuadro
Context1 = 'Recuadro1' #Recuadro rectangular o cuadrado
Context2 = 'Recuadro2' #Recuadro circular o redondeado
NUM_OCC12 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
NUM_OCC24 = NUM_OCC12
iN = 13
while (iN <= 24):
NUM_OCC24.append(iN)
iN += 1
NUM_ROM = {1:'I',
2:'II',
3:'III',
4:'IV',
5:'V',
6:'VI',
7:'VII',
8:'VIII',
9:'IX',
10:'X',
11:'XI',
12:'XII'
}
#---------------------------------------------#
print 'Cargando estructuras C... 100%'
#-------------------------------------------------------------------------------------#
#--ESTRUCTURAS C------------------------------#
# Las estructuras C son utilizadas
# junto con ctypes para poder invocar funciones
# del sistema operativo, que necesiten apuntar
# a estructuras de datos
#-----------------------------------
# Visitar MSDN y documentación de Python para mas información.
#----------------------Console (ScreenBufferInfo)
class COORD(Structure): #-- Estructura para coordenadas.
_fields_ =[
('X', Short),
('Y', Short)
]
class SMALL_RECT(Structure): #-- Estructura para posiciones.
_fields_ =[
('Left', Short),
('Top', Short),
('Right', Short),
('Bottom',Short)
]
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ =[
('dwSize', COORD),
('dwCursorPosition', COORD),
('wAttributes', uShort),
('srWindow', SMALL_RECT),
('dwMaximumWindowSize', COORD)
]
print 'Cargando funciones... (Misc)'
#--- Reversión de una cadena
#--- (Argumento = Cadena)
def strReverse(String):
reversedString = ''
reverseIndex = -1
abs_maxCount = abs(len(String))
while (abs(reverseIndex) <= abs_maxCount):
reversedString = reversedString + String[reverseIndex]
reverseIndex -= 1
return reversedString
#--- Obtención de cadena de mayor y menor longitud, o número mas grande y mas chico
#--- Devuelve una tupla, siendo elemento 0 el mayor y 1 el menor.
#--- Los arugmentos son: 'str', 'num', para indicar si se trabaja con una cadena o números.
#--- Traspasar cualquier cantidad de cadenas/números
def GetValues(valueType, *Values):
valTypes = ('str', 'num');
if not (valueType in valTypes): return ERROR01+valueType;
if (valueType==valTypes[0]):
maxStr, minStr = '', '';
lenValues = len(Values);
Count = 0;
maxCount = (lenValues - 1);
while (Count < maxCount):
if (len(Values[Count]) > len(Values[Count+1])):
maxStr=Values[Count];
minStr=Values[Count+1];
elif (len(Values[Count]) < len(Values[Count+1])):
maxStr=Values[Count+1];
minStr=Values[Count];
Count += 1;
return maxStr, minStr;
elif (valueType==valTypes[1]):
tmpMenor = 0
tmpMayor = 0
longitudValores =len(Valores)
Contador = 0
maxContador = (longitudValores-1)
while (Contador < maxContador):
if (Valores[Contador] >= Valores[Contador+1]):
tmpMayor = Valores[Contador]
tmpMenor = Valores[Contador+1]
elif (Valores[Contador] <= Valores[Contador+1]):
tmpMayor = Valores[Contador+1]
tmpMenor = Valores[Contador]
Contador += 1
return tmpMayor, tmpMenor
print 'Cargando funciones (WINAPI32)...100%'
#------------------------------FUNCIONES---------------------------------#
#--- Manejo de consola (Color e información)
#--- No necesita argumentos, devuelve el color de consola.
def GetConsoleColor():
GConsoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO()
windll.kernel32.GetConsoleScreenBufferInfo(HWND_StdOut, byref(GConsoleScreenBufferInfo))
return hex(GConsoleScreenBufferInfo.wAttributes)
#--- Argumento = Color
def SetConsoleColor(Color):
bool = windll.kernel32.SetConsoleTextAttribute(HWND_StdOut, Color)
return bool
#-------------------------------------------------------------------------#
print 'Cargando funciones de cálculo lineal... 100%'
class Lineal:
# Cálculo líneal
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
# Obtención de discriminante
def Discriminante(self):
Discriminante = self.b*self.b -4*self.a*self.c
return Discriminante
# Obtención de raices (Soporte para raices en campo complejo)
def raices(self):
Discriminante = self.b*self.b -4*self.a*self.c
if (Discriminante < 0):
real = -self.b/(2*self.a)
imag = math.sqrt (-Discriminante)/(2*self.a)
return 'Im', 'X1', real, imag, 'X2', real, imag
elif (Discriminante > 0):
X1 = (-self.b + math.sqrt (Discriminante))/(2*self.a)
X2 = (-self.b - math.sqrt (Discriminante))/(2*self.a)
return '2', X1, X2
elif (Discriminante == 0):
X = -self.b/(2*self.a)
return '1', X
#-----------Draws--------------------------------------------------------#
def pchar(char): sys.stdout.write(char);
def iprint(Color, jline, *iText):
def tpchar(Text):
for item in Text: pchar(str(item));
if (Color != n):
prevColor = hex(GetConsoleColor());
SetConsoleColor(Color);
Count = 0;
fText = [];
for item in iText:fText.append(str(item));
for item in fText:tpchar(str(item));
if (Color != n):
SetConsoleColor(prevColor);
if (jline == endl):
print line
class Draw:
def __init__(self, *Args):
self.Args = Args #-- En construcción
#----------CONTROLES------------------------------------------------------#
print 'Cargando controles... 100%'
class Control:
def __init__(self, *Options):
if not (Options):
pass;
lnOptions = len(Options)
#-- En construcción
def Box(self, Color, Sound, Stop, Text, box):
if not (box in Boxes):
x = Control()
Control.sbox(x, 0xC, 0, 1, 'Error <box inválido>', DBox)
lenLDH = lDHOR*len(Text)
txtLn = lDVER+Text+lDVER
prevColor = GetColor()
SetConsoleColor(Color)
#-- Verificación argumento caja --#
if (box == DBox):
print lDESI+lenLDH+lDESD+line+txtLn+line+lDEII+lenLDH+lDEID
SetConsoleColor(prevColor)
if (Sound == 1): sys.stdout.write(chr(7))
if (Stop == 1): raw_input()
elif (box == DDBox):
print lDESI+lenLDH+lDLTA+line+txtLn+line+lDEII+lenLDH+lDLTB
SetConsoleColor(prevColor)
if (Sound == 1): sys.stdout.write(chr(7))
if (Stop == 1): raw_input()
elif (box == DIBox):
print lDLTA+lenLDH+lDESD+line+txtLn+line+lDLTB+lenLDH+lDEID
SetConsoleColor(prevColor)
if (Sound == 1): sys.stdout.write(chr(7))
if (Stop == 1): raw_input()
elif (box == D1Box):
print lDHOR+lenLDH+lDHOR+line+Texto+line+lDHOR+lenLDH+lDHOR
SetConsoleColor(prevColor)
if (Sound == 1): sys.stdout.write(chr(7))
if (Stop == 1): raw_input()
elif (box == D2Box):
print lDVER+(blank*len(Texto))+lDVER+line+lDVER+Texto+lDVER+line+lDVER+(blank*len(Texto))+lDVER;
SetConsoleColor(prevColor);
if (Sound == 1): sys.stdout.write(chr(7));
if (Stop == 1): raw_input();