Пример #1
0
def add_keys(node, sup, handlers):
	if sup == -1:
		node.keys = node.__bases__[-1].keys.copy()
	elif sup == None:
		node.keys = odict()
	else:
		node.keys = sup.keys.copy()



	for k, v in iteritems(handlers):
		if type(k.key) == tuple:
			for key in k.key:
				node.keys[K(k.mods, key)] = v
		else:
			node.keys[k] = v
Пример #2
0
def potential_handlers(trip):
	"""return every handler for the elements in trip and parents, whose checker passess.
	mods and key are irrelevant, we arent dealing with any particular event
	"""
	output = odict()

	elems = [x.get(Att.elem) for x in [trip.middle or {}, trip.left or {}, trip.right or {}]]

	while any(elems):
		for elem, sidedness, atts in [
								(elems[0], None, trip.middle),
		                        (elems[1], LEFT, trip.left),
								(elems[2], RIGHT, trip.right)]:
			if elem:
				for keys, handler in iteritems(elem.keys):
					if handler.sidedness in (None, sidedness):
						if not handler.checker or handler.checker(elem, atts):
							if keys not in output:
								yield keys, (elem, handler)
								output[keys] = True
		for i in range(3):
			if elems[i]:
				elems[i] =  elems[i].parent
Пример #3
0
def setup(client):
	global c
	c = client
	global_keys[frozenset()] = odict([
		(K_F1, c.cycle_sidebar),
		(K_F2, replay.do_replay),
		#K_F8: c.editor.toggle_arrows,
		(K_UP, (lambda e:(
		(c.editor.move_cursor_v(-1),
				c.editor.and_sides(e))), HIDDEN, PASS_E)),
		(K_DOWN,(lambda e:(
		(c.editor.move_cursor_v(+1),
			c.editor.and_sides(e))), HIDDEN, PASS_E)),
		(K_LEFT,(lambda e:(
		(c.editor.move_cursor_h(-1),
			c.editor.and_updown(e))), HIDDEN, PASS_E)),
		(K_RIGHT,(lambda e:(
		(c.editor.move_cursor_h(+1),
			c.editor.and_updown(e))), HIDDEN, PASS_E)),
		(K_HOME,
			(c.editor.cursor_home, HIDDEN)),
		(K_END,
			(c.editor.cursor_end, HIDDEN)),
		(K_PAGEUP,
			(lambda:c.editor.move_cursor_v(-10), HIDDEN)),
		(K_PAGEDOWN,
			(lambda:c.editor.move_cursor_v(10), HIDDEN)),
		(K_ESCAPE,
			die),
		(K_SPACE,
			(s.menu.accept, None, CHECK))
	])

	global_keys[frozenset([KMOD_CTRL])] = odict([
		('=',
			(lambda:change_font_size(1),'inc font size')),
		('-',
			(lambda:change_font_size(-1),'dec font size')),
		(K_LEFT,
			c.editor.prev_elem),
		(K_RIGHT,
			c.editor.next_elem),
		(K_HOME,
			c.editor.cursor_top),
		(K_END,
			c.editor.cursor_bottom),
		(K_f,
			c.editor.dump_to_file),
		#(K_q,
		#	s.bye),
		(K_m,
			s.menu.menu_dump)])

	if SDL:
		global_keys[frozenset([KMOD_CTRL])].update(odict([
			(K_UP,
			 (lambda:c.sidebar.move(-1), "menu up")),
			(K_DOWN,
			 (lambda:c.sidebar.move(1), "menu down"))]))

	s.node_info.global_keys = (["global keys:"]+
		list(handler_str([])) +
		["ctrl "+x for x in handler_str([KMOD_CTRL])])