Exemple #1
0
 def __init__(self, **kwargs):
     kwargs.setdefault('min', 0)
     kwargs.setdefault('max', 255)
     kwargs.setdefault('values', [77, 77, 77])
     kwargs.setdefault('targets', [])
     self.dl = GlDisplayList()
     super(MTColorPicker, self).__init__(**kwargs)
     self.size = (130, 290)
     self.targets = kwargs.get('targets')
     self.sliders = [
         MTSlider(min=kwargs.get('min'),
                  max=kwargs.get('max'),
                  size=(30, 200),
                  style={'slider-color': (1, 0, 0, 1)},
                  cls='colorpicker-slider'),
         MTSlider(min=kwargs.get('min'),
                  max=kwargs.get('max'),
                  size=(30, 200),
                  style={'slider-color': (0, 1, 0, 1)},
                  cls='colorpicker-slider'),
         MTSlider(min=kwargs.get('min'),
                  max=kwargs.get('max'),
                  size=(30, 200),
                  style={'slider-color': (0, 0, 1, 1)},
                  cls='colorpicker-slider')
     ]
     vbox = MTBoxLayout(spacing=10, padding=10)
     for slider in self.sliders:
         slider.value = 77
         slider.push_handlers(on_value_change=self.update_color)
         vbox.add_widget(slider)
     self.add_widget(vbox)
     self.update_color()
     self.touch_positions = {}
Exemple #2
0
    def __init__(self, **kwargs):
        kwargs.setdefault('bordersize', 10)

        super(MTVideo, self).__init__(**kwargs)

        self._count = 0
        self._controls = False
        self.bordersize = kwargs.get('bordersize')

        # images play/pause/mute
        self.f_play = Image(pymt_icons_dir + 'video-play.png')
        self.f_pause = Image(pymt_icons_dir + 'video-pause.png')
        self.f_vmute = Image(pymt_icons_dir + 'video-volume-mute.png')
        self.f_v100 = Image(pymt_icons_dir + 'video-volume-100.png')

        # create UI
        box = MTBoxLayout(orientation='horizontal', uniform_height=True,
                          spacing=0, padding=0)
        self._btnplay = MTButtonVideo(image=self.f_play,
                                      cls='video-toggleplay')
        self._btnmute = MTButtonVideo(image=self.f_v100,
                                      cls='video-togglemute')
        self._timeline = MTSlider(orientation='horizontal',
                                  cls='video-timeline')

        box.add_widget(self._btnplay)
        box.add_widget(self._btnmute)
        box.add_widget(self._timeline)
        self.add_widget(box)

        # link
        self._btnplay.connect('on_press', self._on_toggle_play)
        self._btnmute.connect('on_press', self._on_toggle_mute)

        self.hide_controls()
Exemple #3
0
 def __init__(self, **kwargs):
     kwargs.setdefault('min', 0)
     kwargs.setdefault('max', 255)
     kwargs.setdefault('values', [77, 77, 77])
     kwargs.setdefault('targets', [])
     self.dl = GlDisplayList()
     super(MTColorPicker, self).__init__(**kwargs)
     self.size = (130, 290)
     self.targets = kwargs.get('targets')
     self.sliders = [
         MTSlider(min=kwargs.get('min'), max=kwargs.get('max'),
                  size=(30, 200),  style={'slider-color': (1, 0, 0, 1)},
                  cls='colorpicker-slider'),
         MTSlider(min=kwargs.get('min'),  max=kwargs.get('max'),
                  size=(30, 200),  style={'slider-color': (0, 1, 0, 1)},
                  cls='colorpicker-slider'),
         MTSlider(min=kwargs.get('min'),  max=kwargs.get('max'),
                  size=(30, 200),  style={'slider-color': (0, 0, 1, 1)},
                  cls='colorpicker-slider')
     ]
     vbox = MTBoxLayout(spacing=10, padding=10)
     for slider in self.sliders:
         slider.value = 77
         slider.push_handlers(on_value_change=self.update_color)
         vbox.add_widget(slider)
     self.add_widget(vbox)
     self.update_color()
     self.touch_positions = {}
 def __init__(self, **kwargs):
     super(MTSpellVKeyboard, self).__init__(**kwargs)
     self.last_word = ''
     self.spelling = kwargs.get('spelling', Spelling())
     self.suggests = []
     self.buttons = []
     self.slayout = MTBoxLayout(orientation='horizontal', spacing=10)
     self.add_widget(self.slayout)
