How to update RecycleView data

312 views
Skip to first unread message

Electronic Part

unread,
Dec 11, 2019, 1:44:47 AM12/11/19
to Kivy users support
Hello,

I want a RecycleView which is updating every time i change the its data. In other words(auto refresh), i want RecycleView update itself and show the new data. Please provide a me a working example to show me how it works.

Any help would be appreciated  

Andrei Sima

unread,
Dec 11, 2019, 4:51:13 AM12/11/19
to Kivy users support
Emmit and event after the data have been changed.
Make RecycleView, or other class at your convenience, listen to that and update the view from data.

This is how I would do it.

____________________
Andrei Sima


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0b2793fd-eb53-4a89-94ab-9d1f1935588e%40googlegroups.com.

Electronic Part

unread,
Dec 11, 2019, 5:04:15 AM12/11/19
to kivy-...@googlegroups.com
Could you please provide a code ? I don't know how to do that

Andrei Sima

unread,
Dec 11, 2019, 7:09:37 AM12/11/19
to Kivy users support
something like this will get you started:

class MyRecycleView(RecycleView):

    def __init__(self, uuid, **kwargs):
        super(MyRecycleView, self).__init__(**kwargs)
        self.register_event_type('on_obj_change')

    def on_object_change(self):
        # here you can update your recycled view from data
       


class MyClass(object):

    def update_object(self, index, val1, val2, val3):
        # here you can update your data
        # and after we emit a signal via dispatch

        MyRecycleView.dispatch('on_obj_change')


____________________
Andrei Sima


Andrei Sima

unread,
Dec 11, 2019, 7:10:45 AM12/11/19
to Kivy users support
    def __init__(self, uuid, **kwargs):

*    def __init__(self, **kwargs):

uuid was copy paste from another project.


Electronic Part

unread,
Dec 12, 2019, 12:27:00 AM12/12/19
to kivy-...@googlegroups.com
Thanks for your help. Could you give me a runable example? Sorry . I am new to kivy  

Andrei Sima

unread,
Dec 12, 2019, 2:48:31 AM12/12/19
to Kivy users support
Sorry, I do not have a runnable example that you can understand (new to Kivy).
It is using multiple files and is not new friendly.

You can take a look here:
https://github.com/andreisima/kivystore/blob/52a60b2929d9ba5a6d4acc9a930423aee6307e7c/store/managers/sensor_manager.py#L45
to see how I dispatch events on other classes/widgets.

If I have time today i will put together a small runnable example for you.


Electronic Part

unread,
Dec 12, 2019, 2:49:11 AM12/12/19
to kivy-...@googlegroups.com
I got this error: 
Exception: Missing default handler <on_obj_change> in <PatientListWindow>

Andrei Sima

unread,
Dec 12, 2019, 5:26:15 AM12/12/19
to Kivy users support
Here is a minimum running example.
I kept it as lightweight as I can so you can understand what is going on.
Dropped dispatch method since is bringing more complexity to the table.

main.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

Builder.load_file('main.kv')


class MainView(BoxLayout):

    data = {
        "sw1": {
            "uid": 1,
            "name": "sw1",
            "human_name": "Left Line",
            "other_param": "Some Random Str 1"
        },
        "sw2": {
            "uid": 2,
            "name": "sw2",
            "human_name": "Adiacent Line",
            "other_param": "Some Random Str 2"
        },
        "sw3": {
            "uid": 3,
            "name": "sw3",
            "human_name": "Centre Line",
            "other_param": "Some Random Str 3"
        },
        "sw4": {
            "uid": 4,
            "name": "sw4",
            "human_name": "Right Line",
            "other_param": "Some Random Str 4"
        },
        "sw5": {
            "uid": 5,
            "name": "sw5",
            "human_name": "Top Line",
            "other_param": "Some Random Str 5"
        }
    }

    def __init__(self, **kwargs):
        super(MainView, self).__init__(**kwargs)
        list_items = [k for k in self.data.keys()]
        self.table_data = []

        # this is done because i supply a dict of dicts and not a list of dicts
        for t in list_items:
            self.table_data.append(
                {
                    'label_text': self.data[t]['human_name'],
                    'sw_id': self.data[t]['uid'],
                    'label2_text': self.data[t]['other_param']
                }
            )
        self.ids.rv.data = self.table_data

    def on_obj_change(self, val):
        print(self.table_data[0]['label_text'])
        self.table_data[0]['label_text'] = val
        print(self.table_data[0]['label_text'])
        self.ids.rv.refresh_from_data()


