# Bryan Schumaker (3 / 11 / 2011) import gtk from libsaria import controls keyval_name = gtk.gdk.keyval_name shortcut_map = {} def null_shortcut(): return False # Setting allow_filter_focus to True means that the # registered shortcut will always run, even if the # filter entry currently has focus def register_shortcut(key, func, allow_filter_focus = False): shortcut_map[key] = (func, allow_filter_focus) def key_pressed(widget, event): from ocarina import body from ocarina.body.header import entry name = keyval_name(event.keyval) func, allow_filter_focus = shortcut_map.get(name, (null_shortcut, False)) if (entry.has_focus() and not allow_filter_focus): return if func() == False: return False widget.emit_stop_by_name("key-press-event") return True register_shortcut("space", controls.toggle_play) register_shortcut( "Left", controls.seek_backward) register_shortcut("Right", controls.seek_forward) register_shortcut( "n", controls.next) register_shortcut( "s", controls.stop)