示例#1
0
    def on_touch_move(self, touch):
        # accept only the touch we've got first.
        if touch.grab_current != self:
            return

        self._animation = False

        # calculate the distance between the touch and the old position
        d = touch.userdata['coverflow.pos'][0] - touch.xpos

        # cancel on-select if needed
        if abs(d) > self.trigger_distance:
            touch.userdata['coverflow.noclick'] = True

        # calculate new cover selected
        cover_distance = self.cover_distance
        len_children = len(self.children) - 1
        ipos = self._internal_position - (touch.xpos - touch.dxpos)
        ipos = boundary(ipos, 0, len_children * cover_distance)
        self._internal_position = ipos

        # calculate selection
        selection = int(round(ipos / cover_distance))
        selection = boundary(selection, 0, len_children)

        # update transition and selection
        # (will fire an event if selection have changed.)
        self._transition = ipos / cover_distance - selection
        self.selection = selection

        return True
示例#2
0
    def on_touch_move(self, touch):
        # accept only the touch we've got first.
        if touch.grab_current != self:
            return

        self._animation = False

        # calculate the distance between the touch and the old position
        d = touch.userdata['coverflow.pos'][0] - touch.xpos

        # cancel on-select if needed
        if abs(d) > self.trigger_distance:
            touch.userdata['coverflow.noclick'] = True

        # calculate new cover selected
        cover_distance = self.cover_distance
        len_children = len(self.children) - 1
        ipos = self._internal_position - (touch.xpos - touch.dxpos)
        ipos = boundary(ipos, 0, len_children * cover_distance)
        self._internal_position = ipos

        # calculate selection
        selection = int(round(ipos / cover_distance))
        selection = boundary(selection, 0, len_children)

        # update transition and selection
        # (will fire an event if selection have changed.)
        self._transition = ipos / cover_distance - selection
        self.selection = selection

        return True
示例#3
0
文件: klist.py 项目: hansent/pymt
 def on_touch_move(self, touch):
     if touch.grab_current is not self:
         return
     cx, cy = touch.userdata["list.startpos"]
     acceleration = self.max_acceleration
     if self.do_x:
         self.content_x = touch.x - touch.oxpos + cx
         self._vx += touch.dxpos - touch.x
         self._vx = boundary(self._vx, -acceleration, acceleration)
     if self.do_y:
         self.content_y = touch.y - touch.oypos + cy
         self._vy += touch.dypos - touch.y
         self._vy = boundary(self._vy, -acceleration, acceleration)
     return True
示例#4
0
文件: klist.py 项目: gavine199/pymt
 def on_touch_move(self, touch):
     if touch.grab_current is not self:
         return
     cx, cy = touch.userdata['list.startpos']
     acceleration = self.max_acceleration
     if self.do_x:
         self.content_x = touch.x - touch.oxpos + cx
         self._vx += touch.dxpos - touch.x
         self._vx = boundary(self._vx, -acceleration, acceleration)
     if self.do_y:
         self.content_y = touch.y - touch.oypos + cy
         self._vy += touch.dypos - touch.y
         self._vy = boundary(self._vy, -acceleration, acceleration)
     return True
示例#5
0
    def ensure_bounding(self):
        size = float(self._last_content_size)
        if size <= 0:
            return

        self._scrollbar_size = 1
        self._scrollbar_index = 0

        if self.do_y:
            if size < self.height:
                self.yoffset = 0
            else:
                self.yoffset = boundary(self.yoffset, -size + self.height, 0)
                self._scrollbar_size = self.height / size
                self._scrollbar_index = -self.yoffset / size
        if self.do_x:
            if size < self.width:
                self.xoffset = 0
            else:
                self.xoffset = boundary(self.xoffset, -size + self.width, 0)
                self._scrollbar_size = self.width / size
                self._scrollbar_index = -self.xoffset / size
示例#6
0
    def ensure_bounding(self):
        size = float(self._last_content_size)
        if size <= 0:
            return

        self._scrollbar_size = 1
        self._scrollbar_index = 0

        if self.do_y:
            if size < self.height:
                self.yoffset = 0
            else:
                self.yoffset = boundary(self.yoffset, -size + self.height, 0)
                self._scrollbar_size = self.height / size
                self._scrollbar_index = -self.yoffset / size
        elif self.do_x:
            if size < self.width:
                self.xoffset = 0
            else:
                self.xoffset = boundary(self.xoffset, -size + self.width, 0)
                self._scrollbar_size = self.width / size
                self._scrollbar_index = -self.xoffset / size
示例#7
0
 def get_cursor_from_index(self, index):
     '''Return the (row, col) of the cursor from text index'''
     index = boundary(0, len(self.value), index)
     if index <= 0:
         return 0, 0
     lf = self.lines_flags
     l = self.lines
     i = 0
     for row in xrange(len(l)):
         ni = i + len(l[row])
         if lf[row] & FL_IS_NEWLINE:
             ni += 1
             i += 1
         if ni >= index:
             return index - i, row
         i = ni
     return index, row
示例#8
0
    def on_touch_move(self, touch):
        # accept only the touch we've got first.
        if touch.grab_current != self:
            return

        # stop transition animation if exist
        if self._animation:
            self._animation.stop()
            self._animation = None

        # calculate the distance between the touch and the old position
        d = touch.userdata['coverflow.pos'][0] - touch.xpos

        # cancel on-select if needed
        if abs(d) > self.trigger_distance:
            touch.userdata['coverflow.noclick'] = True

        # and calculate transition: the delta movement between
        # old and new cover position
        self._transition = d / self.trigger_cover_distance

        # don't make transition go farther than possible
        if self._transition < 0 and self._selection == 0:
            self._transition = 0
        if self._transition > 0 and self._selection == len(self.children) - 1:
            self._transition = 0

        # are we able to switch cover ?
        if abs(self._transition) < 1.:
            return

        # cover switch !
        self._selection += int(self._transition)
        self._selection = boundary(self._selection, 0, len(self.children) - 1)

        # adjust transition
        self._transition -= int(self._transition)

        # save the position of the touch
        # to restart a switch from this position
        touch.userdata['coverflow.pos'] = touch.pos

        # fire on_change
        self.dispatch_event('on_change', self.children[self._selection])
        return True
示例#9
0
    def process_kinetic(self):
        '''Processing of kinetic, called in draw time.'''
        dt = getFrameDt()
        todelete = []
        acceleration = self.max_acceleration

        for touchID in self.touch:
            ktouch = self.touch[touchID]
            if abs(ktouch.X) < 0.01:
                ktouch.X = 0
            else:
                ktouch.X /= 1 + (self.friction * dt)
                ktouch.X = boundary(ktouch.X, -acceleration, acceleration)
            if abs(ktouch.Y) < 0.01:
                ktouch.Y = 0
            else:
                ktouch.Y /= 1 + (self.friction * dt)
                ktouch.Y = boundary(ktouch.Y, -acceleration, acceleration)

            if ktouch.mode != 'spinning':
                continue

            # process kinetic
            event        = ''
            ktouch.dxpos = ktouch.x
            ktouch.dypos = ktouch.y
            ktouch.x    += ktouch.X
            ktouch.y    += ktouch.Y


            if Vector(ktouch.X, ktouch.Y).length() < self.velstop:
                # simulation finished
                event = 'up'
                getCurrentTouches().remove(ktouch)
                super(MTKinetic, self).on_touch_up(ktouch)
                todelete.append(touchID)
            else:
                # simulation in progress
                event = 'move'
                super(MTKinetic, self).on_touch_move(ktouch)

            # dispatch ktouch also in grab mode
            for _wid in ktouch.grab_list[:]:
                wid = _wid()
                if wid is None:
                    ktouch.grab_list.remove(_wid)
                    continue
                ktouch.push()
                ktouch.x, ktouch.y = self.to_window(*ktouch.pos)
                ktouch.dxpos, ktouch.dypos = self.to_window(*ktouch.dpos)
                if wid.parent:
                    ktouch.x, ktouch.y = wid.parent.to_widget(
                        ktouch.x, ktouch.y)
                    ktouch.dxpos, ktouch.dypos = wid.parent.to_widget(
                        ktouch.dxpos, ktouch.dypos)
                else:
                    ktouch.x, ktouch.y = wid.to_parent(
                        *wid.to_widget(ktouch.x, ktouch.y))
                    ktouch.dxpos, ktouch.dypos = wid.to_parent(
                        *wid.to_widget(ktouch.dxpos, ktouch.dypos))
                ktouch.grab_current = wid
                ktouch.grab_state   = True
                if event == 'move':
                    wid.dispatch_event('on_touch_move', ktouch)
                else:
                    # if the widget is not visible, the on_touch_up may have
                    # disabled
                    wid.register_event_type('on_touch_up')
                    wid.dispatch_event('on_touch_up', ktouch)
                ktouch.grab_state   = False
                ktouch.grab_current = None
                ktouch.pop()

        # remove finished event
        for touchID in todelete:
            del self.touch[touchID]