class UpdateRVApp(App):

    def build(self):
        return MainView()


if __name__ == '__main__':
    UpdateRVApp().run()


main.kv:

<MainView>
    canvas.before:
        Color:
            rgba: 0.1, 0.5, 0.5, 1
        Rectangle:
            size: self.size
            pos: self.pos
    orientation: 'vertical'

    RecycleView:
        id: rv
        scroll_type: ['bars', 'content']
        scroll_wheel_distance: dp(100) # scrool step
        bar_width: dp(10)
        size_hint_y: .7
        viewclass: 'Row'

        RecycleBoxLayout:
            id: recycle_box_base
            default_size: None, dp(100)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
            spacing: dp(10)
    BoxLayout:
        size_hint_y: .3
        Button:
            text: 'Update'
            # this will update the firt row label text to val
            on_release: root.on_obj_change(val='Other Name')

<Row@BoxLayout>
    label_text: ''       # Init data replaced by RV data
    label2_text: ''     # Init data replaced by RV data
    sw_id: 1             # Init data replaced by RV data
    Label:
        text: str(root.sw_id)
    Label:
        text: str(root.label_text)
    Label:
        text: str(root.label2_text)
   


Electronic Part

unread,
Dec 18, 2019, 5:28:35 AM12/18/19
to kivy-...@googlegroups.com
Cloud you please how update by using an event? In other words,how to make an event and dispatch it and use it for updating  RecycleView ? Thanks for your help and your time as well

Elliot Garbus

unread,
Dec 18, 2019, 10:58:59 PM12/18/19
to Kivy users support
I have updated your code to update based on changes to the table_data.

table_data is changed to a ListProperty, the association of the table and the recycle view is now done in kv.

A timer fires every 3 seconds and adds an entry to the list, it is reflected on screen in the recycleview.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, NumericProperty
from kivy.clock import Clock



Builder.load_file('main.kv')


class MainView(BoxLayout):
    table_data = ListProperty([])  # make table_data a ListProperty
        # self.table_data = []  Now a listProperty

# this is done because i supply a dict of dicts and not a list of dicts
for t in list_items:
self.table_data.append(
{
'label_text': self.data[t]['human_name'],
'sw_id': self.data[t]['uid'],
'label2_text': self.data[t]['other_param']
}
)
        #self.ids.rv.data = self.table_data  Assignment moved to KV

def on_obj_change(self, val):
print(self.table_data[0]['label_text'])
self.table_data[0]['label_text'] = val
print(self.table_data[0]['label_text'])
self.ids.rv.refresh_from_data()


class UpdateRVApp(App):
    count = NumericProperty(6)  # you already have 5

def build(self):
return MainView()

def add_row(self, dt):
print('row added')
self.root.table_data.append({'label_text': 'human_name' + str(self.count),
'sw_id': 'uid' + str(self.count),
'label2_text': 'Something Else' + str(self.count)})
print(self.root.table_data)
self.count += 1

def on_start(self):
Clock.schedule_interval(self.add_row, 3)



if __name__ == '__main__':
UpdateRVApp().run()

----------------------------
<MainView>
canvas.before:
Color:
rgba: 0.1, 0.5, 0.5, 1
Rectangle:
size: self.size
pos: self.pos
orientation: 'vertical'

RecycleView:
id: rv
scroll_type: ['bars', 'content']
scroll_wheel_distance: dp(100) # scrool step
bar_width: dp(10)
size_hint_y: .7
viewclass: 'Row'
        data: root.table_data           # assignment moved from py to kv
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
main.kv
rvupdate.py

Electronic Part

unread,
Jan 12, 2020, 5:55:05 AM1/12/20
to kivy-...@googlegroups.com
Here is part of my code. I am getting data from sql server. It is not updating my  RecycleView  even by using stter and python property. It is workin when i rerun the code. Any idea what is going on?

class PatientListWindow(Screen,BoxLayout):
data_items = ListProperty([])

AP = ObjectProperty(None)

def __init__(self, **kwargs):
self.register_event_type('on_tabel_change')

self.data_items=self.get_users()

super(PatientListWindow, self).__init__(**kwargs)

def restore(self):
self.data_items = self.get_users()