Exemple #5
0
    def __init__(self, **kwargs):
        kwargs.setdefault('do_scale', False)
        kwargs.setdefault('size', (400, 400))
        kwargs.setdefault('show_cancel', True)
        kwargs.setdefault('label_cancel', 'Cancel')
        kwargs.setdefault('label_submit', 'Ok')
        kwargs.setdefault('title', 'PyMT popup')
        kwargs.setdefault('exit_on_submit', True)
        super(MTPopup, self).__init__(**kwargs)

        self.register_event_type('on_submit')
        self.register_event_type('on_cancel')

        self.exit_on_submit = kwargs.get('exit_on_submit')

        # Create layouts
        self.layout = MTBoxLayout(size=self.size,  orientation='vertical')
        self.l_content = MTBoxLayout(orientation='vertical')
        self.l_buttons = MTBoxLayout(size_hint=(1, None),
                                     orientation='horizontal')

        # Titles
        if kwargs.get('title'):
            self.w_title = MTLabel(label=kwargs.get('title'),
                                   autosize=True, cls='popup-title')

        # Buttons
        self.w_submit = MTButton(label=kwargs.get('label_submit'),
                                 size_hint=(0.5, None), height=40,
                                 cls='popup-button')
        self.w_submit.push_handlers(on_release=curry(
            self._dispatch_event, 'on_submit'))
        self.l_buttons.add_widget(self.w_submit)
        if kwargs.get('show_cancel'):
            self.w_cancel = MTButton(label=kwargs.get('label_cancel'),
                                     size_hint=(0.5, None), height=40,
                                     cls='popup-button')
            self.w_cancel.push_handlers(on_release=curry(
                self._dispatch_event, 'on_cancel'))
            self.l_buttons.add_widget(self.w_cancel)

        # Connect
        if kwargs.get('title'):
            self.layout.add_widget(self.w_title)
        self.layout.add_widget(self.l_content)
        self.layout.add_widget(self.l_buttons)
        super(MTPopup, self).add_widget(self.layout)
Exemple #6
0
 def __init__(self, **kwargs):
     super(MTSpellVKeyboard, self).__init__(**kwargs)
     self.last_word = ''
     self.spelling = kwargs.get('spelling', Spelling())
     self.suggests = []
     self.buttons = []
     self.slayout = MTBoxLayout(orientation='horizontal', spacing=10)
     self.add_widget(self.slayout)
Exemple #7
0
    def __init__(self, **kwargs):
        kwargs.setdefault('hide', True)

        super(MTSidePanel, self).__init__(**kwargs)

        self.side = kwargs.get('side', 'left')
        self.align = kwargs.get('align', 'center')
        self.corner_size = kwargs.get('corner_size', 30)
        self.duration = kwargs.get('duration', .5)
        layout = kwargs.get('layout', None)
        corner = kwargs.get('corner', None)

        assert (self.side in ('bottom', 'top', 'left', 'right'))
        assert (self.align
                in ('bottom', 'top', 'left', 'right', 'middle', 'center'))

        if layout is None:
            from pymt.ui.widgets.layout import MTBoxLayout
            layout = MTBoxLayout()
        self.layout = layout
        super(MTSidePanel, self).add_widget(layout)

        if corner is None:
            from pymt.ui.widgets.button import MTButton
            if self.side == 'right':
                label = '<'
            elif self.side == 'left':
                label = '>'
            elif self.side == 'top':
                label = 'v'
            elif self.side == 'bottom':
                label = '^'
            corner = MTButton(label=label)
        else:
            self.corner_size = None
        self.corner = corner
        # Don't add to front or widgets added as children of layout will be occluded
        super(MTSidePanel, self).add_widget(self.corner, front=False)
        self.corner.connect('on_press', self._corner_on_press)

        self.initial_pos = self.pos
        self.need_reposition = True

        if kwargs.get('hide'):
            self.layout.visible = False
            self.hide()
Exemple #8
0
    def __init__(self, **kwargs):
        kwargs.setdefault('bordersize', 10)

        super(MTVideo, self).__init__(**kwargs)

        self._count = 0
        self._controls = False
        self.bordersize = kwargs.get('bordersize')

        # images play/pause/mute
        self.f_play = Image(pymt_icons_dir + 'video-play.png')
        self.f_pause = Image(pymt_icons_dir + 'video-pause.png')
        self.f_vmute = Image(pymt_icons_dir + 'video-volume-mute.png')
        self.f_v100 = Image(pymt_icons_dir + 'video-volume-100.png')

        # create UI
        box = MTBoxLayout(orientation='horizontal',
                          uniform_height=True,
                          spacing=0,
                          padding=0)
        self._btnplay = MTButtonVideo(image=self.f_play,
                                      cls='video-toggleplay')
        self._btnmute = MTButtonVideo(image=self.f_v100,
                                      cls='video-togglemute')
        self._timeline = MTSlider(orientation='horizontal',
                                  cls='video-timeline')

        box.add_widget(self._btnplay)
        box.add_widget(self._btnmute)
        box.add_widget(self._timeline)
        self.add_widget(box)

        # link
        self._btnplay.connect('on_press', self._on_toggle_play)
        self._btnmute.connect('on_press', self._on_toggle_mute)

        self.hide_controls()