示例#10
0
 def _set_cursor(self, pos):
     l = self.lines
     cc, cr = pos
     self.cursor_row = cr = boundary(0, len(l) - 1, cr)
     self.cursor_col = boundary(0, len(l[cr]), cc)
     self.cursor_fade = 1
示例#11
0
文件: kinetic.py 项目: gavine199/pymt
    def process_kinetic(self):
        '''Processing of kinetic, called in draw time.'''
        dt = getFrameDt()
        todelete = []
        acceleration = self.max_acceleration

        for touchID in self.touch:
            ktouch = self.touch[touchID]
            if abs(ktouch.X) < 0.01:
                ktouch.X = 0
            else:
                ktouch.X /= 1 + (self.friction * dt)
                ktouch.X = boundary(ktouch.X, -acceleration, acceleration)
            if abs(ktouch.Y) < 0.01:
                ktouch.Y = 0
            else:
                ktouch.Y /= 1 + (self.friction * dt)
                ktouch.Y = boundary(ktouch.Y, -acceleration, acceleration)

            if ktouch.mode != 'spinning':
                continue

            # process kinetic
            event = ''
            ktouch.dxpos = ktouch.x
            ktouch.dypos = ktouch.y
            ktouch.x += ktouch.X
            ktouch.y += ktouch.Y

            if Vector(ktouch.X, ktouch.Y).length() < self.velstop:
                # simulation finished
                event = 'up'
                getCurrentTouches().remove(ktouch)
                super(MTKinetic, self).on_touch_up(ktouch)
                todelete.append(touchID)
            else:
                # simulation in progress
                event = 'move'
                super(MTKinetic, self).on_touch_move(ktouch)

            # dispatch ktouch also in grab mode
            for _wid in ktouch.grab_list[:]:
                wid = _wid()
                if wid is None:
                    ktouch.grab_list.remove(_wid)
                    continue
                ktouch.push()
                ktouch.x, ktouch.y = self.to_window(*ktouch.pos)
                ktouch.dxpos, ktouch.dypos = self.to_window(*ktouch.dpos)
                if wid.parent:
                    ktouch.x, ktouch.y = wid.parent.to_widget(
                        ktouch.x, ktouch.y)
                    ktouch.dxpos, ktouch.dypos = wid.parent.to_widget(
                        ktouch.dxpos, ktouch.dypos)
                else:
                    ktouch.x, ktouch.y = wid.to_parent(
                        *wid.to_widget(ktouch.x, ktouch.y))
                    ktouch.dxpos, ktouch.dypos = wid.to_parent(
                        *wid.to_widget(ktouch.dxpos, ktouch.dypos))
                ktouch.grab_current = wid
                ktouch.grab_state = True
                if event == 'move':
                    wid.dispatch_event('on_touch_move', ktouch)
                else:
                    # if the widget is not visible, the on_touch_up may have
                    # disabled
                    wid.register_event_type('on_touch_up')
                    wid.dispatch_event('on_touch_up', ktouch)
                ktouch.grab_state = False
                ktouch.grab_current = None
                ktouch.pop()

        # remove finished event
        for touchID in todelete:
            del self.touch[touchID]