Exemple #1
0
    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().__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')

        # TODO: 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 #2
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()
Exemple #3
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().__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()
Exemple #4
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
Exemple #6
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()
Exemple #7
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()
class ComboBox(SelectionCommon):
    name = 'combo-box'
    is_focusable = True

    is_vertical = True

    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

    def resize(self):
        while self.contents.width is None or self.contents.height is None:
            self.contents.resize()
        # fix label width so it fits largest selection
        self.label.width = self.contents.width
        if not super(ComboBox, self).resize(): return False
        self.contents.y = -(self.contents.height - self.height)
        self.contents.x = 0
        return True

    @classmethod
    def get_arrow(cls):
        if not hasattr(cls, 'image_object'):
            cls.image_object = data.load_gui_image('slider-arrow-down.png')
        return cls.image_object

    def _get_arrow(self):
        return self.get_arrow()

    arrow = property(_get_arrow)

    def get_value(self):
        return self._value

    def set_value(self, value):
        for item in self.contents.children:
            if item.id == value: break
        else:
            raise ValueError, '%r not a valid child item id' % (value, )
        self.label.text = item.text
        self._value = value

    value = property(get_value, set_value)

    def addOption(self, label, id=None, **kw):
        Option(self.contents, text=label, id=id or label, **kw)

    @event.default('combo-box')
    def on_click(widget, x, y, button, modifiers, click_count):
        if not button & mouse.LEFT:
            return event.EVENT_UNHANDLED
        # XXX position contents so the active item is over the label
        label = widget.label
        contents = widget.contents
        if contents.is_visible:
            label.setVisible(True)
            contents.setVisible(False)
            contents.loseFocus()
        else:
            label.setVisible(False)
            contents.setVisible(True)
            contents.gainFocus()
            # reposition the selection drop down
            contents.y = -(contents.height - widget.height)
            contents.x = 0
        return event.EVENT_HANDLED

    @event.default('combo-box', 'on_gain_focus')
    def on_gain_focus(widget, source):
        if source == 'mouse':
            # don't focus on mouse clicks
            return event.EVENT_UNHANDLED
        # catch focus
        return event.EVENT_HANDLED

    @event.default('combo-box', 'on_lose_focus')
    def on_lose_focus(widget):
        widget.contents.setVisible(False)
        return event.EVENT_HANDLED

    @event.default('combo-box')
    def on_text_motion(widget, motion):
        options = widget.contents.children
        for i, option in enumerate(options):
            if option.id == widget.value:
                break
        if motion == key.MOTION_DOWN and i + 1 != len(options):
            widget.value = options[i + 1].id
        elif motion == key.MOTION_UP and i - 1 != -1:
            widget.value = options[i - 1].id

        return event.EVENT_HANDLED
Exemple #9
0
class ComboBox(SelectionCommon):
    name = 'combo-box'
    is_focusable = True

    is_vertical = True

    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().__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')

        # TODO: 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

    def resize(self):
        while self.contents.width is None or self.contents.height is None:
            self.contents.resize()
        # fix label width so it fits largest selection
        self.label.width = self.contents.width
        if not super().resize():
            return False
        self.contents.y = -(self.contents.height - self.height)
        self.contents.x = 0
        return True

    @classmethod
    def get_arrow(cls):
        if not hasattr(cls, 'image_object'):
            cls.image_object = data.load_gui_image('slider-arrow-down.png')
        return cls.image_object

    def _get_arrow(self):
        return self.get_arrow()

    arrow = property(_get_arrow)

    def get_value(self):
        return self._value

    def set_value(self, value):
        for item in self.contents.children:
            if item.id == value:
                break
        else:
            raise ValueError('%r not a valid child item id' % (value,))
        self.label.text = item.text
        self._value = value

    value = property(get_value, set_value)

    def addOption(self, label, id=None, **kw):
        Option(self.contents, text=label, id=id or label, **kw)

    @event.default('combo-box')
    def on_click(widget, x, y, button, modifiers, click_count):
        if not button & mouse.LEFT:
            return event.EVENT_UNHANDLED
        # TODO: position contents so the active item is over the label
        label = widget.label
        contents = widget.contents
        if contents.is_visible:
            label.setVisible(True)
            contents.setVisible(False)
            contents.loseFocus()
        else:
            label.setVisible(False)
            contents.setVisible(True)
            contents.gainFocus()
            # reposition the selection drop down
            contents.y = -(contents.height - widget.height)
            contents.x = 0
        return event.EVENT_HANDLED

    @event.default('combo-box', 'on_gain_focus')
    def on_gain_focus(widget, source):
        if source == 'mouse':
            # don't focus on mouse clicks
            return event.EVENT_UNHANDLED
        # catch focus
        return event.EVENT_HANDLED

    @event.default('combo-box', 'on_lose_focus')
    def on_lose_focus(widget):
        widget.contents.setVisible(False)
        return event.EVENT_HANDLED

    @event.default('combo-box')
    def on_text_motion(widget, motion):
        options = widget.contents.children
        for i, option in enumerate(options):
            if option.id == widget.value:
                break
        if motion == key.MOTION_DOWN and i + 1 != len(options):
            widget.value = options[i + 1].id
        elif motion == key.MOTION_UP and i - 1 != -1:
            widget.value = options[i - 1].id

        return event.EVENT_HANDLED