recycleview and new pics

23 views
Skip to first unread message

Radosław Głębicki

unread,
May 20, 2026, 2:07:09 PM (14 days ago) May 20
to Kivy users support
Hello.
Problem. Recycleview with pictures. Pic can be broken and one is for tests. My class for images has __init__ with bind each element and send for check to another function:

class clMyImage(Image):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# From net: Bind the image size to our error handler
self.bind(size = self.m_handleBroken)
return None
def m_handleBroken(self, inst, value):
# From net: value will be None if the image fails to load
if self.texture is None:
inst
.source = f"{gsPath2App}pic/brokenPic.jpg" # change src to `broken`
return None

Just to explain strange thing: size and texture. I found that solution (texture and texture) in internet but bind to texture doesn't work but with size and check for texture is working fine.
But this works only at begin. Each element is pass __init__ and I can catch broken pic. After adding new pics and change dict and pass as new for:

koRecView.data = gdFILES['lData']

It's showing (try to show) original broken pic. Is not going by __init__.

I try:

koRecView.refresh_from_data()

Is not going again by __init__ of my image class.
I try remove recycleview and add again. Is not helping. Maybe reload kv lang?

class clMyGridLayout(BL):
Builder.load_string(f'''<clMyGridLayout>:
orientation: "vertical"
RecycleView:
canvas.before:
Color:
rgba: 0,0,0,1  #{glBckColor}
Rectangle:
pos: self.pos
size: self.size
bar_color: {glSlidCol}
bar_inactive_color: {glInSlCol}
bar_width: {gnWinS / 50}
viewclass: 'clMyImage'
data: {gdFILES['lData']}
RecycleGridLayout:                 # this layout is in var: koRecGridLay
id: grid
cols: {str(gnCol)}
default_size: None, {gnWinW / gnCol * 0.75}
default_size_hint: 1, None
spacing: 10,10
padding: {gtThumbPadd}
size_hint_y: None
height: self.minimum_height
orientation: "lr-tb"''')

I am using PIL for exif so probably I can use PIL to verify images before I pass to recycleview, but this take extra time and if I can use kivy for this is I think better.

Radek Glebicki

ElliotG

unread,
May 20, 2026, 2:34:14 PM (14 days ago) May 20
to Kivy users support
Using init() is not gong to work because in a RecycleView, only the number of widgets required to be visible in the RecycleView are created, they are then recycled.  
You could use on_source, so the when the source changes you inspect the texture (perhaps after a clock).   

If you can share a minimal, runnable example I'd be happy to take a closer look.

Radosław Głębicki

unread,
May 20, 2026, 4:21:15 PM (14 days ago) May 20
to Kivy users support
So there is no control over "recycling" places in grid in RecycleView in the moment when pic is going back on place? In which moment kivy analyse pictures data (if is ok) and place in the recycleview? Checking cells in the grid? Image object is with not correct texture? I can't get info about this?

Radek Glebicki

I will try to do: minimal, runnable example but is a lot about cutting and completing.

Radosław Głębicki

unread,
May 20, 2026, 4:29:28 PM (14 days ago) May 20
to Kivy users support
When I am scrolling and broken pic is coming to the view this happen:

[WARNING] [Image       ] Unable to load image </storage/emulated/0/Pic/Plik tekstowy.png>
[ERROR  ] [Image       ] Error loading </storage/emulated/0/Pic/Plik tekstowy.png>
[WARNING] [Image       ] Unable to load image </storage/emulated/0/Pic/Plik tekstowy.png>
[ERROR  ] [Image       ] Error loading </storage/emulated/0/Pic/Plik tekstowy.png>
[WARNING] [Image       ] Unable to load image </storage/emulated/0/Pic/Plik tekstowy.png>
[ERROR  ] [Image       ] Error loading </storage/emulated/0/Pic/Plik tekstowy.png>

How to catch this moment and change to "pic with symbol of broken"?

Radek Glebicki

Radosław Głębicki

unread,
May 20, 2026, 4:41:44 PM (14 days ago) May 20
to Kivy users support
Ok. I think I have solution. I am using `Clock` to just after filling `recycleview` I am analysing objects in the RecycleGrid (children) and swap `source` to "pic with symbol of broken". That way scroll is working fine. Now I try to do that same after extending list with pictures.

Radek Glebicki

PS: I have to say this:
"only the number of widgets required to be visible in the RecycleView are created, they are then recycled"
give my to understanding how recycle is working. Thanks.

PS2: Maybe you can point me where this happen in kivy:
[WARNING] [Image       ] Unable to load image </storage/emulated/0/Pic/Plik tekstowy.png>
[ERROR  ] [Image       ] Error loading </storage/emulated/0/Pic/Plik tekstowy.png>

Radosław Głębicki

unread,
May 20, 2026, 9:49:46 PM (13 days ago) May 20
to Kivy users support
Solution which is working I think fine is:

class clMyImage(Image):
def on_texture(self, *d):
Clock.schedule_once(f_swapBrokenPic,.01)                  # without delay doesn't work
return None
# [Rest of class .......]

and outside:

def f_swapBrokenPic(*d):
for oElm in koRecGridLay.children:                                             # cells of grid used for recycle
if oElm.texture == None:                                                       # texture doesn't exist, broken pic
oElm.source = gsPath2broken + gsBrokenPic         # swap to pic with symbol of broken
return None

Scroll works, adding pics also works even with extra broken pic. I think solved.

Radek Glebicki
Reply all
Reply to author
Forward
0 new messages