Exemple #9
0
class MTSpellVKeyboard(MTVKeyboard):
    '''
    The MTSpellVKeyboard augments the ordinary MTVKeyboard with spelling suggestions.
    You can use it instead of the MTVKeyboard. The only difference are the spelling
    suggestions that are shown on top of the widget. As you type, these are populated
    by suggestions from the system. To use a suggestion, simply tap it.

    :Parameters:
        `spelling` : Spelling object
            If provided, the keyboard uses this spelling instance (can be used to
            indicate which language should be used for spelling). If not provided,
            a fallback spelling instance will be created that uses the first language
            available.
    '''

    def __init__(self, **kwargs):
        super(MTSpellVKeyboard, self).__init__(**kwargs)
        self.last_word = ''
        self.spelling = kwargs.get('spelling', Spelling())
        self.suggests = []
        self.buttons = []
        self.slayout = MTBoxLayout(orientation='horizontal', spacing=10)
        self.add_widget(self.slayout)

    def _clear_suggestions(self):
        self.slayout.children.clear()

    def _add_suggestion(self, word):
        k = {'autoheight': True, 'font_size': 16}
        label = MTSpellVKeyboardLabel(label=' %s ' % word, **k)
        label.connect('on_press', curry(self._press_suggestion, word))
        self.slayout.add_widget(label)

    def _press_suggestion(self, word, *largs):
        l = len(self.last_word)
        if not l:
            return
        self.text = self.text[0:-l] + word
        self._clear_suggestions()

    def on_touch_down(self, touch):
        x, y = self.to_local(touch.x, touch.y)
        touch.push('xy')
        touch.x, touch.y = x, y
        if self.slayout.dispatch_event('on_touch_down', touch):
            touch.pop()
            return True
        touch.pop()
        return super(MTSpellVKeyboard, self).on_touch_down(touch)

    def on_text_change(self, text):
        self._clear_suggestions()
        if len(text) == 0:
            return

        l = text.replace('\r\n,.:; ', ' ')
        self.last_word = l.split(' ')[-1]
        if self.last_word == '':
            return

        self._add_suggestion(self.last_word)

        self.suggests = self.spelling.suggest(self.last_word)[:10]
        for word in self.suggests:
            self._add_suggestion(word)

    def on_update(self):
        # ensure the layout position
        self.slayout.pos = (5, self.height + 5)
        super(MTSpellVKeyboard, self).on_update()
