I have created a custom template list in my Blender add-on panel: row.template_list("COMFYUI_UL_OutputList", "", addon_prefs, "outputs_collection", addon_prefs, "selected_output_index", type=addon_prefs.outputs_layout)
Then I have created a custom UIList to customize the display of my items in the template list. I would like to use 2 different layouts. One list layout (DEFAULT) and one gallery layout (GRID) to display the images contained in my collection. My DEFAULT layout works well, but the GRID layout only display tiny small items. I am not able to resize the items in the list so that they look bigger.
Here is the DEFAULT layout:
Here is the bad GRID layout:
Here is the code of my UIList. Is there a solution to have a nicer grid layout with larger images?
"""Custom list of outputs displayed in the output panel."""
import os
import bpy
class COMFYUI_UL_OutputList(bpy.types.UIList):
"""Custom list of outputs displayed in the output panel."""
def draw_item(self, context, layout, data, item, icon, active_data, selected_output_index):
"""Draw each list item."""
# Get outputs folder
addon_prefs = context.preferences.addons["comfyui_blender"].preferences
outputs_folder = str(addon_prefs.outputs_folder)
# Load generated image in the data block if it does not exist
if item.filename not in bpy.data.images:
full_path = os.path.join(outputs_folder, item.name)
if os.path.exists(full_path):
bpy.data.images.load(full_path, check_existing=True)
else:
# If the file does not exist anymore, remove it from the outputs collection
# To avoid error when trying to display the image
addon_prefs.outputs_collection.remove(selected_output_index)
self.report({'INFO'}, f"Removed output from collection: {item.filename}")
# Prepare image
if item.filename in bpy.data.images:
bpy.data.images[item.filename].preview_ensure()
# Get icon based on output type
if item.type == "image":
icon_default = "FILE_IMAGE"
icon_grid = bpy.data.images[item.filename].preview.icon_id
elif item.type == "3d":
icon_default = "MESH_DATA"
if self.layout_type in {'DEFAULT', 'COMPACT'}:
row = layout.row(align=True)
row.label(text=item.filename, icon=icon_default)
# Image editor button
image_editor = row.operator("comfy.open_image_editor", text="", icon="IMAGE", emboss=False)
image_editor.filename = item.filename
# Delete output button
delete_output = row.operator("comfy.delete_output", text="", icon="TRASH", emboss=False)
delete_output.filename = item.filename
delete_output.filepath = item.name
delete_output.type = item.type
elif self.layout_type in {'GRID'}:
box = layout.box()
box.template_icon(icon_value=icon_grid, scale=5.0)
box.label(text=item.filename)
def register():
"""Register the panel."""
bpy.utils.register_class(COMFYUI_UL_OutputList)
def unregister():
"""Unregister the panel."""
bpy.utils.unregister_class(COMFYUI_UL_OutputList)
[UPDATE] I found that if I enlarge the width of my panel the image gets resized and I can see... It's not solving the issue per say, I would still need to ensure a minimal image size so that it remains visible regardless of the panel width



bpy.data.images[item.filename].preview.icon_size = [128,128]. $\endgroup$AttributeError: Writing to ID classes in this context is not allowed: blender_00032_.png, Image datablock, error setting ImagePreview.icon_size$\endgroup$