Advertisement
Guest User

Untitled

a guest
May 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. import kivy
  2. kivy.require('1.0.8')
  3.  
  4. from kivy.app import App
  5. from kivy.uix.scrollview import ScrollView
  6. from kivy.uix.stacklayout import StackLayout
  7. from kivy.uix.label import Label
  8. from kivy.lang import Builder
  9. from kivy.uix.floatlayout import FloatLayout
  10.  
  11. Builder.load_file('scrollview.kv')
  12.  
  13. class MyFloatLayout(FloatLayout):
  14.  
  15. def __init__(self, name, *args, **kwargs):
  16. super(MyFloatLayout, self).__init__(*args, **kwargs)
  17. self.name = name
  18.  
  19. # TESTPOINT FLOAT
  20. def on_touch_down(self, touch):
  21. # super(MyFloatLayout, self).on_touch_down(touch)
  22. # print "MyFloatLayout: touched!", self.name
  23.  
  24. class MyLabel(Label):
  25. def __init__(self, *args, **kwargs):
  26. super(MyLabel, self).__init__(*args, **kwargs)
  27.  
  28. # TESTPOINT LABEL
  29. def on_touch_down(self,touch):
  30. print "MyLabel: touched!", self.text
  31.  
  32. class MyScrollView(ScrollView):
  33.  
  34. def __init__(self, name, *args, **kwargs):
  35. super(MyScrollView, self).__init__(*args, **kwargs)
  36. self.name = name
  37.  
  38. # TESTPOINT SCROLL
  39. def on_touch_down(self, touch):
  40. # super(MyScrollView, self).on_touch_down(touch)
  41. # print "MyScrollView: touched!", self.name
  42. # return True
  43.  
  44. class MyStackLayout(StackLayout):
  45.  
  46. def __init__(self, name, *args, **kwargs):
  47. super(MyStackLayout, self).__init__(*args, **kwargs)
  48. self.name = name
  49.  
  50. # TESTPOINT STACK
  51. def on_touch_down(self, touch):
  52. # super(MyStackLayout, self).on_touch_down(touch)
  53. # print "MyStackLayout: touched!", self.name
  54.  
  55.  
  56. class ScrollViewApp(App):
  57.  
  58. def build(self):
  59. root = MyFloatLayout("root")
  60. for j in [[1,1], [2,1], [1,2], [2,2]]:
  61. # create a default grid layout with custom width/height. Find the specs in the .kv file
  62. mystacklayout = MyStackLayout(str(j))
  63.  
  64. # when we add children to the grid layout, its size doesn't change at
  65. # all. we need to ensure that the height will be the minimum required to
  66. # contain all the childs. (otherwise, we'll child outside the bounding
  67. # box of the view)
  68. mystacklayout.bind(minimum_height=mystacklayout.setter('height'))
  69.  
  70. label_group = str(j)
  71. # add button into that grid
  72. for i in range(5):
  73. a_label = MyLabel(text=label_group + "_lbl: " + str(i))
  74. mystacklayout.add_widget(a_label)
  75. # create a scroll view, with a size < size of the grid
  76. x = float(j[0])**2 * 80
  77. y = float(j[1])**2 * 80
  78. myscrollview = MyScrollView(str(j), pos=(x,y)) # Specs also in the .kv
  79. myscrollview.add_widget(mystacklayout)
  80.  
  81. root.add_widget(myscrollview)
  82.  
  83. odd_label = MyLabel(text="Oddball")
  84. root.add_widget(odd_label)
  85. return root
  86.  
  87. if __name__ == '__main__':
  88.  
  89. ScrollViewApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement