Adding/Removing columns in RecycleView

70 views
Skip to first unread message
Assigned to stash....@gmail.com by me

Jude Obande

unread,
May 29, 2019, 9:04:05 AM5/29/19
to Kivy users support
Hello Everyone,

I'm trying to display a lot of data in my app while giving the user the option to select what data to display

                                                                  Data to be displayed is in this format :

          Date                       |                  A                       |                     B                      |                       C                  
 From: xxxxxx To: xxxxxx | col 1  | col 2  | col 3  | col 4|    col 1 | col 2 | col 3 | col 4  | col 1 | col 2 | col 3 | col 4  |
   23-02-1987                   | xx      | xx      | xx      | xx    |   xx      | xx     | xx     | xx      | xx     | xx     | xx     | xx      | 
   22-02-1987                   | xx      | xx      | xx      | xx    |   xx      | xx     | xx     | xx      | xx     | xx     | xx     | xx      | 
   21-02-1987                   | xx      | xx      | xx      | xx    |   xx      | xx     | xx     | xx      | xx     | xx     | xx     | xx      |
....

The options to display/hide will be: From, To | A, B, C | col 1, col 2, col 3, col 4 and then user can scroll through 
the data displayed subsequently

Idea 1:
Making INDEPENDENT recycleviews for each column to be displayed

Problem: How to make them all scroll TOGETHER

Idea 2:
Including ALL the data in ONE recycleview and having the options to add/remove data

Problem: Recycleview only accepts the data so I can't hide/remove columns based on the options I want

Progress so far:

I tried to work on the sub-columns  [col1, col 2, col 3, col 4] section to make it dynamic with some success, 
but I can't seem to think of a way to extend this logic to the main columns [A,B,C] and include the date part 

See code:
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



Any idea's help is much appreciated. Thanks guys
Message has been deleted

Jude Obande

unread,
May 31, 2019, 4:21:05 PM5/31/19
to Kivy users support
Still hoping for help on this from anyone

Jude Obande

unread,
Jun 1, 2019, 7:02:24 PM6/1/19
to Kivy users support
problem solved
Reply all
Reply to author
Forward
0 new messages