Exemplo n.º 1
0
Arquivo: list.py Projeto: saebyn/nwgui
    def handleEvent(self, event):
        VerticalContainer.handleEvent(self, event)

        # find clicks on children, do select
        if event.type == MOUSEBUTTONDOWN:
            position = pygame.mouse.get_pos()
            for index in xrange(0, len(self.items)):
                if self.items[index][1].rect.collidepoint(position):
                    self.select(index)
                    return

            self.unselect()
        # handle keys up and down, do scroll/select
        elif event.type == KEYDOWN:
            if event.key == K_UP:
                try:
                    index = self.selectedItem - 1
                except ValueError:
                    return

                if index >= 0:
                    self.scrollUp()
                    self.select(index)
            elif event.key == K_DOWN:
                try:
                    index = self.selectedItem + 1
                except ValueError:
                    return

                if index < len(self.items):
                    self.scrollDown()
                    self.select(index)
Exemplo n.º 2
0
Arquivo: list.py Projeto: saebyn/nwgui
 def __init__(self, *args, **kwargs):
     kwargs['padding'] = (5, 5)
     kwargs['border'] = (1, (0, 0, 0))
     VerticalContainer.__init__(self, *args, **kwargs)
     self.items = []
     # This is the index of the item at the top of the
     # displayed list of items. It is None if there are no items.
     self.listItemViewedIndex = None
     self.selectedItem = None
     self._dirty = True
     self.callback = None
Exemplo n.º 3
0
Arquivo: list.py Projeto: saebyn/nwgui
    def remove(self, name):
        widget = self._find(name)

        VerticalContainer.remove(self, widget)

        self.items.remove((name, widget))

        if self.listItemViewedIndex >= len(self.items):
            self.listItemViewedIndex = len(self.items) - 1

        if self.listItemViewedIndex == -1:
            self.listItemViewedIndex = None
Exemplo n.º 4
0
Arquivo: list.py Projeto: saebyn/nwgui
 def add(self, name, widget):
     VerticalContainer.add(self, widget)
     self.items.append((name, widget))
     if self.listItemViewedIndex is None:
         self.listItemViewedIndex = 0
Exemplo n.º 5
0
Arquivo: list.py Projeto: saebyn/nwgui
 def setActive(self, widget=None):
     VerticalContainer.setActive(self, self)
Exemplo n.º 6
0
Arquivo: list.py Projeto: saebyn/nwgui
    def update(self, *args):
        VerticalContainer.update(self, *args)

        if self._dirty:
            self._refreshVisibleItems()
            self._dirty = False