def do_something(self, value):
# when do_something is called, the 'on_test' event will be
# dispatched with the value
self.dispatch('on_tabel_change', value)

def on_tabel_change(self,*args):
print ("I am dispatched", args)

def on_custom_callback(*args):
print('my on_custom_event is called with {}'.format(args))
@property
def update_tabel(self):
return '{}'.format( self.data_items )

@update_tabel.setter
def update_tabel(self,val):
self.data_items = val

@property
def update_tabel_data(self):
return '{}'.format(self.ids.patient_tabel.data )

@update_tabel_data.setter
def update_tabel_data(self,val):
self.ids.patient_tabel.data = [{'text': str(x)} for x in val]


def update_user(self):
self.update_tabel=self.get_users()
self.update_tabel_data=self.get_users()
print('New Data',self.data_items)
self.ids.patient_tabel.data= [{'text': str(x)} for x in self.data_items]
print(self.ids.patient_tabel.data)
self.ids.patient_tabel.refresh_from_data()

def get_users(self):
db = DataBase()
rows=db.get_patient_list()

class MyMainApp(App):



def build(self):

return kv

my_app = MyMainApp()
if __name__ == "__main__":
# LS=strt_thread()
# LS.start()
# LS.join()
my_app = MyMainApp()
    my_app.run()


and kivy side

