Пример #1
0
 def _make_placeholder(self, data):
     return Comment(size_hint=(1, None),
                    height=_scale_to_theme_dpi(90),
                    data=data,
                    placeholder_texture=placeholderimage.texture,
                    factor=self._make_template,
                    gesture_target=self.target,
                    gesture_anim_height=_scale_to_theme_dpi(70),
                    target=self.target)
Пример #2
0
 def _make_placeholder(self, data):
     return Comment(
         size_hint=(1, None),
         height=_scale_to_theme_dpi(90),
         data=data,
         placeholder_texture=placeholderimage.texture,
         factor=self._make_template,
         gesture_target=self.target,
         gesture_anim_height=_scale_to_theme_dpi(70),
         target=self.target)
Пример #3
0
class Menu(CustomDropDown):
    background_color = ListProperty([0, 0, 0, 1])
    outline_color = ListProperty([1., 1., 1., 1])
    item_sep_height = NumericProperty(_scale_to_theme_dpi(1))
    item_sep_margin = NumericProperty(_scale_to_theme_dpi(1))

    def __init__(self, **kwargs):
        super(Menu, self).__init__(**kwargs)
        self.bind(item_sep_height=self._set_item_sep_height)
        self._set_item_sep_height()

    def _set_item_sep_height(self):
        c = self.container
        if c:
            c.padding[1] += self.item_sep_height
            c.padding[3] += self.item_sep_height
            c.spacing[1] += self.item_sep_height

    def _item_state_changed(self, item, value):
        if value == 'down':
            self.select(item)

    def on_container(self, instance, value):
        super(CustomDropDown, self).on_container(instance, value)
        for w, largs in getattr(self, 'queued_items', []):
            self.add_widget(w, *largs)
        self.queued_items = []

    def add_widget(self, widget, *largs):
        if isinstance(widget, MenuItem):
            widget.bind(state=self._item_state_changed)
            widget.item_sep_margin = self.item_sep_margin
            if not self.container:
                self.queued_items = getattr(self, 'queued_items',
                                            []) + [(widget, largs)]
                return
        super(Menu, self).add_widget(widget, *largs)
        self.scroll_y = 0
        self.scroll_x = 0

    def open(self, widget, selected=None):
        if selected:
            for i in self.items():
                if i.title == selected:
                    i.state = 'down'
                    break
        else:
            for i in self.items():
                i.state = 'normal'
        super(Menu, self).open(widget)
Пример #4
0
 def __init__(self, **kwargs):
     self.prev_stop_pos = -1.0
     self.stop_pos = 0.0
     self.prev_vp_height = 0
     self.last_remove_pos = [0, 0]
     self.last_addition_pos = [0, 0]
     self.border_event_dispatched = dict((event, False) for event in self.__events__)
     self.border_event_fired = dict((event, False) for event in self.__events__)
     super(StableScrollView, self).__init__(**kwargs)
     self.scroll_timeout = 80
     self.scroll_distance = int(_scale_to_theme_dpi(self.scroll_distance*1.333))
Пример #5
0
    def on_touch_move(self, touch):
        if touch.grab_current is not self:
            return False
        swipe_range = 0.35
        swipe_dx = touch.osx - touch.sx
        swipe_range_y = 0.35
        swipe_dy = touch.osy - touch.sy
        touch_distance = max(abs(swipe_dx), abs(swipe_dy))
        #Logger.info('<<<MOVE>>>: %s %s %s %s' % (str(touch.pos), touch_distance, touch.dx, touch.dy))
        scale = min(1, max(.001, abs(swipe_dx) / abs(swipe_range)))
        scale_y = min(1, max(.001, abs(swipe_dy) / swipe_range_y))
        sign = float(swipe_dx) / swipe_range
        self._vote_scale = scale if sign >= 0 else -scale
        if not self._vote_widget and abs(scale) > 0.1:
            cx, cy = self.to_window(*self.center)
            global global_vote_widget
            self._vote_widget = global_vote_widget
            pos = (cx - self._vote_widget.width / 2,
                   cy - self._vote_widget.height / 2)
            self._vote_widget.clear(pos=pos)
            if self._gesture_target:
                self._gesture_target.add_gesture_animation(self._vote_widget)

        v = self._vote_widget
        if v:
            #Logger.info('<<<MOVE>>>: osx=%s sx=%s r=%s dx=%s' % (touch.osx, touch.sx, swipe_range, swipe_dx))
            rescale = 1 + _scale_to_theme_dpi(2 * 1.33) * scale
            if v.height * 3 > self._gesture_anim_max_height and rescale * v.height > self._gesture_anim_max_height:
                rescale = float(self._gesture_anim_max_height) / float(
                    v.height)

            if scale_y < 0.0:
                pass
            elif scale_y > 0.35:
                scale = .001
            elif scale_y >= 0.0:
                scale *= 1.  ##-scale_y
            self._vote_scale = scale if sign >= 0 else -scale
            #Logger.info('<<<MOVE>>>: %s %s osy=%s sy=%s r=%s dy=%s' % (scale, scale_y, touch.osy, touch.sy, swipe_range_y, swipe_dy))

            ancore = v.center
            #print 'anim: pos %s sign %s scaling %s ancore %s' % (v.pos, sign, scale, ancore)
            v.apply_transform(rescale=rescale, anchor=ancore)
            v.setscale(scale, sign)
        return True
