Created
May 28, 2016 05:47
-
-
Save GreyGnome/93671a4fd926137653bd07f74587ca2b to your computer and use it in GitHub Desktop.
For evaluating event propagation: Test of FloatLayout with 4 ScrollViews added to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment