Exemple #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)
Exemple #2
0
 def __init__(self, parent, width='100%', bgcolor='aaa', **kw):
     kw['y'] = parent.height - parent.getStyle().font_size
     super(Heading, self).__init__(parent, width=width, **kw)
     self.layout = layouts.Horizontal(self,
                                      valign='top',
                                      halign='fill',
                                      padding=2)
Exemple #3
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)
Exemple #4
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
Exemple #5
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
Exemple #7
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)
Exemple #8
0
    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
Exemple #9
0
    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()