Пример #1
0
    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)
Пример #2
0
 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
Пример #3
0
    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
Пример #4
0
 def add(self, name, widget):
     VerticalContainer.add(self, widget)
     self.items.append((name, widget))
     if self.listItemViewedIndex is None:
         self.listItemViewedIndex = 0
Пример #5
0
 def setActive(self, widget=None):
     VerticalContainer.setActive(self, self)
Пример #6
0
    def update(self, *args):
        VerticalContainer.update(self, *args)

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