I think this depends a lot on the size of the images you are trying to upload, but I notice that the compilation of the previews in the popup always seems to be slow.
The compilation of the icons in the pcoll was done with a function similar to this:
def enum_previews_from_directory_items(self, context):
"""EnumProperty callback"""
enum_items = []
if context is None:
return enum_items
wm = context.window_manager
directory = wm.my_previews_dir
# Get the preview collection (defined in register func).
pcoll = preview_collections["main"]
if directory == pcoll.my_previews_dir:
return pcoll.my_previews
print("Scanning directory: %s" % directory)
if directory and os.path.exists(directory):
# Scan the directory for png files
image_paths = []
for fn in os.listdir(directory):
if fn.lower().endswith(".png"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# generates a thumbnail preview for a file.
filepath = os.path.join(directory, name)
icon = pcoll.get(name)
if not icon:
thumb = pcoll.load(name, filepath, 'IMAGE')
else:
thumb = pcoll[name]
enum_items.append((name, name, "", thumb.icon_id, i))
pcoll.my_previews = enum_items
pcoll.my_previews_dir = directory
return pcoll.my_previews
I was wondering if there is anything that can do the trick.
pathliboveros.pathcan for instance glob the extension. https://blender.stackexchange.com/questions/204268/simple-python-script-to-stitch-images-into-movie-failing-with-incorrect-context/204418#204418 vs https://blender.stackexchange.com/questions/135690/load-images-with-substring-in-filename-from-a-given-path – batFINGER Jul 01 '21 at 08:27my_previews_dirproperty. IIRC have answered re an icons module that uses a folder keyed dictionary (instead of "main" above) to do much the same... – batFINGER Jul 01 '21 at 08:47