# Bryan Schumaker (10/4/2010)

import ocarina
gtk = ocarina.gtk
LS  = ocarina.libsaria

body = ocarina.body
filter = None

class FilterEntry(gtk.Entry):
	def __init__(self):
		gtk.Entry.__init__(self)
		global filter
		filter = self
		self.connect("changed", self.filter)
		self.show()

	def filter(self, entry):
		body.cur_page_filter(entry.get_text())

def key_press(widget, event):
	name = gtk.gdk.keyval_name(event.keyval)
	if name == "Escape":
		ocarina.window.window.set_focus(None)
		return
	if filter.is_focus():
		return
	if name == "space":
		LS.controls.toggle_play()
	elif name == "slash":
		filter.grab_focus()
	elif name == "Left":
		LS.controls.seek_backward()
	elif name == "Right":
		LS.controls.seek_forward()
	elif name == "d":
		ocarina.footer.down_button()
	elif name == "g":
		body.cur_page_goto()
	elif name == "n":
		LS.controls.next()
	elif name == "s":
		LS.controls.stop()
	elif name == "u":
		ocarina.footer.up_button()
	else:
		#print name
		return False
	widget.emit_stop_by_name("key-press-event")
	return True
