Skip to content

Instantly share code, notes, and snippets.

@buntine
Created March 1, 2015 21:09
Show Gist options
  • Save buntine/2da5285c45da065d30a5 to your computer and use it in GitHub Desktop.
Save buntine/2da5285c45da065d30a5 to your computer and use it in GitHub Desktop.
from Tkinter import *
import tkFont
import subprocess, os, re
BASE = "/home/andrew/Downloads/SNES/ROMS/"
def play(e):
lb = e.widget
text = lb.get(ACTIVE)
filename = lb.data[text]
subprocess.call(["mpg321", "excellent.mp3"])
subprocess.call(["snes9x-gtk", os.path.join(BASE, filename)])
def scan(e):
lb = e.widget
char = e.char
curr = lb.get(ACTIVE)
curr_char = curr[0].lower()
def find(items, f):
start = lb.index(ACTIVE)
for i in items:
if i[0].lower() != curr_char:
break
start = f(start)
return start
if char == 'c':
rest = lb.get(ACTIVE, END)
index = find(rest, lambda n: n + 1)
else:
rest = list(lb.get(0, ACTIVE))
rest.reverse()
index = find(rest, lambda n: n - 1)
lb.selection_clear(0, END)
lb.see(index)
lb.selection_set(index)
lb.activate(index)
master = Tk()
frame = Frame(master)
scrollbar = Scrollbar(frame, orient=VERTICAL)
listbox = Listbox(frame, yscrollcommand=scrollbar.set)
list_font = tkFont.Font(
family="Silkscreen",
size=-31,
weight="bold")
master.bind('<Escape>', lambda e: master.destroy())
master.config(background="#10171F")
master.attributes("-fullscreen", True)
frame.config(background="#10171F")
frame.grid(
row=0,
column=2,
sticky="n")
scrollbar.config(
command=listbox.yview,
background="#10171F",
borderwidth=0,
width=0)
scrollbar.pack(
side=RIGHT,
fill=Y,
pady=17)
listbox.data = {}
listbox.pack(
side=LEFT,
fill=BOTH,
expand=1,
pady=17,
ipadx=20)
listbox.config(
borderwidth=0,
highlightthickness=0,
width=61,
height=23,
background="#10171F",
foreground="mint cream",
font=list_font,
selectforeground="#10171F",
selectbackground="#cccccc",
selectborderwidth=2,
relief="flat")
listbox.bind("<Return>", play)
listbox.bind("<Key c>", scan)
listbox.bind("<Key v>", scan)
photo = PhotoImage(file="instructions.gif")
label = Label(image=photo, borderwidth=0)
label.image = photo
label.grid(
row=0,
column=1,
padx=0,
sticky="n",
pady=10)
for _, _, filenames in os.walk(BASE):
for filename in sorted(filenames):
display_name = filename.split(".")[0]
display_name = display_name.replace("_", " ")
listbox.data[display_name] = filename
listbox.insert(END, display_name)
listbox.selection_set(ACTIVE)
listbox.focus_set()
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment