Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.recycleview import RecycleView
  4. from kivy.uix.recycleview.views import RecycleDataViewBehavior
  5. from kivy.uix.label import Label
  6. from kivy.properties import BooleanProperty
  7. from kivy.uix.recycleboxlayout import RecycleBoxLayout
  8. from kivy.uix.behaviors import FocusBehavior
  9. from kivy.uix.recycleview.layout import LayoutSelectionBehavior
  10. from kivy.uix.boxlayout import BoxLayout
  11.  
  12. Builder.load_string('''
  13. <Box>:
  14. orientation: 'horizontal'
  15. Image:
  16. source: 'icon.png'
  17. size: self.texture_size
  18. Label:
  19. text: #How do I access the text from RV.data?
  20.  
  21. <SelectableLabel>:
  22. # Draw a background to indicate selection
  23. canvas.before:
  24. Color:
  25. rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
  26. Rectangle:
  27. pos: self.pos
  28. size: self.size
  29. <RV>:
  30. viewclass: 'Box'
  31. SelectableRecycleBoxLayout:
  32. default_size: None, dp(56)
  33. default_size_hint: 1, None
  34. size_hint_y: None
  35. height: self.minimum_height
  36. orientation: 'vertical'
  37. multiselect: True
  38. touch_multiselect: True
  39. ''')
  40.  
  41. class Box(BoxLayout):
  42. pass
  43.  
  44. class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
  45. RecycleBoxLayout):
  46. ''' Adds selection and focus behaviour to the view. '''
  47.  
  48. class RV(RecycleView):
  49. def __init__(self, **kwargs):
  50. super(RV, self).__init__(**kwargs)
  51. self.data = [{'text1': str(x)} for x in range(100)]
  52.  
  53.  
  54. class TestApp(App):
  55. def build(self):
  56. return RV()
  57.  
  58. if __name__ == '__main__':
  59. TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement