Esempio n. 1
0
    def __init__(self,
                 parent,
                 text,
                 callback=None,
                 cancel=True,
                 font_size=None,
                 padding=10,
                 **kw):
        super().__init__(parent, padding=padding, **kw)
        self.callback = callback

        self.layout = layouts.Vertical(self, padding=10)

        widgets.Label(self, text, font_size=font_size)

        buttons = widgets.Frame(self, width='100%')
        buttons.layout = layouts.Horizontal(buttons,
                                            padding=10,
                                            halign='center')
        self.ok = widgets.TextButton(buttons,
                                     'Ok',
                                     border='black',
                                     padding=2,
                                     classes=('-question-dialog-ok', ),
                                     font_size=font_size)
        if cancel:
            widgets.TextButton(buttons,
                               'Cancel',
                               border='black',
                               classes=('-question-dialog-cancel', ),
                               padding=2,
                               font_size=font_size)
Esempio n. 2
0
    def __init__(self,
                 parent,
                 items=list(),
                 size=None,
                 is_exclusive=False,
                 color='black',
                 bgcolor='white',
                 is_vertical=True,
                 alt_bgcolor='eee',
                 active_bgcolor='ffc',
                 item_pad=0,
                 is_transparent=True,
                 scrollable=True,
                 font_size=None,
                 **kw):
        self.is_vertical = is_vertical
        self.is_exclusive = is_exclusive

        if font_size is None:
            font_size = parent.getStyle().font_size
        else:
            font_size = util.parse_value(font_size, None)

        size = util.parse_value(size, None)

        if is_vertical:
            if size is not None:
                kw['height'] = size * font_size
        else:
            if size is not None:
                kw['width'] = size * font_size

        super().__init__(parent,
                         bgcolor=bgcolor,
                         scrollable=scrollable,
                         scrollable_resize=scrollable,
                         is_transparent=is_transparent,
                         **kw)
        if scrollable:
            f = self.contents
        else:
            f = self
        if is_vertical:
            f.layout = layouts.Vertical(f, padding=item_pad)
        else:
            f.layout = layouts.Horizontal(f, padding=item_pad)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        for label, id, kw in items:
            self.addOption(label, id, **kw)
Esempio n. 3
0
    def __init__(self, parent, is_transparent=True, halign='left', **kw):
        super().__init__(parent,
                         is_transparent=is_transparent, **kw)

        self.halign = halign

        self.top = Frame(self, is_transparent=True)
        self.top.layout = layouts.Horizontal(self.top, halign=self.halign,
                                             padding=2)
        self.bottom = Frame(self, is_transparent=True)
        self.bottom.layout = TabsLayout(self.bottom)
        self.layout = layouts.Vertical(self, valign='bottom', padding=0)
        self._active_frame = None
Esempio n. 4
0
    def __init__(self, parent, file=None, source=None, title=None,
            playing=False, bgcolor=(1, 1, 1, 1), color=(0, 0, 0, 1),
            font_size=20, **kw):
        '''Pass in a filename as "file" or a pyglet Source as "source".
        '''
        self.parent = parent

        if file is not None:
            source = media.load(file, streaming=True)
        else:
            assert source is not None, 'one of file or source is required'

        self.player = media.Player()

        # poke at the audio format
        if not source.audio_format:
            raise ValueError("File doesn't contain audio")

        super(Music, self).__init__(parent, bgcolor=bgcolor, **kw)

        # lay it out

        # control frame top-level
        c = self.control = Frame(self, width='100%', height=64)

        ft = Frame(c, is_transparent=True, width='100%', height='100%')
        ft.layout = layouts.Vertical(ft)
        Label(ft, title or 'unknown', color=color, bgcolor=bgcolor,
            padding=2, font_size=font_size)

        # controls underlay
        f = Frame(ft, is_transparent=True, width='100%', height='100%')
        f.layout = layouts.Horizontal(f, valign='center', halign='center',
            padding=10)
        c.play = Image(f, data.load_gui_image('media-play.png'),
            classes=('-play-button',), is_visible=not playing)
        c.pause = Image(f, data.load_gui_image('media-pause.png'),
            bgcolor=None, classes=('-pause-button',), is_visible=playing)
        fi = Frame(f, is_transparent=True)
        c.range = Image(fi, data.load_gui_image('media-range.png'))
        c.position = Image(fi, data.load_gui_image('media-position.png'),
            y=-2, classes=('-position',))
        c.time = Label(f, '00:00', font_size=20)
        c.anim = None

        # make sure we get at least one frame to display
        self.player.queue(source)
        clock.schedule(self.update)
        self.playing = False
        if playing:
            self.play()
    def __init__(self,
                 parent,
                 items,
                 font_size=None,
                 border="black",
                 color='black',
                 bgcolor='white',
                 alt_bgcolor='eee',
                 active_bgcolor='ffc',
                 item_pad=0,
                 **kw):
        super(ComboBox, self).__init__(parent, **kw)

        # specific attributes for Options
        self.color = util.parse_color(color)
        self.base_bgcolor = self.bgcolor
        self.alt_bgcolor = util.parse_color(alt_bgcolor)
        self.active_bgcolor = util.parse_color(active_bgcolor)
        self.font_size = font_size

        lf = Frame(self)
        lf.layout = layouts.Horizontal(lf, halign='left', valign='top')

        # XXX add a an editable flag, and use a TextInput if it's true
        self.label = Label(lf,
                           items[0][0],
                           font_size=font_size,
                           color=color,
                           bgcolor=bgcolor,
                           border=border)
        Image(lf,
              self.arrow,
              color=(0, 0, 0, 1),
              bgcolor=bgcolor,
              border=border)

        # set up the popup item - try to make it appear in front
        self.contents = Frame(self,
                              is_visible=False,
                              bgcolor=bgcolor,
                              border=border,
                              z=.5)
        self.contents.layout = layouts.Vertical(self.contents)
        self.layout.ignore = set([self.contents])

        # add the options
        for label, id, kw in items:
            Option(self.contents, text=label, id=id, **kw)

        self.value = self.contents.children[0].id
Esempio n. 6
0
    def __init__(self, parent, items, **kw):
        super(PopupMenu, self).__init__(parent,
                                        border="black",
                                        is_visible=False,
                                        **kw)

        for n, (label, id) in enumerate(items):
            MenuItem(self,
                     text=label,
                     id=id,
                     width='100%',
                     bgcolor=((.95, .95, .95, 1), (1, 1, 1, 1))[n % 2])

        self.layout = layouts.Vertical(self)
Esempio n. 7
0
File: file.py Progetto: pyzh/pyglet
    def __init__(self, parent, path=default_dir, callback=None, **kw):
        kw['border'] = 'black'
        kw['bgcolor'] = 'white'
        kw['padding'] = 2
        kw['width'] = 300
        super().__init__(parent, **kw)
        self.callback = callback

        self.layout = layouts.Vertical(self, halign='left', padding=2)

        label = widgets.Label(self,
                              'Select File to Open',
                              classes=('title', ),
                              bgcolor="aaa",
                              padding=2,
                              width="100%",
                              halign="center")

        self.path = widgets.TextInput(self,
                                      width="100%",
                                      classes=('-file-open-path', ))

        self.listing = widgets.Selection(self,
                                         scrollable=True,
                                         width="100%",
                                         is_exclusive=True,
                                         size=20,
                                         classes=('-file-open-dialog', ))

        self.openPath(os.path.abspath(path))

        f = widgets.Frame(self, width=296, is_transparent=True)
        ok = widgets.TextButton(f,
                                text='Ok',
                                border="black",
                                classes=('-file-open-dialog-ok', ))
        cancel = widgets.TextButton(f,
                                    text='Cancel',
                                    border="black",
                                    classes=('-file-open-dialog-cancel', ))
        f.layout = layouts.Horizontal(f, padding=10, halign='right')

        self.selected_file = None
        self.selected_widget = None