示例#1
0
    def __init__(self, **kwargs):
        '''Kinetic object, the base object for every child in kineticlist.

        :Parameters:
            `deletable`: bool, default to True
                Indicate if object can be deleted or not
        '''
        kwargs.setdefault('deletable', True)
        super(MTKineticObject, self).__init__(**kwargs)
        self.deletable = kwargs.get('deletable')
        self.register_event_type('on_animation_complete')
        self.push_handlers(on_animation_complete=self.on_animation_complete)

        # List of attributes that can be searched
        self.attr_search = ['label']

        # In case the widget has to move itself
        # while still having kinetic movement applied
        self.xoffset = self.yoffset = 0

        # The position values that the kinetic container edits.
        # We do this so we can break free and move ourself it necessary
        self.kx = self.ky = 0

        self.db_alpha = 0.0

        # Set to true if you want to break free from
        # the grasp of a kinetic widget
        self.free = False

        # Delete Button
        if self.deletable:
            self.db = MTButton(label='',
                               size=(40, 40),
                               pos=(self.x + self.width - 40,
                                    self.y + self.height - 40),
                               style={'bg-color': (1, 0, 0, 0)},
                               visible=False)
            self.db.push_handlers(on_press=self._delete_callback)
            self.add_widget(self.db)

            self.a_delete = Animation(width=0,
                                      height=0,
                                      xoffset=self.kx + self.width / 2,
                                      yoffset=self.ky + self.height / 2,
                                      duration=0.5,
                                      f='ease_in_cubic')

        self.a_show = Animation(db_alpha=.5, duration=0.25)
        self.a_hide = Animation(db_alpha=0.0, duration=0.25)
示例#2
0
    def _create_ui(self):
        # Title Text
        if self.titletext is not None:
            self.title = Label(font_size=18,
                               bold=True,
                               anchor_x='center',
                               anchor_y='center',
                               label=self.titletext)
            self.title.x = self.width / 2 + self.x
            self.title.y = self.height - 20 + self.y

        # Delete Button
        if self.deletable:
            self.db = MTToggleButton(label='X',
                                     pos=(self.x + self.width - 80,
                                          self.y + self.height - 40),
                                     size=(80, 40),
                                     cls='kineticlist-delete')
            self.db.push_handlers(on_press=self.toggle_delete)
            self.widgets.append(self.db)

        # Search Button and Input Text Area
        if self.searchable:
            self.sb = MTToggleButton(
                label='S',  #Button
                pos=(self.x, self.y + self.width - 40),
                size=(80, 40),
                cls='kineticlist-search')

            self.sb.push_handlers(on_press=self.toggle_search)
            self.sb.parent = self
            self.widgets.append(self.sb)

            self.sinput = pymt.MTTextInput(pos=(self.x,
                                                self.y + self.height - 40),
                                           size=(80, 40),
                                           style={'font-size': 20})
            self.sinput.parent = self
            self.sinput.push_handlers(on_text_change=self.apply_filter)
            self.widgets.insert(0, self.sinput)

            # Animations to hide and show the search text input box
            self._a_sinput_in = Animation(y=self.y + self.height - 40 -
                                          self.sinput.size[1],
                                          duration=0.5,
                                          f='ease_out_cubic')
            self._a_sinput_out = Animation(y=self.y + self.height -
                                           self.sinput.size[1],
                                           duration=0.5,
                                           f='ease_out_cubic')
示例#3
0
    def __init__(self, **kwargs):
        kwargs.setdefault('flipangle', 90.)
        super(MTFlippableWidget, self).__init__(**kwargs)
        self.flipangle = kwargs.get('flipangle')

        # For flipping animations
        self.zangle = 0
        self.side = 'front'

        # Holds children for both sides
        self.children_front = SafeList()
        self.children_back = SafeList()

        self._anim_current = None
        self._anim_back = Animation(zangle=180)
        self._anim_front = Animation(zangle=0)
示例#4
0
 def hide(self):
     dpos = self._get_position_for(False)
     if dpos is None:
         return
     anim = Animation(duration=self.duration, f='ease_out_cubic', pos=dpos)
     anim.connect('on_complete', self._on_animation_complete_hide)
     self.layout.do(anim)
示例#5
0
 def reposition_child(self, child, **kwargs):
     if self.animation_type and len(kwargs):
         kwargs['f'] = self.animation_type
         kwargs['d'] = self.animation_duration
         child.do(Animation(**kwargs))
     else:
         for prop in kwargs:
             child.__setattr__(prop, kwargs[prop])
示例#6
0
 def notify_error(self):
     '''Call this function to make animation on background as an error
     '''
     error_color = self.style['bg-color-error']
     if self._notify_animation is not None:
         self._notify_animation.stop()
     self.style['bg-color'] = self._notify_bg_color
     self.style['bg-color-active'] = self._notify_bg_color_active
     self._notify_animation = self.do(
         Animation(style={
             'bg-color': error_color,
             'bg-color-active': error_color
         },
                   f=lambda x: 1 - AnimationAlpha.ease_in_out_quart(x)))
示例#7
0
 def show(self):
     dpos = self._get_position_for(True)
     self.layout.visible = True
     self.layout.do(
         Animation(duration=self.duration, f='ease_out_cubic', pos=dpos))