Esempio n. 1
0
    def __init__(self, title, choices, callback, explanation=None, width=400):
        super(ChoiceLayer, self).__init__()
        self.callback = callback
        self.add(ColorLayer(20, 20, 20, 150), z=-2)
        w, h = director.get_window_size()

        y = h - 256
        but = Label(title,
                    color=(0, 0, 0, 255),
                    position=(w // 2, y),
                    anchor_x='center',
                    anchor_y='top',
                    font_size=24)
        x1 = w // 2 - but.element.content_width // 2
        x2 = w // 2 + but.element.content_width // 2
        y2 = y
        self.add(but)
        y -= but.element.content_height + 10

        if explanation:
            but = Label(explanation,
                        multiline=True,
                        color=(0, 0, 0, 255),
                        position=(w // 2, y),
                        width=width,
                        anchor_x='center',
                        anchor_y='top',
                        font_size=14,
                        align='center',
                        font_name='Prototype')
            self.add(but)
            x1 = min(w // 2 - width // 2, x1)
            x2 = max(w // 2 + width // 2, x2)
            y -= but.element.content_height + 10

        y -= 32

        self.choice_buts = []
        for choice in choices:
            but = Label(choice,
                        color=(0, 0, 0, 255),
                        position=(w // 2, y),
                        anchor_x='center',
                        anchor_y='bottom',
                        font_size=20,
                        font_name='Prototype')
            self.add(but, z=1)
            self.choice_buts.append(but)
            x = w // 2 - but.element.content_width // 2
            x1 = min(x, x1)
            x2 = max(w // 2 + but.element.content_width // 2, x2)
            but.rect = Rect(x, y, but.element.content_width,
                            but.element.content_height)
            y1 = y
            y -= but.element.content_height

        self.patch_dimensions = (x1, y1, x2 - x1, y2 - y1)

        self.ninepatch = NinePatch(pyglet.resource.image('border-9p.png'))
Esempio n. 2
0
    def __init__(self, title, choices, callback, explanation=None, width=400):
        super(ChoiceLayer, self).__init__()
        self.callback = callback
        self.add(ColorLayer(20, 20, 20, 150), z=-2)
        w, h = director.get_window_size()

        y = h - 256
        but = Label(title, color=(0, 0, 0, 255), position=(w//2, y),
            anchor_x='center', anchor_y='top', font_size=24)
        x1 = w//2 - but.element.content_width // 2
        x2 = w//2 + but.element.content_width // 2
        y2 = y
        self.add(but)
        y -= but.element.content_height + 10

        if explanation:
            but = Label(explanation, multiline=True, color=(0, 0, 0, 255),
                position=(w//2, y), width=width, anchor_x='center',
                anchor_y='top', font_size=14, align='center',
                font_name='Prototype')
            self.add(but)
            x1 = min(w//2 - width // 2, x1)
            x2 = max(w//2 + width // 2, x2)
            y -= but.element.content_height + 10

        y -= 32

        self.choice_buts = []
        for choice in choices:
            but = Label(choice, color=(0, 0, 0, 255), position=(w//2, y),
                anchor_x='center',  anchor_y='bottom', font_size=20,
                font_name='Prototype')
            self.add(but, z=1)
            self.choice_buts.append(but)
            x = w//2 - but.element.content_width // 2
            x1 = min(x, x1)
            x2 = max(w//2 + but.element.content_width // 2, x2)
            but.rect = Rect(x, y, but.element.content_width,
                but.element.content_height)
            y1 = y
            y -= but.element.content_height

        self.patch_dimensions = (x1, y1, x2-x1, y2-y1)

        self.ninepatch = NinePatch(pyglet.resource.image('border-9p.png'))
Esempio n. 3
0
 def add_button():
     y = 758
     x = 10
     while 1:
         indent, but, label = yield
         y -= but.image.height
         but.position = (x + indent, y)
         if isinstance(but.info, str):
             name = but.info
         else:
             name = but.info.name
         self.add(but, z=1, name=name)
         lx = x + indent + but.image.width + 10
         ly = y + 12
         if '\n' in label:
             ly += 12
         if label.count('\n') > 1:
             y -= 24 * (label.count('\n') - 1)
         l = Label(label, multiline=True, width=400, position=(lx, ly),
             color=(255,255,255,255), font_name='Prototype')
         l.rect = Rect(l.x, l.y, l.element.content_width,
                       l.element.content_height)
         self.add(l)
         but.label_ob = l