BoxLayout:
orientation: "vertical"
GridLayout:
height: 25
cols: 7
size_hint: .8, None
pos_hint: {"x":0.3, "y":.6} if root.AP.is_language_english() else{"x":0.1, "y":.6}
height: 25
cols: 1
PatientLabel:
color: 0,0,0,1
canvas.before:
Color:
rgba: .7, .7, .7, 1
Rectangle:
pos: self.pos
size: self.size
text:get_display(arabic_reshaper.reshape('List of Patients')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('لیست بیماران')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' قائمة المرضى '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

GridLayout:
#size_hint: .7, None
size_hint_y: None
#pos_hint: {"x":0.6, "y":0.3}
height: 25
cols: 7
size_hint: .8, None
#size_hint_y: None
#size_hint_x: .5
pos_hint: {"x":0.3, "y":.6} if root.AP.is_language_english() else{"x":0.1, "y":.6}
height: 25
cols: 8

PatientLabel:
text:get_display(arabic_reshaper.reshape('File Number')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('شماره پرونده')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' رقم الملف '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

PatientLabel:
text:get_display(arabic_reshaper.reshape('Name')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('نام')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' اسم '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

PatientLabel:
text:get_display(arabic_reshaper.reshape('Last Name')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('نام خانوادگی')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' الكنية '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large


PatientLabel:
text:get_display(arabic_reshaper.reshape("father's name")) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape(' نام پدر ')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' اسم الاب '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

PatientLabel:
text:get_display(arabic_reshaper.reshape('National Number')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('کد ملی')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' الرقم الوطني '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

PatientLabel:
text:get_display(arabic_reshaper.reshape('Insurance Type')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('نوع بیمه')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' نوع التأمين '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

PatientLabel:
text:get_display(arabic_reshaper.reshape('Insurance Number')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('شماره بیمه')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' رقم التأمين '))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large
PatientLabel:
text:get_display(arabic_reshaper.reshape('Description')) if root.AP.is_language_english() else get_display(arabic_reshaper.reshape('توضیحات')) if root.AP.is_language_persian() else get_display(arabic_reshaper.reshape(' الوصف'))
font_size:small if root.AP.is_font_small() else medium if root.AP.is_font_medium() else large

BoxLayout:
#size: 300,50
#pos: 0,root.height*.5
pos_hint: {"x":0.3, "y":.6} if root.AP.is_language_english() else{"x":0.1, "y":.6}
size_hint: .8, 0.6
RecycleView:
id:patient_tabel
viewclass: 'SelectableButton'
data: [{'text': str(x)} for x in root.data_items]
#data:[]
SelectableRecycleGridLayout:
cols: 8
default_size: None, dp(26)
default_size_hint: .6, None
size_hint_x: 1
height: self.minimum_height
orientation: 'vertical'
multiselect: True
                touch_multiselect: True  

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6371f85e-d827-4215-8f0a-5df0ccf65f24%40googlegroups.com.

Elliot Garbus

unread,
Jan 12, 2020, 9:00:06 AM1/12/20
to kivy-...@googlegroups.com

You have a ListProperty data items that is storing a list of strings.

You are using a list comprehension in KV to convert the list of strings into a list of dictionaries.

My suggestion is to create a new ListProperty rv_data_items that maintains the list of dictionaries. 

In KV change:

data: [{'text': str(x)} for x in root.data_items]]

To:

       data: root.rv_data_items

Electronic Part

unread,
Jan 14, 2020, 12:31:19 AM1/14/20
to kivy-...@googlegroups.com
Can you please explain me a little bit more? How make  rv_data_items in my code?

Elliot Garbus

unread,
Jan 14, 2020, 1:14:55 PM1/14/20
to kivy-...@googlegroups.com

Here is an example, I hope this helps:

 

from kivy.app import App
from kivy.lang import Builder
from kivy.properties import ListProperty
from kivy.uix.boxlayout import BoxLayout

kv =
"""

<TestButton@Button>
    on_release: print(f'Button: {self.text} pressed')
TestBox:
    orientation: 'vertical'
    RecycleView:
        viewclass: 'TestButton'
        data: root.rv_data_list
        scroll_type: ['bars','content']
        bar_width: dp(20)
        do_scroll_x: False
        RecycleBoxLayout:
            default_size: None, dp(56)

            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
            orientation: 'vertical'
    BoxLayout:
        size_hint_y: None
        height: dp(48)
        Button:
            text: 'Add pets'
            on_release: root.add_pets()
        Button:
            text: 'Remove pets'
            on_release: root.remove_pets()
"""


class TestBox(BoxLayout):
    rv_data_list = ListProperty([{
'text': 'A' + str(n)} for n in range(4)] +
                                [{
'text': 'B' + str(n)} for n in range(4)])

    pets = [
'dog', 'cat', 'hamster', 'guinea pig', 'rabbit', 'parrot', 'snake']

   
def list_to_rv_data(self, str_data):
       
#  convert a list of strings to a list of dictionaries for the rv list
       
return [{'text': s} for s in str_data]

   
def rv_data_to_list(self, rv_data):
       
# convert a list of  rv_data to a list of strings
       
return [list(item.values())[0] for item in rv_data]

   
def add_pets(self):
       
self.rv_data_list = self.rv_data_list + self.list_to_rv_data(self.pets)

   
def remove_pets(self):
        entries =
self.rv_data_to_list(self.rv_data_list)
        no_pets = [d
for d in entries if d not in self.pets]
       
self.rv_data_list = self.list_to_rv_data(no_pets)


class RVTestApp(App):
   
def build(self):
       
return Builder.load_string(kv)


RVTestApp().run()

Electronic Part

unread,
Jan 19, 2020, 1:51:40 AM1/19/20
to kivy-...@googlegroups.com
I got following error when i tried to use recycle view id in python side. Any help would be appreciated  

.kv
BoxLayout:

scroll_type: ['bars', 'content']
scroll_wheel_distance: dp(100) # scrool step
    RecycleView:
id:patient_tabel
viewclass: 'SelectableButton'
data: [{'text': str(x)} for x in root.data_items]
        #data: root.data_items

#data:[]
SelectableRecycleGridLayout:
cols: 8
default_size: None, dp(26)
default_size_hint: .6, None
size_hint_x: 1
height: self.minimum_height
orientation: 'vertical'
multiselect: True
touch_multiselect: True

python side
class PatientListWindow(Screen,BoxLayout):
data_items = ListProperty([])
    patient_tabel=ObjectProperty(None)


def __init__(self, **kwargs):
self.table_data = []
self.data_items = self.get_users()
self.table_data=[{'text': str(x)} for x in self.data_items]

super(PatientListWindow, self).__init__(**kwargs)

and the error is
     self.ids.patient_tabel.data = []
   File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "D:/code/final_designe/persian_fona_design.py", line 1772, in <module>
     with open(current_folder_path+"/persian_fona.kv", encoding='utf-8') as f:  # Note the name of the .kv
 FileNotFoundError: [Errno 2] No such file or directory: 'D:\\code/persian_fona.kv'

Elliot Garbus

unread,
Jan 19, 2020, 10:55:35 AM1/19/20
to kivy-...@googlegroups.com

As you know a runnable example would make it easier to help, but here are a few things that could be a problem:

 

Find the code that is causeing the problem:

self.ids.patient_tabel.data = []  Is this is Python or kv?  I’m assuming this is in your Python file, see below:

 

class PatientListWindow(Screen,BoxLayout):
    data_items = ListProperty([])
    patient_tabel=ObjectProperty(
None)

you are declaring parient_tabel an object property in Python. It appears you want to create an easier to access copy of the id patient_tabel in Recyleview.  If that is the case, do something like the following:

 

class PatientListWindow(Screen,BoxLayout):
    data_items = ListProperty([])
    # patient_tabel=ObjectProperty(
None)  Move the creation to KV

 


BoxLayout:

    patient_tabel: patient_tabel

   # ^ *** this creates an object property self.patient initiatlized to the id.  This should go at the top of <PatientListWindow>


    scroll_type: ['bars', 'content']
    scroll_wheel_distance: dp(100) # scrool step
    RecycleView:
        id:patient_tabel

A waring I see ‘patient_tabel’ and ‘data_table’

 

In the later exception:

open(current_folder_path+"/persian_fona.kv", encoding='utf-8')

 

use os.path.join to combine paths:  https://docs.python.org/3/library/os.path.html#os.path.join

 

from os.path import join

open(join(current_folder_path, “persian_fona.kv"), encoding='utf-8')

Electronic Part

unread,
Jan 20, 2020, 12:22:31 AM1/20/20
to kivy-...@googlegroups.com
Hello,
I want to use this code . the body of my code is different but same concept. i tried initialize data on my python side and then update labels with new strings. My problem is the error i gave you. I can not get access to patient_tabel like the attach example.


test6.py
test6.kv

Electronic Part

unread,
Jan 20, 2020, 12:24:04 AM1/20/20
to kivy-...@googlegroups.com
By the way, too complicated to make a runable example since i got data from database 

Elliot Garbus

unread,
Jan 20, 2020, 12:41:34 AM1/20/20
to kivy-...@googlegroups.com

If you’d like more help, mock up some data and manually put it in the dictionary, and create a smaller example.  There is not enough info here for me to provide more help.

Electronic Part

unread,
Jan 20, 2020, 12:43:15 AM1/20/20
to kivy-...@googlegroups.com

Electronic Part

unread,
Jan 21, 2020, 2:08:52 AM1/21/20
to kivy-...@googlegroups.com
Hello,

I made an example. I put an example of my data in this code. I think you can understand what i want to do by looking at this simple example 
test6.py
test6.kv

Electronic Part

unread,
Jan 21, 2020, 3:04:14 AM1/21/20
to kivy-...@googlegroups.com
Here is a working one
test6.py
test6.kv

Electronic Part

unread,
Jan 21, 2020, 5:28:29 AM1/21/20
to kivy-...@googlegroups.com
I can not access to patient_table which is id for recycle view. i added  patient_table: patient_table to top of the my PatientListWindows but still got this error
    self.ids.patient_tabel.data = []
   File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'
That is the error can accrue for all ids not only this case. Could you please tell me how to solve it. if you need i can send you my PatientListWindows to be both on the same page



Electronic Part

unread,
Jan 21, 2020, 6:18:47 AM1/21/20
to kivy-...@googlegroups.com
I think problem explained  here
https://www.reddit.com/r/kivy/comments/588tx7/how_can_i_use_init_for_screen_ids/ 
the solution does not work for me or i need add or change something. Please tell me how to do that?

Electronic Part

unread,
Jan 21, 2020, 6:59:40 AM1/21/20
to kivy-...@googlegroups.com
I solved the problem. Now, i will work on the main issue

Elliot Garbus

unread,
Jan 21, 2020, 7:43:01 AM1/21/20
to kivy-...@googlegroups.com

Glad to hear you got that working!

Electronic Part

unread,
Jan 21, 2020, 8:10:33 AM1/21/20
to kivy-...@googlegroups.com
Still updating my recycle view data exist. Hope i solve it.  


Electronic Part

unread,
Jan 22, 2020, 2:13:22 AM1/22/20
to kivy-...@googlegroups.com
Hello, Here i tried to make an example. As you see, I want to update my data and show new data(updated data)
test12.py
test12.kv

Electronic Part

unread,
Jan 22, 2020, 2:27:10 AM1/22/20
to kivy-...@googlegroups.com
Sorry please check this one not previous version
test12.py
test12.kv

Elliot Garbus

unread,
Jan 22, 2020, 8:54:05 AM1/22/20
to Kivy users support

There are a number of problems here, but the fundamental problem is that you have not defined a viewclass that is capable of displaying your data.

The viewclass is applied to the data in the data list to create a set of widgets that get ‘recycled’.

 

For your data I created to following simplified viewclass:

<DataRecordButtons@BoxLayout>:
filenumber: 'filenumber' # These are all initial vales that will not be used
name: 'name'
lastname: 'lastname'
fathername: 'fathername'
nationalid: '123'
insurancetype: 'insurancetype'
insurancenumber: 'ins num'
description: 'useful?'
Button:
text: root.filenumber
Button:
text: root.name
Button:
text: root.lastname
Button:
text: root.fathername
Button:
text: root.nationalid
Button:
text: root.nationalid
Button:
text: root.insurancetype
Button:
text: root.insurancenumber
Button:
text: root.description

This creates a horizontal list of buttons that display the text from the data record.


Also for your consideration:  I don't know why your are using multiple inheritance on MainView.  This is a screen that contains a BoxLayout.  It would be more straight forward to move the Boxlayout into the screen, rather than inheriting from it.  The MainView 'is a' screen that 'has a' Boxlayout. 

test12.kv
test12.py

Electronic Part

unread,
Jan 27, 2020, 5:04:35 AM1/27/20
to kivy-...@googlegroups.com
Thanks for you answer. That was absolutely helpful. just one problem in your code. Why do i have 9 columns instead of 8?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Electronic Part

unread,
Jan 27, 2020, 5:09:19 AM1/27/20
to kivy-...@googlegroups.com
Actually, nationalid column has been shown twice

Electronic Part

unread,
Jan 27, 2020, 6:06:47 AM1/27/20
to kivy-...@googlegroups.com
Got it. Just comment these two lines. 
#Button:
# text: root.nationalid

Electronic Part

unread,
Jan 27, 2020, 7:18:16 AM1/27/20
to kivy-...@googlegroups.com
Now my problem is how to update patient list. To be clear please attend to my example. Assume i have two columns. i want to add another column and edit one of them and also delete another one. So, i want to change patient list with new data that i am getting from database. How does it work? Here is extension  of your code. just in on_object_change i want to update the table with new data.


 self.data_items = self.get_users()
self.table_data=[]
for i in range(int(len(self.data_items)/8)):
temp={'filenumber': str(self.data_items[(i*8)]),
'name': str(self.data_items[(i*8)+1]),
'lastname': str(self.data_items[(i*8)+2]),
'fathername': str(self.data_items[(i*8)+3]),
'nationalid': str(self.data_items[(i*8)+4]),
'insurancetype': str(self.data_items[(i*8)+5]),
'insurancenumber':str(self.data_items[(i*8)+6]),
'description': str(self.data_items[(i*8)+7]) }
self.table_data.append(temp)
temp = {}
#self.table_data=[{'filenumber': '10','name': 'Henry', 'lastname': 'ln12', 'fathername': '12',
# 'nationalid': '123','insurancetype': '123456', 'insurancenumber': '12', 'description': 'None'},
# {'filenumber': '20', 'name': 'Elctrnc', 'lastname': 'Part', 'fathername': 'Dad',
# 'nationalid': 'USA ', 'insurancetype': 'Exp ', 'insurancenumber': '77', 'description': '$$$'}]

Problem is when i press update button new data will add to the old ones

Electronic Part

unread,
Jan 27, 2020, 8:03:22 AM1/27/20
to kivy-...@googlegroups.com
I got it. Just 
self.data_items=[]

self.data_items = self.get_users()
self.table_data=[]
for i in range(int(len(self.data_items)/8)):
temp={'filenumber': str(self.data_items[(i*8)]),
'name': str(self.data_items[(i*8)+1]),
'lastname': str(self.data_items[(i*8)+2]),
'fathername': str(self.data_items[(i*8)+3]),
'nationalid': str(self.data_items[(i*8)+4]),
'insurancetype': str(self.data_items[(i*8)+5]),
'insurancenumber':str(self.data_items[(i*8)+6]),
'description': str(self.data_items[(i*8)+7]) }
self.table_data.append(temp)

Elliot Garbus

unread,
Jan 27, 2020, 8:08:20 AM1/27/20
to kivy-...@googlegroups.com

Electronic Part

unread,
Jan 27, 2020, 8:22:49 AM1/27/20
to kivy-...@googlegroups.com
Just as my last question in this part, How i can add scrollview to patient list window. I am sure i will have a lot of patients in future. I need to scroll up and down  

Elliot Garbus

unread,
Jan 27, 2020, 8:41:42 AM1/27/20
to kivy-...@googlegroups.com

Good news, your recycle view already scrolls.

 

Try replacing get_users() with:

def get_users(self):
   
return [str(i) for i in range((800))]

 

to test it.

Electronic Part

unread,
Jan 28, 2020, 7:29:21 AM1/28/20
to kivy-...@googlegroups.com
Thanks.  it is better to keep it simple. just need to open a pop up when i click on buttons. I don't know. Could you please let me know how to do that?

Elliot Garbus

unread,
Jan 28, 2020, 10:14:33 AM1/28/20
to Kivy users support
You can add a popup the same as you add an action to any button.
In the attached example I use the Factory to instance the PopUp, and customize the popup instance using key word arguments.



TestBox(BoxLayout):
    rv_data_list = ListProperty([{
'text': 'A' + str(n)} <span style="font
test12.kv
test12.py

Electronic Part

unread,
Feb 1, 2020, 7:54:58 AM2/1/20
to kivy-...@googlegroups.com
I really appreciate your help. You answers are prefect. Could you please tell me  how change title. I know how to do that by using title:'My Title' but what about when the title be in different language. I used this command 

font_name:'fonts/DejaVuSans.ttf'
title: str(arabic_reshaper.reshape('Patient Info')) #if root.is_language_english() else str(get_display(arabic_reshaper.reshape('ویرایش کنید')))

Thanks


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Elliot Garbus

unread,
Feb 1, 2020, 9:51:59 AM2/1/20
to kivy-...@googlegroups.com

The font for the title in a PopUp is title_font.  Then pass in the title text, or hard code it here.

 
<DataRecordDialog>:                                   # The definition of the popup
   
size_hint: .7, .7
   
title_font:'fonts/DejaVuSans.ttf'
   
BoxLayout:
       
orientation: 'vertical'
       
Label:
           
text: root.name
       
Label:
            
text: root.msg
       
Button:
           
size_hint_y: None
           
height: dp(48)
           
text:'OK'
           
on_release: root.dismiss()

 

I imagine you are using the selected font all over your code.  You might be able to simplify things by redefining Label to have a different font, this is another way to change the font in the Popup.

 

<Label>:

    -font_name: 'fonts/DejaVuSans.ttf'

 

This will globally redefine he default font.  Buttons, Popups, Labels all get their text properties from Label,

Electronic Part

unread,
Feb 2, 2020, 1:01:14 AM2/2/20
to kivy-...@googlegroups.com
Awesome. That works. Could you please let me know if there is any way i can position the title (something like pos_hint for title only) ? 

Electronic Part

unread,
Feb 2, 2020, 1:13:42 AM2/2/20
to kivy-...@googlegroups.com
I don't know if i can change background color for popup . I did some search and understand it is possible to change background image . Is it possible to do that?

Elliot Garbus

unread,
Feb 2, 2020, 7:42:27 AM2/2/20
to kivy-...@googlegroups.com

Elliot Garbus

unread,
Feb 2, 2020, 8:11:59 AM2/2/20
to kivy-...@googlegroups.com

You can change the image. 

You can find the default image located at:

kivy/kivy/tools/theming/defaulttheme/modalview-background.png

 

copy the image, bring it into a photo/image editor, change as designed and save.

Then set background: ‘name_of_edited_image.png’

Electronic Part

unread,
Feb 2, 2020, 8:17:45 AM2/2/20
to kivy-...@googlegroups.com

Electronic Part

unread,
Feb 10, 2020, 1:38:11 AM2/10/20
to kivy-...@googlegroups.com
Could you let me know how add vertical scroll bar to  recycle view?

Electronic Part

unread,
Feb 10, 2020, 2:06:30 AM2/10/20
to kivy-...@googlegroups.com
No need to answer. Here is what i found. Just add this to  recycle view
bar_width: 10
#bar_color: 1, 0, 0, 1 # red
bar_color: 0, 0, 1, 1 # red
bar_inactive_color: 0, 0, 1, 1 # blue
effect_cls: "ScrollEffect"
scroll_type: ['bars']
Reply all
Reply to author
Forward
0 new messages