Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.recycleview import RecycleView
- from kivy.uix.recycleview.views import RecycleDataViewBehavior
- from kivy.uix.label import Label
- from kivy.properties import BooleanProperty
- from kivy.uix.recycleboxlayout import RecycleBoxLayout
- from kivy.uix.behaviors import FocusBehavior
- from kivy.uix.recycleview.layout import LayoutSelectionBehavior
- from kivy.uix.boxlayout import BoxLayout
- Builder.load_string('''
- <Box>:
- orientation: 'horizontal'
- Image:
- source: 'icon.png'
- size: self.texture_size
- Label:
- text: #How do I access the text from RV.data?
- <SelectableLabel>:
- # Draw a background to indicate selection
- canvas.before:
- Color:
- rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
- Rectangle:
- pos: self.pos
- size: self.size
- <RV>:
- viewclass: 'Box'
- SelectableRecycleBoxLayout:
- default_size: None, dp(56)
- default_size_hint: 1, None
- size_hint_y: None
- height: self.minimum_height
- orientation: 'vertical'
- multiselect: True
- touch_multiselect: True
- ''')
- class Box(BoxLayout):
- pass
- class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
- RecycleBoxLayout):
- ''' Adds selection and focus behaviour to the view. '''
- class RV(RecycleView):
- def __init__(self, **kwargs):
- super(RV, self).__init__(**kwargs)
- self.data = [{'text1': str(x)} for x in range(100)]
- class TestApp(App):
- def build(self):
- return RV()
- if __name__ == '__main__':
- TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement