1 import pygame.locals as pgl
3 from naja.constants import KEYS
4 from naja.widgets.base import Container
5 from naja.resources import resources
6 from naja.resources.mutators import EIGHT_BIT, R270
9 class SelectorWidget(Container):
10 def __init__(self, *args, **kwargs):
11 super(SelectorWidget, self).__init__(*args, **kwargs)
13 self.selector = resources.get_image('bits', 'arrow_on.png',
14 transforms=(R270, EIGHT_BIT))
16 def render(self, surface):
17 super(SelectorWidget, self).render(surface)
18 pos = self.selector.get_rect()
19 selected = self.widgets[self.position]
20 pos = pos.move(selected.pos)
21 pos = pos.move(-pos.width * 1.5, (selected.size[1] - pos.height) / 2)
22 surface.blit(self.selector, pos)
24 def handle_event(self, ev):
25 if ev.type == pgl.KEYDOWN:
26 if ev.key in KEYS.UP + KEYS.DOWN:
27 if ev.key in KEYS.DOWN:
31 self.position %= len(self.widgets)
33 elif ev.key in KEYS.SELECT:
34 return self.widgets[self.position].callback('click')
36 return super(SelectorWidget, self).handle_event(ev)