Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import kivy
- kivy.require('1.0.8')
- from kivy.app import App
- from kivy.uix.scrollview import ScrollView
- from kivy.uix.stacklayout import StackLayout
- from kivy.uix.label import Label
- from kivy.lang import Builder
- from kivy.uix.floatlayout import FloatLayout
- Builder.load_file('scrollview.kv')
- class MyFloatLayout(FloatLayout):
- def __init__(self, name, *args, **kwargs):
- super(MyFloatLayout, self).__init__(*args, **kwargs)
- self.name = name
- # TESTPOINT FLOAT
- def on_touch_down(self, touch):
- # super(MyFloatLayout, self).on_touch_down(touch)
- # print "MyFloatLayout: touched!", self.name
- class MyLabel(Label):
- def __init__(self, *args, **kwargs):
- super(MyLabel, self).__init__(*args, **kwargs)
- # TESTPOINT LABEL
- def on_touch_down(self,touch):
- print "MyLabel: touched!", self.text
- class MyScrollView(ScrollView):
- def __init__(self, name, *args, **kwargs):
- super(MyScrollView, self).__init__(*args, **kwargs)
- self.name = name
- # TESTPOINT SCROLL
- def on_touch_down(self, touch):
- # super(MyScrollView, self).on_touch_down(touch)
- # print "MyScrollView: touched!", self.name
- # return True
- class MyStackLayout(StackLayout):
- def __init__(self, name, *args, **kwargs):
- super(MyStackLayout, self).__init__(*args, **kwargs)
- self.name = name
- # TESTPOINT STACK
- def on_touch_down(self, touch):
- # super(MyStackLayout, self).on_touch_down(touch)
- # print "MyStackLayout: touched!", self.name
- class ScrollViewApp(App):
- def build(self):
- root = MyFloatLayout("root")
- for j in [[1,1], [2,1], [1,2], [2,2]]:
- # create a default grid layout with custom width/height. Find the specs in the .kv file
- mystacklayout = MyStackLayout(str(j))
- # 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 view)
- mystacklayout.bind(minimum_height=mystacklayout.setter('height'))
- label_group = str(j)
- # add button into that grid
- for i in range(5):
- a_label = MyLabel(text=label_group + "_lbl: " + str(i))
- mystacklayout.add_widget(a_label)
- # create a scroll view, with a size < size of the grid
- x = float(j[0])**2 * 80
- y = float(j[1])**2 * 80
- myscrollview = MyScrollView(str(j), pos=(x,y)) # Specs also in the .kv
- myscrollview.add_widget(mystacklayout)
- root.add_widget(myscrollview)
- odd_label = MyLabel(text="Oddball")
- root.add_widget(odd_label)
- return root
- if __name__ == '__main__':
- ScrollViewApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement