0

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.

Noob Cat
  • 1,222
  • 3
  • 20
  • 61
  • 1
    Where is it slow? Have you timed it. Is it slow re the dynamic enum items? Big fan of pathlib over os.path can 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:27
  • would weigh up having a "refresh" button to reload if need be. For example the text editor if saved source is touched. over the need to constantly keep an eye on the folder. The logic above also suggests an update method on my_previews_dir property. 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

0 Answers0