Builder.load_file("../venv/kv/sliding.kv")
class ExampleRV(RecycleView, ButtonBehavior):
def __init__(self, **kwargs):
super(ExampleRV, self).__init__(**kwargs)
pic1 = Image(source="../venv/icon/pics/a.png")
pic2 = Image(source="../venv/icon/pics/b.png")
pic3 = Image(source="../venv/icon/pics/c.png")
xr = [pic1,pic2,pic3]
self.data = [{'source': str(x)} for x in xr]
Sliding.kv
<ExampleRV>:
viewclass:'BoxLayout'
RecycleBoxLayout:
default_size: dp(160), None
default_size_hint: None, 1
size_hint_x: None
width: self.minimum_width
orientation: 'horizontal'
padding: 10
spacing: 30
canvas:
Color:
rgba: utils.get_color_from_hex("#fcfcfc")
Rectangle:
size: self.size
pos:self.pos
Note that i changed the viewclass to Image and app is working but its mentioned that :
[ERROR ] [Image ] Error reading file <kivy.uix.image.Image object at 0x000002DC166F73C8> [ERROR ] [Image ] Error reading file <kivy.uix.image.Image object at 0x000002DC166F7588> [ERROR ] [Image ] Error reading file <kivy.uix.image.Image object at 0x000002DC166F7748>how i can make Image RecycleView? any idead or help from your side appreciated.
Code example below. With a recycle view, the widgets get populated with data from a list of dicts. The dict keys are the attributes you want to set.
In the example below, the class Image and title is created. Note in the kv code how the attributes are applied to the class. In the Python code, the attributes are declared using kivy properties. The rv_data_list is a list of dicts. The keys, ‘source’ and ‘title’ correspond to the attributes in the viewclass.
I had 3 images handy so I created the images list, and use the 3 images over and over… you can of course ignore this little trick.
As you are going to be dynamically changing the rv_data_list from a database, you should make this a list property in your code.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
kv = """
<ImageAndTitle>:
Image:
source: root.source
Label:
text: root.title
TestBox:
orientation: 'vertical'
RecycleView:
id:rv
viewclass: 'ImageAndTitle'
data: root.rv_data_list
scroll_type: ['bars','content']
#bar_inactive_color: 1,1,1,1
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'
"""
class ImageAndTitle(BoxLayout):
title = StringProperty()
source = StringProperty()
images = ['1a.png', '2a.png', '3a.png'] # a little hack to use 3 images over and over...
class TestBox(BoxLayout):
rv_data_list = [{'source': images[n % 3], 'title': f'image title {n}'} for n in range(20)]
class RVTestApp(App):
def build(self):
return Builder.load_string(kv)
RVTestApp().run()
--
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/748d1784-7e1e-4c19-97a0-8a3693f7bc46%40googlegroups.com.