Exemple #1
0
    def __init__(self, pos, text, font, width, center=0):
        self.lines = []

        words = text.split(' ')
        start = 0
        stop = 0

        height = font.get_height()

        while start < len(words):
            while (get_item_width(' '.join(words[start:stop]), font) < width
                   and stop < len(words) + 1):
                stop += 1

            l = ' '.join(words[start:stop - 1])

            self.lines.append\
                (TextLine((pos[0], pos[1] + len(self.lines) * (height + 1)),
                          l,
                          font,
                          Borders(),
                          width,
                          center))

            start = stop - 1

        Widget.__init__(self, pos, (width, len(self.lines) * (height + 1)))
Exemple #2
0
    def __init__(self, pos, text, font, width, center = 0):
        self.lines = []

        words = text.split(' ')
        start = 0
        stop  = 0

        height = font.get_height()

        while start < len(words):
            while (get_item_width(' '.join(words[start:stop]), font) < 
                   width and stop < len(words) + 1):
                stop += 1

            l = ' '.join(words[start:stop - 1])

            self.lines.append\
                (TextLine((pos[0], pos[1] + len(self.lines) * (height + 1)), 
                          l, 
                          font, 
                          Borders(), 
                          width,
                          center))

            start = stop - 1

        Widget.__init__(self, pos, (width, len(self.lines) * (height + 1)))
Exemple #3
0
    def __init__(self, pos, title, items, font, width=-1):
        width = max(width, get_item_width(title, font))
        for item in items:
            width = max(width, get_item_width(item, font))

        closed_title_borders = Borders(1, 1, 1, 1)
        self.title_line = TextLine(pos, title, font, closed_title_borders,
                                   width)

        open_title_borders = Borders(1, 0, 1, 1)
        self.item_lines = [
            TextLine(pos, title, font, open_title_borders, width)
        ]

        item_borders = Borders(0, 0, 1, 1)
        last_item_borders = Borders(0, 1, 1, 1)

        for i in range(len(items)):
            if i + 1 == len(items):
                self.item_lines.append\
                    (TextLine((pos[0],
                               pos[1] + (i + 1) * self.title_line.dim[1]),
                              items[i],
                              font,
                              last_item_borders,
                              width))
            else:
                self.item_lines.append\
                    (TextLine((pos[0],
                               pos[1] + (i + 1) * self.title_line.dim[1]),
                              items[i],
                              font,
                              item_borders,
                              width))

        Widget.__init__(self, pos, (width, self.title_line.dim[1]))

        self.is_open = 1
        self.close()
Exemple #4
0
    def __init__(self, pos, title, items, font, width = -1):
        width = max(width, get_item_width(title, font))
        for item in items:
            width = max(width, get_item_width(item, font))

        closed_title_borders = Borders(1, 1, 1, 1)
        self.title_line = TextLine(pos, title, font, 
                                   closed_title_borders, width)
        
        open_title_borders = Borders(1, 0, 1, 1)
        self.item_lines = [TextLine(pos, title, font, 
                                    open_title_borders, width)]

        item_borders = Borders(0, 0, 1, 1)
        last_item_borders = Borders(0, 1, 1, 1)

        for i in range(len(items)):
            if i + 1 == len(items):
                self.item_lines.append\
                    (TextLine((pos[0], 
                               pos[1] + (i + 1) * self.title_line.dim[1]),
                              items[i],
                              font,
                              last_item_borders,
                              width))
            else:
                self.item_lines.append\
                    (TextLine((pos[0], 
                               pos[1] + (i + 1) * self.title_line.dim[1]),
                              items[i],
                              font,
                              item_borders,
                              width))

        Widget.__init__(self, pos, (width, self.title_line.dim[1]))

        self.is_open = 1
        self.close()
Exemple #5
0
def get_radio_button_width(text, font):
    return font.get_height() + get_item_width(text, font) + 2 * PAD
