daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 17th, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.boxlayout import BoxLayout
  4. from kivy.uix.floatlayout import FloatLayout
  5. from kivy.properties import ObjectProperty
  6. from kivy.uix.label import Label
  7. from kivy.uix.recycleview import RecycleView
  8. from kivy.clock import Clock
  9. from kivy.uix.button import Button
  10.  
  11. kv = """
  12. <Row>:
  13.     id: row
  14.     canvas.before:
  15.         Color:
  16.             rgba: 0.5, 0.5, 0.5, 1
  17.         Rectangle:
  18.             size: self.size
  19.             pos: self.pos
  20. <Test>:
  21.     canvas:
  22.         Color:
  23.             rgba: 0.3, 0.3, 0.3, 1
  24.         Rectangle:
  25.             size: self.size
  26.             pos: self.pos
  27.     orientation: 'vertical'
  28.     RecycleView:
  29.         id: rvlist
  30.         scroll_type: ['bars', 'content']
  31.         scroll_wheel_distance: dp(114)
  32.         bar_width: dp(10)
  33.         viewclass: 'Row'
  34.         RecycleBoxLayout:
  35.             default_size: None, dp(56)
  36.             default_size_hint: 1, None
  37.             size_hint_y: None
  38.             height: self.minimum_height
  39.             orientation: 'vertical'
  40.             spacing: dp(2)
  41.  
  42. <TestRoot>:
  43.     Test:
  44.         pos_hint: {"center_x": .5, "center_y": .5}
  45. """
  46.  
  47. Builder.load_string(kv)
  48.  
  49. class Row(BoxLayout):
  50.     row_content = ObjectProperty()
  51.  
  52.  
  53.     def __init__(self,**kwargs):
  54.         super(Row, self).__init__(**kwargs)
  55.         Clock.schedule_once(self.finish_init,0)
  56.  
  57.        
  58.     def finish_init(self, dt):
  59.         for elt in self.row_content:
  60.             self.add_widget(Label(text = elt))
  61.         self.bind(row_content = self.update_row)
  62.  
  63.  
  64.     def update_row(self, *args):
  65.         self.clear_widgets()
  66.         for elt in args[1]:
  67.             self.add_widget(Label(text = elt))
  68.  
  69.     def on_touch_down(self, touch):
  70.         super(Row, self).on_touch_down(touch)
  71.  
  72.         if self.collide_point(*touch.pos):
  73.             print(self.row_content)
  74.             print(touch)
  75.             print(App.get_running_app().root_window.mouse_pos)
  76.             print(touch.spos)
  77.             spos_button = Button(text="SPOS", pos_hint={"x": touch.spos[0], "y": touch.spos[1]}, size_hint=(.1, .1))
  78.             pos_button = Button(text="POS", pos=touch.pos, size_hint=(None, None))
  79.             window_pos_button = Button(text="Window POS", pos=App.get_running_app().root_window.mouse_pos, size_hint=(None, None))
  80.             App.get_running_app().root.add_widget(spos_button)
  81.             App.get_running_app().root.add_widget(pos_button)
  82.             App.get_running_app().root.add_widget(window_pos_button)
  83.        
  84. class Test(BoxLayout):
  85.    
  86.     def __init__(self,**kwargs):
  87.         super(Test, self).__init__(**kwargs)
  88.         Clock.schedule_once(self.do_new_data)
  89.  
  90.     def do_new_data(self, *args):
  91.         self.ids.rvlist.data = [{'row_content': [str(i) for i in range(5)]} for x in range(15)]
  92.  
  93.  
  94. class TestRoot(FloatLayout):
  95.     pass
  96.  
  97. class TestApp(App):
  98.     def build(self):
  99.         return TestRoot()
  100.  
  101. if __name__ == '__main__':
  102.     TestApp().run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top