ScrollView and Scatter objects...

319 views
Skip to first unread message

Ryan

unread,
May 2, 2012, 1:43:50 AM5/2/12
to kivy-...@googlegroups.com
Hi,

I was wondering if someone could tell me why adding Scatter objects to a ScrollView object results in the selected object being moved to the end of the list when long clicking on a Scatter object.

To help illustrate what I'm talking about, I've modified the scrollview demo application.
Button objects are now contained in Scatter objects, and the Scatter widgets are added to the ScrollView.

To see the problem, just long click on the any of the buttons... the selected button jumps to the end of the list!


import kivy
kivy.require('1.0.8')

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.scatter import Scatter
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout


class ScrollViewApp(App):

    def build(self):

        # create a default grid layout with custom width/height
        layout = GridLayout(cols=1, spacing=10, size_hint=(None, None),
                            width=500)

        # when we add children to the grid layout, its size doesn't change at
        # all. we need to ensure that the height will be the minimum required to
        # contain all the childs. (otherwise, we'll child outside the bounding
        # box of the childs)
        layout.bind(minimum_height=layout.setter('height'))

        # add button into that grid
        for i in range(30):
            btn = Button(text=str(i), size=(480, 40),
                         size_hint=(None, None))
            scatter = Scatter(size=btn.size, size_hint=(None, None))
            scatter.add_widget(btn)
            layout.add_widget(scatter)

        # create a scroll view, with a size < size of the grid
        root = ScrollView(size_hint=(None, None))
        root.size = (480, 320)
        root.center = Window.center
        root.add_widget(layout)

        return root

if __name__ == '__main__':

    ScrollViewApp().run()

Mathieu Virbel

unread,
May 2, 2012, 7:39:38 AM5/2/12
to kivy-...@googlegroups.com
Hi,

The scatter is a very special object.
By default, it have 'auto_bring_to_front' boolean to True, and then when you touch it, it will remove/readd itself to it's parent.
Swith to False, and you should have what you want.

Mathieu
Reply all
Reply to author
Forward
0 new messages