Пример #6
0
    def on_touch_move(self, touch):
        if touch.grab_current is not self:
            return False
        swipe_range = 0.35
        swipe_dx = touch.osx - touch.sx
        swipe_range_y = 0.35
        swipe_dy = touch.osy - touch.sy
        touch_distance = max(abs(swipe_dx), abs(swipe_dy))
        #Logger.info('<<<MOVE>>>: %s %s %s %s' % (str(touch.pos), touch_distance, touch.dx, touch.dy))
        scale = min(1, max(.001, abs(swipe_dx) / abs(swipe_range)))
        scale_y = min(1, max(.001, abs(swipe_dy) / swipe_range_y))
        sign = float(swipe_dx) / swipe_range
        self._vote_scale = scale if sign >= 0 else -scale
        if not self._vote_widget and abs(scale) > 0.1:
            cx, cy = self.to_window(*self.center)
            global global_vote_widget
            self._vote_widget = global_vote_widget
            pos = (cx - self._vote_widget.width/2, cy - self._vote_widget.height/2)
            self._vote_widget.clear(pos=pos)
            if self._gesture_target:
                self._gesture_target.add_gesture_animation(self._vote_widget)

        v = self._vote_widget
        if v:
            #Logger.info('<<<MOVE>>>: osx=%s sx=%s r=%s dx=%s' % (touch.osx, touch.sx, swipe_range, swipe_dx))
            rescale = 1+_scale_to_theme_dpi(2*1.33)*scale
            if v.height*3 > self._gesture_anim_max_height and rescale*v.height > self._gesture_anim_max_height:
                rescale = float(self._gesture_anim_max_height)/float(v.height)

            if scale_y < 0.0:
                pass
            elif scale_y > 0.35:
                scale = .001
            elif scale_y >= 0.0:
                scale *= 1. ##-scale_y
            self._vote_scale = scale if sign >= 0 else -scale
            #Logger.info('<<<MOVE>>>: %s %s osy=%s sy=%s r=%s dy=%s' % (scale, scale_y, touch.osy, touch.sy, swipe_range_y, swipe_dy))

            ancore = v.center
            #print 'anim: pos %s sign %s scaling %s ancore %s' % (v.pos, sign, scale, ancore)
            v.apply_transform(rescale=rescale, anchor=ancore)
            v.setscale(scale, sign)
        return True
Пример #7
0
def get_keyboard_top():
    from kivy import platform
    global _keyboard_top_absolute
    if _keyboard_top_absolute > 0:
        return _keyboard_top_absolute

    if platform == 'android':
        import android
        #from kivy.clock import Clock
        from kivy.logger import Logger
        from time import sleep

        class Target:
            password = False
            keyboard_suggestions = True

        target = Target()
        android.show_keyboard(target, 'text')
        for i in range(50):
            keyboard_top = android.get_keyboard_height()
            Logger.info('Theme: android get_keyboard_height return %s' %
                        keyboard_top)
            try:
                _keyboard_top_absolute = int(keyboard_top)
            except Exception:
                pass
            if _keyboard_top_absolute > 0:
                break
            sleep(0.025)
    elif platform == 'ios':
        from kivy.core.window import Window
        if hasattr(Window, 'keyboard_height') and (Window.keyboard_height > 0):
            _keyboard_top_absolute = Window.keyboard_height
            print 'HAS KEYB HEIGHT %s' % _keyboard_top_absolute
        else:
            #from kivy.metrics import Metrics
            _keyboard_top_absolute = int(Window.height *
                                         0.3805)  #288.0*Metrics.density
            print 'DEF KEYB HEIGHT %s' % _keyboard_top_absolute
    else:
        _keyboard_top_absolute = _scale_to_theme_dpi(300)

    return _keyboard_top_absolute
Пример #8
0
def get_keyboard_top():
    from kivy import platform
    global _keyboard_top_absolute
    if _keyboard_top_absolute > 0:
        return _keyboard_top_absolute

    if platform == 'android':
        import android
        #from kivy.clock import Clock
        from kivy.logger import Logger
        from time import sleep

        class Target:
            password = False
            keyboard_suggestions = True
        target = Target()
        android.show_keyboard(target, 'text')
        for i in range(50):
            keyboard_top = android.get_keyboard_height()
            Logger.info('Theme: android get_keyboard_height return %s' % keyboard_top)
            try:
                _keyboard_top_absolute = int(keyboard_top)
            except Exception:
                pass
            if _keyboard_top_absolute > 0:
                break
            sleep(0.025)
    elif platform == 'ios':
        from kivy.core.window import Window
        if hasattr(Window, 'keyboard_height') and (Window.keyboard_height > 0):
            _keyboard_top_absolute =  Window.keyboard_height
            print 'HAS KEYB HEIGHT %s' % _keyboard_top_absolute
        else:
            #from kivy.metrics import Metrics
            _keyboard_top_absolute = int(Window.height*0.3805) #288.0*Metrics.density
            print 'DEF KEYB HEIGHT %s' % _keyboard_top_absolute
    else:
        _keyboard_top_absolute = _scale_to_theme_dpi(300)


    return _keyboard_top_absolute