def loop(): """Menu loop""" data.ruta_data('json', '') window = menu.build() while True: event, _values = window.read() if event in (sg.WIN_CLOSED, '-BOT_SALIR-'): break if event == '-BOT_FIFA-': inicializar(('data_fifa.json', 'data_fifa.csv', window), fifa_menu) if event == '-BOT_JUEGOS-': inicializar(('video_juegos.json', 'video_juegos.csv', window), games_menu) return window
def obtener_lista(nom_json): ruta_json = data.ruta_data('json', nom_json) try: with open(ruta_json, 'r') as file: info = json.load(file) except FileNotFoundError: print('Error al intentar leer el archivo') return info
def games_estadisticas(datos): button, nombre_json, orden_key, cant = datos if not os.path.isfile(data.ruta_data('json', nombre_json)): try: ruta_data_games = data.ruta_data('json', 'video_juegos.json') with open(ruta_data_games, 'r') as file: dic = json.load(file) juegos = [] for i, valor in dic.items(): if button == 'a': #juegos de nintendo DS con mas ventas globales if valor['Publisher'] == 'Nintendo' and valor[ 'Platform'] == 'DS': juegos.append( dict(ID=i, Nombre=valor['Name'], Ventas=float(valor['Global_Sales']))) elif button == 'b': #juegos de pc con mejores criticas en el 2010 if valor['Platform'] == 'PC' and valor[ 'Year_of_Release'] == '2010': if not valor['Critic_Score'] == '': juegos.append( dict(ID=i, nombre=valor['Name'], Critica=int(valor['Critic_Score']))) else: # 5 juegos de deportes mas vendidos en Norte America if valor['Genre'] == 'Sports': juegos.append( dict(ID=i, Nombre=valor['Name'], Ventas=float(valor['NA_Sales']))) juegos = sorted(juegos, key=lambda juego: juego[orden_key], reverse=True) #Escribo el archivo en /data/json/'nombre_json'.json try: with open(data.ruta_data('json', nombre_json), mode='w') as file: file.write(json.dumps(juegos[:cant], indent=2)) except: print(f'Error al escribir el archivo {nombre_json}') except FileNotFoundError: print('Error al encontrar el archivo video_juegos.json')
def build(): icono = data.ruta_data('images', 'futbol-icon.ico') "Devuele el la ventana con el layout definido" #---estilos--- color_fondo = "#eeeeee" fuente = ('Sans-serif', 10, 'bold') ventana = { 'size': (500, 300), 'background_color': color_fondo, 'element_justification': 'center' } botones = { 'size': (45, 2), 'button_color': '#084405', 'font': fuente, 'border_width': 3, 'focus': True } titulos = { 'font': ('Arial Black', 24), 'background_color': color_fondo, 'text_color': '#1d3fea' } # ---Layout--- layout = [ [sg.Text(k='-TITULO-', text='FIFA 19', **titulos)], [ sg.Button(k='-BOT_A-', button_text='20 jugadores con mejor control', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button( k='-BOT_B-', button_text='10 jugadores argentinos con mejor reputacion', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_C-', button_text='20 jugadores mas caros', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_VOLVER-', button_text='Menu principal', pad=((0, 0), (25, 0)), **botones) ] ] window = sg.Window('FIFA Menu', layout, **ventana, icon=icono) return window
def build(): icono = data.ruta_data('images', 'main-icon.ico') "Devuele la ventana con el layout definido" #---estilos--- color_fondo = "#3a064d" fuente = ('Calibri', 10) ventana = { 'size': (300, 200), 'background_color': color_fondo, 'element_justification': 'center' } botones = { 'size': (15, 1), 'button_color': '#cb0f42', 'font': fuente, 'border_width': 3, 'focus': True } titulos = { 'font': ('Arial Black', 15), 'background_color': color_fondo, 'text_color': '#ffffff' } barra = { 'max_value': 1000, 'visible': False, 'size': (400, 10), 'pad': ((0, 0), (15, 0)) } # ---Layout--- layout = [[sg.Text(k='-TITULO-', text='Analisis de datos', **titulos)], [ sg.Button(k='-BOT_FIFA-', button_text='Jugadores de FIFA', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_JUEGOS-', button_text='Videojuegos', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_SALIR-', button_text='Salir', pad=((0, 0), (25, 0)), **botones) ], [sg.ProgressBar(k='-STATUS_BAR-', **barra)]] window = sg.Window('Menu', layout, **ventana, icon=icono) return window
def jugadores_estadisticas(datos): """Almacena en un archivo json los datos seleccionados""" button, nombre_json, clave = datos if not data.archivo_json_existe( nombre_json): #verifico el archivo de estadisticas no esta creado try: ruta_data_json = data.ruta_data('json', 'data_fifa.json') with open(ruta_data_json, 'r') as file: dic = json.load(file) lista = crear_datos(dic, clave, button) try: with open(data.ruta_data('json', nombre_json), 'w') as file: file.write(json.dumps(lista, indent=4)) except: print(f'Algo salio mal al intentar crear el archivo json') except: print( f'Algo ocurrio al intentar abrir el archivo json -> {ruta_data_json}' ) else: return None
def build(lista): icono = data.ruta_data('images', 'json-icon.ico') layout = [[ sg.Button(k='-BOT_VOLVER-', button_text='Volver', size=(20, 1)) ], [ sg.Listbox(k='LISTBOX_DATA', values=lista, text_color='#f1f1f1', background_color='#714e8b', size=(800, 300), font=('Consolas', 9)) ]] window = sg.Window('Visor JSON', layout, size=(800, 300), background_color='#252525', icon=icono) return window
def build(): icono = data.ruta_data('images', 'pad-icon.ico') "Devuele el la ventana con el layout definido" #---estilos--- color_fondo = "#fb8c00" fuente = ('Calibri', 10, 'bold') ventana = { 'size': (500, 400), 'background_color': color_fondo, 'element_justification': 'center' } botones = { 'size': (45, 3), 'button_color': '#1b5e20', 'font': fuente, 'border_width': 3, 'focus': True } titulos = { 'font': ( 'Arial Black', 20, ), 'background_color': color_fondo, 'text_color': '#17202a' } # ---Layout--- layout = [ [sg.Text(k='-TITULO-', text='JUEGOS', **titulos)], [ sg.Button(k='-BOT_A-', button_text='20 juegos con mas ventas en NINTENDO DS', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button( k='-BOT_B-', button_text='10 juegos con mejores criticas en PC (2010)', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_C-', button_text= '5 juegos de deportes mas vendidos en Norte America', pad=((0, 0), (10, 0)), **botones) ], [ sg.Button(k='-BOT_VOLVER-', button_text='Menu Principal', pad=((0, 0), (35, 0)), **botones) ], ] window = sg.Window('Games Menu', layout, **ventana, icon=icono) return window