import kivy
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.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
one = ['a1','b1','c1','d1','e1','f1','g1','h1','i1','j1','k1','l1','m1','a11','b11','c11','d11','e11','f11','g11','h11','i11','j11','k11','l11','m11','a11','b11','c111','d111','e111','f111','g111','h111','i111','j111','k111','l111','m111']
three = ['n3','o3','p3','q3','r3','s3','t3','u3','v3','w3','x3','y3','z3','n3','o3','p3','q3','r3','s3','t3','u3','v3','w3','x3','y3','z3','n33','o33','p33','q33','r33','s33','t33','u33','v33','w33','x33','y33','z33']
five = ['a5','b5','c5','d5','e5','f5','g5','h5','i5','j5','k5','l5','m5','a5','b5','c5','d5','e5','f5','g5','h5','i5','j5','k5','l5','m5','a5','b5','c5','d5','e5','f5','g5','h5','i5','j5','k5','l5','m5']
ten = ['n10','o10','p10','q10','r10','s10','t10','u10','v10','w10','x10','y10','z10','n10','o10','p10','q10','r10','s10','t10','u10','v10','w10','x10','y10','z10','n10','o10','p10','q10','r10','s10','t10','u10','v10','w10','x10','y10','z10']
fiftn = ['a15','b15','c15','d15','e15','f15','g15','h15','i15','j15','k15','l15','m15','a15','b15','c15','d15','e15','f15','g15','h15','i15','j15','k15','l15','m15','a15','b15','c15','d15','e15','f15','g15','h15','i15','j15','k15','l15','m15']
twnty = ['n20','o20','p20','q20','r20','s20','t20','u20','v20','w20','x20','y20','z20','n20','o20','p20','q20','r20','s20','t20','u20','v20','w20','x20','y20','z20','n20','o20','p20','q20','r20','s20','t20','u20','v20','w20','x20','y20','z20']
frames = ['1','3','5','10','15','20']
nframes = [one, three, five, ten, fiftn, twnty]
Builder.load_string('''
<SelectableLabel>:
canvas.before:
Color:
rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0.517, 0.705, 1)
Rectangle:
pos: self.pos
size: self.size
id: selectable_label
pos: self.pos
size: self.size
# size_hint: None, None
# size: self.texture_size[1], self.texture_size[1]
<RV>:
gr: gr
viewclass: 'SelectableLabel'
effect_cls: "ScrollEffect"
scroll_type: ['bars']
bar_width: 10
bar_color: 0, 0.517, 0.705, 1 # red
bar_inactive_color: 0, 0, 1, 1 # blue
SelectableRecycleGridlayout:
id: gr
cols: 2
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 SelectableRecycleGridlayout(FocusBehavior, LayoutSelectionBehavior, RecycleGridLayout):
''' Adds selection and focus behaviour to the view. '''
class SelectableLabel(RecycleDataViewBehavior, Label):
''' Add selection support to the Label '''
index = None
selected = BooleanProperty(False)
selectable = BooleanProperty(True)
def refresh_view_attrs(self, rv, index, data):
''' Catch and handle the view changes '''
self.index = index
return super(SelectableLabel, self).refresh_view_attrs(rv, index, data)
def on_touch_down(self, touch):
''' Add selection on touch down '''
if super(SelectableLabel, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos) and self.selectable:
return self.parent.select_with_touch(self.index, touch)
def apply_selection(self, rv, index, is_selected):
''' Respond to the selection of items in the view. '''
self.selected = is_selected
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
global frames, nframes
#Dynamic data selection
mother_tf = dict(zip(frames, nframes))
selectable_tf = ['20' ,'5','10','3','1']
selectable_tf.sort(key=int, reverse=False)
self.ids.gr.cols = len(selectable_tf)
select_list = {}
for tf in selectable_tf:
select_list[tf] = mother_tf[tf]
x = [sorted(list(item),reverse=False) for item in list(select_list.values())]
grouped = list(zip(*x))
self.data = [{'text': val, 'id': val} for item in grouped for val in item