Esempio n. 1
0
    def test_vertical_scroll_doesnt_depend_on_lines_rendering(self):
        # TextInput.on_touch_down was checking the possibility to scroll_up
        # using the positions of the rendered lines' rects. These positions
        # don't change when the lines are skipped (e.g. during fast scroll
        # or ctrl+cursor_home) which lead to scroll freeze
        ti = self.make_scrollable_text_input()

        # move viewport to the first line
        ti.do_cursor_movement('cursor_home', control=True)
        self.advance_frames(1)
        assert ti._visible_lines_range == (0, 10)

        from kivy.base import EventLoop
        win = EventLoop.window

        # slowly scroll to the last line to render all lines at least once
        for _ in range(30):  # little overscroll is important for detection
            touch = UTMotionEvent("unittest", next(touch_id), {
                "x": ti.center_x / float(win.width),
                "y": ti.center_y / float(win.height),
            })
            touch.profile.append('button')
            touch.button = 'scrollup'

            EventLoop.post_dispatch_input("begin", touch)
            EventLoop.post_dispatch_input("end", touch)
            self.advance_frames(1)
        assert ti._visible_lines_range == (20, 30)

        # jump to the first line again
        ti.do_cursor_movement('cursor_home', control=True)

        # temp fix: only change of cursor position triggers update as for now
        ti._trigger_update_graphics()

        self.advance_frames(1)
        assert ti._visible_lines_range == (0, 10)

        # scrolling up should work now
        touch = UTMotionEvent("unittest", next(touch_id), {
            "x": ti.center_x / float(win.width),
            "y": ti.center_y / float(win.height),
        })
        touch.profile.append('button')
        touch.button = 'scrollup'
        EventLoop.post_dispatch_input("begin", touch)
        EventLoop.post_dispatch_input("end", touch)
        self.advance_frames(1)
        assert ti._visible_lines_range == (1, 11)
Esempio n. 2
0
    def test_scroll_doesnt_move_cursor(self):
        ti = self.make_scrollable_text_input()

        from kivy.base import EventLoop
        win = EventLoop.window
        touch = UTMotionEvent("unittest", next(touch_id), {
            "x": ti.center_x / float(win.width),
            "y": ti.center_y / float(win.height),
        })
        touch.profile.append('button')
        touch.button = 'scrolldown'

        prev_cursor = ti.cursor
        assert ti._visible_lines_range == (20, 30)
        EventLoop.post_dispatch_input("begin", touch)
        EventLoop.post_dispatch_input("end", touch)
        self.advance_frames(1)
        assert ti._visible_lines_range == (19, 29)
        assert ti.cursor == prev_cursor
Esempio n. 3
0
    def test_scroll_doesnt_move_cursor(self):
        ti = self.make_scrollable_text_input()

        from kivy.base import EventLoop
        win = EventLoop.window
        touch = UTMotionEvent("unittest", next(touch_id), {
            "x": ti.center_x / float(win.width),
            "y": ti.center_y / float(win.height),
        })
        touch.profile.append('button')
        touch.button = 'scrolldown'

        prev_cursor = ti.cursor
        assert ti._visible_lines_range == (20, 30)
        EventLoop.post_dispatch_input("begin", touch)
        EventLoop.post_dispatch_input("end", touch)
        self.advance_frames(1)
        assert ti._visible_lines_range == (19, 29)
        assert ti.cursor == prev_cursor
Esempio n. 4
0
    def process_points(self, scroll, points):
        win = EventLoop.window
        dt = 0.02

        for point in points:
            if DEBUG:
                print('point:', point, scroll.scroll_x, scroll.scroll_y)
                Clock.schedule_once(lambda *dt: sleep(0.5), 0)
                self.render(scroll)

            x, y, nx, ny, pos_x, pos_y, border_check = point
            scroll.bar_pos = (pos_x, pos_y)

            touch = UTMotionEvent("unittest", next(touch_id), {
                "x": x / float(win.width),
                "y": y / float(win.height),
            })

            # we start with the default top-left corner
            self.assertAlmostEqual(scroll.scroll_x, 0.0, delta=dt)
            self.assertAlmostEqual(scroll.scroll_y, 1.0, delta=dt)

            # check the collision with the margin empty area
            if border_check:
                EventLoop.post_dispatch_input("begin", touch)
                touch.move({
                    "x": nx / float(win.width),
                    "y": ny / float(win.height)
                })
                EventLoop.post_dispatch_input("update", touch)
                EventLoop.post_dispatch_input("end", touch)

                self.assertAlmostEqual(scroll.scroll_x, 0.0, delta=dt)
                self.assertAlmostEqual(scroll.scroll_y, 1.0, delta=dt)
                return

            EventLoop.post_dispatch_input("begin", touch)
            touch.move({
                "x": nx / float(win.width),
                "y": ny / float(win.height)
            })
            EventLoop.post_dispatch_input("update", touch)
            EventLoop.post_dispatch_input("end", touch)

            if DEBUG:
                print(scroll.scroll_x, scroll.scroll_y)
                Clock.schedule_once(lambda *dt: sleep(0.5), 0)
                self.render(scroll)

            # check the scroll position
            self.assertAlmostEqual(scroll.scroll_x,
                                   0.0 if x == nx else 1.0,
                                   delta=dt)
            self.assertAlmostEqual(scroll.scroll_y,
                                   1.0 if y == ny else 0.0,
                                   delta=dt)

            # reset scroll to original state
            scroll.scroll_x = 0.0
            scroll.scroll_y = 1.0
