Last active
January 7, 2022 21:05
-
-
Save tshirtman/adfbd51151b9f25397930c1299bf1ac6 to your computer and use it in GitHub Desktop.
This file contains 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
from kivy.lang import Builder | |
from kivy.app import App | |
from kivy.properties import ListProperty, NumericProperty | |
KV = ''' | |
#:import RGBA kivy.utils.rgba | |
<Row@BoxLayout>: | |
text: '' | |
rv_key: 0 | |
CheckBox: | |
active: root.rv_key in app.current_selection | |
on_release: app.select_row(root.rv_key, self.active) | |
# on_active: app.select_row(root.rv_key, self.active) | |
Label: | |
text: root.text | |
FloatLayout: | |
RecycleView: | |
size_hint: .8, .8 | |
pos_hint: {'center': (.5, .5)} | |
data: app.data | |
viewclass: 'Row' | |
canvas.before: | |
Color: | |
rgba: RGBA('#212121') | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
RecycleBoxLayout: | |
orientation: 'vertical' | |
size: self.minimum_size | |
size_hint_y: None | |
default_size_hint: 1, None | |
default_size: 0, 50 | |
BoxLayout: | |
size_hint: 1, None | |
height: self.minimum_height | |
Button: | |
text: 'select all' | |
size_hint_y: None | |
on_release: app.current_selection = [i for i, _ in enumerate(app.data)] | |
Button: | |
text: 'unselect all' | |
size_hint_y: None | |
on_release: app.current_selection = [] | |
''' | |
class TestApp(App): | |
data = ListProperty() | |
current_selection = ListProperty([]) | |
def build(self): | |
self.data = [ | |
dict( | |
text='key {}'.format(i), | |
rv_key=i, | |
) | |
for i in range(100) | |
] | |
return Builder.load_string(KV) | |
def select_row(self, rv_key, active): | |
if active and rv_key not in self.current_selection: | |
self.current_selection.append(rv_key) | |
elif not active and rv_key in self.current_selection: | |
self.current_selection.remove(rv_key) | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment