Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def addElement(self, label, element, **kw):
        from wydget.widgets.frame import Frame

        row = Frame(self.parent, is_transparent=True)
        if label:
            element._label = Label(row, label, **kw)
        else:
            element._label = None
            Frame(row, is_transparent=True, width=0, height=0)

        # move the element to the row
        element.parent.children.remove(element)
        row.children.append(element)
        element.parent = row
    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
Ejemplo n.º 4
0
    def __init__(self, parent, text=None, image=None, border="black",
                 padding=1, halign="left", valign="bottom", font_size=None,
                 **kw):
        super().__init__(parent, border=border,
                         padding=padding, **kw)

        if text is None and image is None:
            raise ValueError('text or image required')

        if image is not None:
            Image(self, image)
        if text is not None:
            Label(self, text, font_size=font_size)
        self.layout = layouts.Horizontal(self, padding=2, halign=halign,
                                         valign=valign)
Ejemplo n.º 5
0
Archivo: movie.py Proyecto: pyzh/pyglet
    def __init__(self,
                 parent,
                 file=None,
                 source=None,
                 playing=False,
                 x=0,
                 y=0,
                 z=0,
                 width=None,
                 height=None,
                 scale=True,
                 **kw):
        self.parent = parent
        self.scale = scale

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

        self.player = media.Player()
        self.player.eos_action = self.player.EOS_PAUSE
        self.player.on_eos = self.on_eos

        # poke at the video format
        if not source.video_format:
            raise ValueError("Movie file doesn't contain video")
        video_format = source.video_format
        if width is None:
            width = video_format.width
            if video_format.sample_aspect > 1:
                width *= video_format.sample_aspect
        if height is None:
            height = video_format.height
            if video_format.sample_aspect < 1:
                height /= video_format.sample_aspect

        super().__init__(parent, x, y, z, width, height, **kw)

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

        # controls underlay
        f = Frame(c, 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'))
        im = data.load_gui_image('media-position.png')
        c.position = Image(fi, im, x=0, 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()