initial
This commit is contained in:
commit
3997fd814d
126
main.py
Normal file
126
main.py
Normal file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tkinter as tk
|
||||
import requests
|
||||
import tkinter.ttk as ttk
|
||||
|
||||
# Useful gubbins
|
||||
border_effects = {
|
||||
"flat": tk.FLAT,
|
||||
"sunken": tk.SUNKEN,
|
||||
"raised": tk.RAISED,
|
||||
"groove": tk.GROOVE,
|
||||
"ridge": tk.RIDGE,
|
||||
}
|
||||
|
||||
REPO_URL = "http://10.6.9.5"
|
||||
|
||||
def handle_keypress(event):
|
||||
print(event.char)
|
||||
|
||||
|
||||
def handle_click(event):
|
||||
print("The button has been clicked", event)
|
||||
|
||||
def handle_game_click(event, rom_data, dest_frame):
|
||||
# clean up old info
|
||||
for widget in dest_frame.winfo_children():
|
||||
widget.destroy()
|
||||
#sys_label = tk.Label(text=rom_data['name'], master=dest_frame, font=('Times', 24))
|
||||
sys_label = ttk.Label(text=rom_data['name'], master=dest_frame, font=('Times', 24))
|
||||
sys_label.pack(anchor="w", pady=11, padx=11)
|
||||
|
||||
#lbl_info = tk.Label(text="Info:", master=dest_frame, font=('Times', 15))
|
||||
lbl_info = ttk.Label(text="Info:", master=dest_frame, font=('Times', 15))
|
||||
lbl_info.pack(anchor="w", padx=11)
|
||||
|
||||
#lbl_uri = tk.Label(text=f"URI: {rom_data['uri']}", master=dest_frame)
|
||||
lbl_uri = ttk.Label(text=f"URI: {rom_data['uri']}", master=dest_frame)
|
||||
lbl_uri.pack(anchor="w", padx=11)
|
||||
|
||||
#lbl_base = tk.Label(text=f"BASE ROM: {rom_data['contents']['base']['name']}", master=dest_frame)
|
||||
lbl_base = ttk.Label(text=f"BASE ROM: {rom_data['contents']['base']['name']}", master=dest_frame)
|
||||
lbl_base.pack(anchor="w", padx=11)
|
||||
|
||||
#lbl_size = tk.Label(text=f"SIZE: {rom_data['contents']['base']['size']}", master=dest_frame)
|
||||
lbl_size = ttk.Label(text=f"SIZE: {rom_data['contents']['base']['size']}", master=dest_frame)
|
||||
lbl_size.pack(anchor="w", padx=11)
|
||||
|
||||
#lbl_updates = tk.Label(text="Updates:", master=dest_frame, font=('Times', 15))
|
||||
lbl_updates = ttk.Label(text="Updates:", master=dest_frame, font=('Times', 15))
|
||||
lbl_updates.pack(anchor="w", padx=11)
|
||||
|
||||
# Render updates
|
||||
for update in enumerate(rom_data['contents']['updates']):
|
||||
#lbl_update = tk.Label(text=f"{update[0]} - {update[1]['name']}", master=dest_frame)
|
||||
lbl_update = ttk.Label(text=f"{update[0]} - {update[1]['name']}", master=dest_frame)
|
||||
lbl_update.pack(anchor="w", padx=11)
|
||||
|
||||
#lbl_dlcs = tk.Label(text="DLC:", master=dest_frame, font=('Times', 15))
|
||||
lbl_dlcs = ttk.Label(text="DLC:", master=dest_frame, font=('Times', 15))
|
||||
lbl_dlcs.pack(anchor="w", padx=11)
|
||||
|
||||
# Render DLC
|
||||
for dlc in enumerate(rom_data['contents']['dlc']):
|
||||
#lbl_dlc = tk.Label(text=f"{dlc[0]} - {dlc[1]['name']}", master=dest_frame)
|
||||
lbl_dlc = ttk.Label(text=f"{dlc[0]} - {dlc[1]['name']}", master=dest_frame)
|
||||
lbl_dlc.pack(anchor="w", padx=11)
|
||||
|
||||
def handle_menu_click(event, rom_cat, dest_frame):
|
||||
|
||||
# clean up old info
|
||||
for widget in dest_frame.winfo_children():
|
||||
widget.destroy()
|
||||
|
||||
#sys_label = tk.Label(text=repo_data['roms'][rom_cat]['name'], master=dest_frame, font=('Times', 24))
|
||||
sys_label = ttk.Label(text=repo_data['roms'][rom_cat]['name'], master=dest_frame, font=('Times', 24))
|
||||
sys_label.pack(anchor="w", pady=11, padx=11)
|
||||
|
||||
|
||||
# Get info from uri
|
||||
new_data = requests.get(f"{REPO_URL}/{repo_data['roms'][rom_cat]['uri']}/repodata.json").json()
|
||||
# print(new_data)
|
||||
for data in new_data['roms']:
|
||||
def _handle_click(event, rom_data=data):
|
||||
return handle_game_click(event, rom_data, info_frame)
|
||||
#btn_rom = tk.Button(text=data['name'], master=dest_frame)
|
||||
btn_rom = ttk.Button(text=data['name'], master=dest_frame)
|
||||
btn_rom.bind("<Button-1>", _handle_click)
|
||||
btn_rom.pack(anchor="w", padx=11)
|
||||
|
||||
|
||||
# Get repo data from repo
|
||||
repo_data = requests.get(f"{REPO_URL}/repodata.json").json()
|
||||
|
||||
print(repo_data['roms'])
|
||||
|
||||
# Define tkinter window object
|
||||
window = tk.Tk()
|
||||
window.minsize(1600, 900)
|
||||
window.bind("<Key>", handle_keypress)
|
||||
|
||||
#list_frame = tk.Frame()
|
||||
list_frame = ttk.Frame()
|
||||
list_frame.pack(side=tk.LEFT, padx=10, pady=2, anchor="n")
|
||||
|
||||
#lbl_list = tk.Label(text="Systems", master=list_frame)
|
||||
lbl_list = ttk.Label(text="Systems", master=list_frame)
|
||||
lbl_list.pack()
|
||||
|
||||
#info_frame = tk.Frame( relief=border_effects["sunken"])
|
||||
info_frame = ttk.Frame( relief=border_effects["sunken"])
|
||||
info_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, pady=5, padx=5)
|
||||
|
||||
# dict of sets of buttons
|
||||
buttons = {}
|
||||
for rom_cat in repo_data['roms']:
|
||||
def handle_click_data(event, rom_cat=rom_cat):
|
||||
return handle_menu_click(event, rom_cat=rom_cat, dest_frame=info_frame)
|
||||
|
||||
#buttons[rom_cat] = tk.Button(text=rom_cat, master=list_frame, width=15)
|
||||
buttons[rom_cat] = ttk.Button(text=rom_cat, master=list_frame, width=15)
|
||||
buttons[rom_cat].pack(padx=10)
|
||||
buttons[rom_cat].bind("<Button-1>", handle_click_data)
|
||||
|
||||
|
||||
window.mainloop()
|
||||
Loading…
x
Reference in New Issue
Block a user