Exemple #6
0
    def __init__(self, pos, text, font, width=-1):
        text_line = TextLine(pos, text, font, Borders(),
                             get_item_width(text, font) + BUTTON_PADDING, 1)

        width = max(width, text_line.dim[0])

        Widget.__init__(
            self, pos,
            (width + BUTTON_MARGINALS, text_line.dim[1] + BUTTON_MARGINALS))

        x_pos = BUTTON_MARGINALS / 2 + (width - text_line.dim[0]) / 2

        self.focused_surface = pygame.Surface(self.dim)
        self.focused_surface.fill(FOCUSED_COLOR)
        self.focused_surface.blit(text_line.focused_surface,
                                  (x_pos, BUTTON_MARGINALS / 2))

        self.unfocused_surface = pygame.Surface(self.dim)
        self.unfocused_surface.fill(BG_COLOR)
        self.unfocused_surface.blit(text_line.unfocused_surface,
                                    (x_pos, BUTTON_MARGINALS / 2))

        pygame.draw.line(self.focused_surface, BORDER_COLOR,
                         (0, BUTTON_MARGINALS / 4),
                         (width + BUTTON_MARGINALS, BUTTON_MARGINALS / 4),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface, BORDER_COLOR,
                         (0, BUTTON_MARGINALS / 4),
                         (width + BUTTON_MARGINALS, BUTTON_MARGINALS / 4),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(
            self.focused_surface, BORDER_COLOR,
            (0, self.dim[1] - BUTTON_MARGINALS / 4 - 1),
            (width + BUTTON_MARGINALS, self.dim[1] - BUTTON_MARGINALS / 4 - 1),
            BUTTON_MARGINALS / 2)

        pygame.draw.line(
            self.unfocused_surface, BORDER_COLOR,
            (0, self.dim[1] - BUTTON_MARGINALS / 4 - 1),
            (width + BUTTON_MARGINALS, self.dim[1] - BUTTON_MARGINALS / 4 - 1),
            BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface, BORDER_COLOR,
                         (BUTTON_MARGINALS / 4, 0),
                         (BUTTON_MARGINALS / 4, self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.focused_surface, BORDER_COLOR,
                         (BUTTON_MARGINALS / 4, 0),
                         (BUTTON_MARGINALS / 4, self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface, BORDER_COLOR,
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, 0),
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.focused_surface, BORDER_COLOR,
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, 0),
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, self.dim[1]),
                         BUTTON_MARGINALS / 2)

        self.surface = self.unfocused_surface

        # FIXME
        self.event = text
Exemple #7
0
    def __init__(self, pos, text, font, width = -1):
        text_line = TextLine(pos, text, font, Borders(),
                             get_item_width(text, font) + BUTTON_PADDING, 1)

        width = max(width, text_line.dim[0])

        Widget.__init__(self, pos, (width + BUTTON_MARGINALS,
                                    text_line.dim[1] + BUTTON_MARGINALS))

        x_pos = BUTTON_MARGINALS / 2 + (width - text_line.dim[0]) / 2

        self.focused_surface = pygame.Surface(self.dim)
        self.focused_surface.fill(FOCUSED_COLOR)
        self.focused_surface.blit(text_line.focused_surface,
                                  (x_pos,
                                   BUTTON_MARGINALS / 2))
        
        self.unfocused_surface = pygame.Surface(self.dim)
        self.unfocused_surface.fill(BG_COLOR)
        self.unfocused_surface.blit(text_line.unfocused_surface,
                                    (x_pos,
                                     BUTTON_MARGINALS / 2))

        pygame.draw.line(self.focused_surface,BORDER_COLOR,
                         (0, BUTTON_MARGINALS / 4), 
                         (width + BUTTON_MARGINALS, BUTTON_MARGINALS / 4),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface,BORDER_COLOR,
                         (0, BUTTON_MARGINALS / 4), 
                         (width + BUTTON_MARGINALS, BUTTON_MARGINALS / 4),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.focused_surface,BORDER_COLOR,
                         (0, self.dim[1] - BUTTON_MARGINALS / 4 - 1), 
                         (width + BUTTON_MARGINALS, 
                          self.dim[1] - BUTTON_MARGINALS / 4 - 1),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface,BORDER_COLOR,
                         (0, self.dim[1] - BUTTON_MARGINALS / 4 - 1), 
                         (width + BUTTON_MARGINALS, 
                          self.dim[1] - BUTTON_MARGINALS / 4 - 1),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface,BORDER_COLOR,
                         (BUTTON_MARGINALS / 4 , 0), 
                         (BUTTON_MARGINALS / 4, 
                          self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.focused_surface,BORDER_COLOR,
                         (BUTTON_MARGINALS / 4, 0), 
                         (BUTTON_MARGINALS / 4, 
                          self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.unfocused_surface,BORDER_COLOR,
                         (self.dim[0] - BUTTON_MARGINALS / 4-1 , 0), 
                         (self.dim[0] - BUTTON_MARGINALS / 4-1, 
                          self.dim[1]),
                         BUTTON_MARGINALS / 2)

        pygame.draw.line(self.focused_surface,BORDER_COLOR,
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, 0), 
                         (self.dim[0] - BUTTON_MARGINALS / 4 - 1, 
                          self.dim[1]),
                         BUTTON_MARGINALS / 2)

        self.surface = self.unfocused_surface
 
        # FIXME
        self.event = text
Exemple #8
0
def get_radio_button_width(text, font):
    return font.get_height() + get_item_width(text, font) + 2 * PAD