Exemple #10
0
class MTPopup(MTScatterWidget):
    '''Popup with customizable content.

    :Parameters:
        `show_cancel`: bool, default to True
            Show/hide the cancel button
        `label_cancel`: str, default to 'Cancel'
            Change the label of cancel button
        `label_submit`: str, default to 'Ok'
            Change the label of submit button
        `title`: str, default to 'PyMT popup'
            Title of the popup (if None, no title will be added.)
        `exit_on_submit`: bool, default to 'True'
            Title of the popup (if None, no title will be added.)

    :Events:
        `on_submit`
            Fired when the popup submit button is pressed.
            In default behavior, the widget remove himself from parent.
        `on_cancel`
            Fired when the popup cancel button is pressed.
            In default behavior, the widget remove himself from parent.
    '''
    def __init__(self, **kwargs):
        kwargs.setdefault('do_scale', False)
        kwargs.setdefault('size', (400, 400))
        kwargs.setdefault('show_cancel', True)
        kwargs.setdefault('label_cancel', 'Cancel')
        kwargs.setdefault('label_submit', 'Ok')
        kwargs.setdefault('title', 'PyMT popup')
        kwargs.setdefault('exit_on_submit', True)
        super(MTPopup, self).__init__(**kwargs)

        self.register_event_type('on_submit')
        self.register_event_type('on_cancel')

        self.exit_on_submit = kwargs.get('exit_on_submit')

        # Create layouts
        self.layout = MTBoxLayout(size=self.size,  orientation='vertical')
        self.l_content = MTBoxLayout(orientation='vertical')
        self.l_buttons = MTBoxLayout(size_hint=(1, None),
                                     orientation='horizontal')

        # Titles
        if kwargs.get('title'):
            self.w_title = MTLabel(label=kwargs.get('title'),
                                   autosize=True, cls='popup-title')

        # Buttons
        self.w_submit = MTButton(label=kwargs.get('label_submit'),
                                 size_hint=(0.5, None), height=40,
                                 cls='popup-button')
        self.w_submit.push_handlers(on_release=curry(
            self._dispatch_event, 'on_submit'))
        self.l_buttons.add_widget(self.w_submit)
        if kwargs.get('show_cancel'):
            self.w_cancel = MTButton(label=kwargs.get('label_cancel'),
                                     size_hint=(0.5, None), height=40,
                                     cls='popup-button')
            self.w_cancel.push_handlers(on_release=curry(
                self._dispatch_event, 'on_cancel'))
            self.l_buttons.add_widget(self.w_cancel)

        # Connect
        if kwargs.get('title'):
            self.layout.add_widget(self.w_title)
        self.layout.add_widget(self.l_content)
        self.layout.add_widget(self.l_buttons)
        super(MTPopup, self).add_widget(self.layout)

    def _ensure_layout(self, force=False):
        while force or (self.size != self.layout.size):
            self.layout.do_layout()
            self.size = self.layout.size
            force = False

    def add_widget(self, widget, force=False):
        self.l_content.add_widget(widget)
        self._ensure_layout(force)

    def remove_widget(self, widget, force=False):
        self.l_content.remove_widget(widget)
        self._ensure_layout(force)

    def close(self):
        if self.exit_on_submit:
            self.parent.remove_widget(self)
        else:
            self.hide()

    def on_submit(self):
        self.close()

    def on_cancel(self):
        self.close()

    def _dispatch_event(self, event, *largs):
        self.dispatch_event(event)

    def draw(self):
        # draw background
        set_color(*self.style['bg-color'])
        drawCSSRectangle(size=self.size, style=self.style)
Exemple #11
0
class MTSpellVKeyboard(MTVKeyboard):
    '''
    The MTSpellVKeyboard augments the ordinary MTVKeyboard with spelling suggestions.
    You can use it instead of the MTVKeyboard. The only difference are the spelling
    suggestions that are shown on top of the widget. As you type, these are populated
    by suggestions from the system. To use a suggestion, simply tap it.

    :Parameters:
        `spelling` : Spelling object
            If provided, the keyboard uses this spelling instance (can be used to
            indicate which language should be used for spelling). If not provided,
            a fallback spelling instance will be created that uses the first language
            available.
    '''

    def __init__(self, **kwargs):
        super(MTSpellVKeyboard, self).__init__(**kwargs)
        self.last_word = ''
        self.spelling = kwargs.get('spelling', Spelling())
        self.suggests = []
        self.buttons = []
        self.slayout = MTBoxLayout(orientation='horizontal', spacing=10)
        self.add_widget(self.slayout)

    def _clear_suggestions(self):
        self.slayout.children.clear()

    def _add_suggestion(self, word):
        k = {'autoheight': True, 'font_size': 16}
        label = MTSpellVKeyboardLabel(label=' %s ' % word, **k)
        label.connect('on_press', curry(self._press_suggestion, word))
        self.slayout.add_widget(label)

    def _press_suggestion(self, word, *largs):
        l = len(self.last_word)
        if not l:
            return
        self.text = self.text[0:-l] + word
        self._clear_suggestions()

    def on_touch_down(self, touch):
        x, y = self.to_local(touch.x, touch.y)
        touch.push('xy')
        touch.x, touch.y = x, y
        if self.slayout.dispatch_event('on_touch_down', touch):
            touch.pop()
            return True
        touch.pop()
        return super(MTSpellVKeyboard, self).on_touch_down(touch)

    def on_text_change(self, text):
        self._clear_suggestions()
        if len(text) == 0:
            return

        l = text.replace('\r\n,.:; ', ' ')
        self.last_word = l.split(' ')[-1]
        if self.last_word == '':
            return

        self._add_suggestion(self.last_word)

        self.suggests = self.spelling.suggest(self.last_word)[:10]
        for word in self.suggests:
            self._add_suggestion(word)

    def on_update(self):
        # ensure the layout position
        self.slayout.pos = (5, self.height + 5)
        super(MTSpellVKeyboard, self).on_update()