picibucor picibucor - 17 days ago 5
Python Question

scroll_to() behaviour

I'm using the scroll_to function in my kv-file. It scrolls properly as I wanted, but if I turn the mouse-wheel it will jump back where it was, before the scroll_to().

Any ideas, how could I improve my code?

snipplet of my kv-file:

MyButton:
text: 'jump'
on_release: scroll_content.scroll_to(jump_id_2, padding=0, animate=True)

ScrollView:
id: scroll_content
blah, blah, blah.......

# values of the devices
GridLayout:

BoxLayout:
id: jump_id_0
blah, blah, blah.......

BoxLayout:
id: jump_id_1
blah, blah, blah.......

BoxLayout:
id: jump_id_2
blah, blah, blah.......


Thank you for your help....

Answer

I managed to find a "solution": basically you set the scroll_type on "content", and click somewhere on the screen...

MyButton:
    text: 'jump'
    on_release: scroll_content.scroll_to(jump_id_2, padding=0, animate=True); app.click(200)

ScrollView:
    id: scroll_content
    scroll_type: ['content']
    blah, blah, blah.......

    # values of the devices
    GridLayout:

        BoxLayout:
            id: jump_id_0
            blah, blah, blah.......

        BoxLayout:
            id: jump_id_1
            blah, blah, blah.......

        BoxLayout:
            id: jump_id_2
            blah, blah, blah.......

where the click function is:

def click(self, shift):
"""Click on the screen."""
        pt = POINT()
        ctypes.windll.user32.GetCursorPos(ctypes.byref(pt))
        ctypes.windll.user32.SetCursorPos(pt.x, pt.y + shift)
        ctypes.windll.user32.mouse_event(2, pt.x, pt.y + shift, 0, 0)
        ctypes.windll.user32.mouse_event(4, pt.x, pt.y + shift, 0, 0)
        ctypes.windll.user32.SetCursorPos(pt.x, pt.y)
Comments