Esempio n. 5
0
    def test_smooth_scroll_end(self):
        EventLoop.ensure_window()
        win = EventLoop.window
        grid = _TestGrid()
        scroll = ScrollView(smooth_scroll_end=10)

        assert scroll.smooth_scroll_end == 10
        scroll.add_widget(grid)

        # XXX this shouldn't be needed, but previous tests apparently
        # don't cleanup
        while win.children:
            win.remove_widget(win.children[0])

        win.add_widget(scroll)

        # get widgets ready
        EventLoop.idle()

        e = scroll.effect_y
        assert e.velocity == 0

        touch = UTMotionEvent(
            "unittest", next(touch_id), {
                "x": scroll.center_x / float(win.width),
                "y": scroll.center_y / float(win.height),
            })

        touch.profile.append('button')
        touch.button = 'scrollup'

        EventLoop.post_dispatch_input("begin", touch)
        # EventLoop.post_dispatch_input("update", touch)
        assert e.velocity == 10 * scroll.scroll_wheel_distance
        EventLoop.idle()
        assert 0 < e.velocity < 10 * scroll.scroll_wheel_distance
        EventLoop.post_dispatch_input("end", touch)
        EventLoop.idle()
        assert 0 < e.velocity < 10 * scroll.scroll_wheel_distance

        # wait for velocity to die off
        while e.velocity:
            EventLoop.idle()

        touch = UTMotionEvent(
            "unittest", next(touch_id), {
                "x": scroll.center_x / float(win.width),
                "y": scroll.center_y / float(win.height),
            })
        touch.profile.append('button')
        touch.button = 'scrolldown'

        EventLoop.post_dispatch_input("begin", touch)
        # EventLoop.post_dispatch_input("update", touch)
        assert e.velocity == -10 * scroll.scroll_wheel_distance
        EventLoop.idle()
        assert 0 > e.velocity > -10 * scroll.scroll_wheel_distance
        EventLoop.post_dispatch_input("end", touch)
        EventLoop.idle()
        assert 0 > e.velocity > -10 * scroll.scroll_wheel_distance
Esempio n. 6
0
    def test_vertical_scroll_doesnt_depend_on_lines_rendering(self):
        # TextInput.on_touch_down was checking the possibility to scroll_up
        # using the positions of the rendered lines' rects. These positions
        # don't change when the lines are skipped (e.g. during fast scroll
        # or ctrl+cursor_home) which lead to scroll freeze
        ti = self.make_scrollable_text_input()

        # move viewport to the first line
        ti.do_cursor_movement('cursor_home', control=True)
        self.advance_frames(1)
        assert ti._visible_lines_range == (0, 10)

        from kivy.base import EventLoop
        win = EventLoop.window

        # slowly scroll to the last line to render all lines at least once
        for _ in range(30):  # little overscroll is important for detection
            touch = UTMotionEvent(
                "unittest", next(touch_id), {
                    "x": ti.center_x / float(win.width),
                    "y": ti.center_y / float(win.height),
                })
            touch.profile.append('button')
            touch.button = 'scrollup'

            EventLoop.post_dispatch_input("begin", touch)
            EventLoop.post_dispatch_input("end", touch)
            self.advance_frames(1)
        assert ti._visible_lines_range == (20, 30)

        # jump to the first line again
        ti.do_cursor_movement('cursor_home', control=True)

        # temp fix: only change of cursor position triggers update as for now
        ti._trigger_update_graphics()

        self.advance_frames(1)
        assert ti._visible_lines_range == (0, 10)

        # scrolling up should work now
        touch = UTMotionEvent(
            "unittest", next(touch_id), {
                "x": ti.center_x / float(win.width),
                "y": ti.center_y / float(win.height),
            })
        touch.profile.append('button')
        touch.button = 'scrollup'
        EventLoop.post_dispatch_input("begin", touch)
        EventLoop.post_dispatch_input("end", touch)
        self.advance_frames(1)
        assert ti._visible_lines_range == (1, 11)