Sounds like quite a tall order, especially since you say you don’t want it in bpy.data.images and you do want it in the GUI.
If you want to show an image in the viewport there is a way but bpy.data.images loads the images and you pass opengl the bindcode to draw the texture. And that, AFAIK can only be done in the viewport.
I am eagerly awaiting for someone to prove me wrong.
i would open it into bpy.data.images
when i change the shown image into another one, i would delete the old one.
it would help if i can access the selected value of a prop_search when click to open the selection-window (before i select the next one)
this way i could get the image-name of the previous image and i can remove this from bpy.data.images.
i tried it with a variable containing the image-name (this works, but not when loading an other file with the addon installed)
I tried something kind of similar once. You may need to assume the role of garbage collector to some extent
bpy.types.ID has user_clear and users
make sure there are no other users before you call del.
Also there is this UILayout.template_ID_preview – I haven’t found decent examples for much of the template_*'s … it sounds very intriguingly like exactly what is wanted.
You can overlay any space with opengl and draw a texture on top for instance. But as there aren’t custom widgets, nor the required offsets and dimensions (Panel x, y, width, height, visible area), you can’t really integrate it like a native widget.
There’s the preview template widget, which can show a bpy.data.images datablock, but you can’t really control how the image is drawn.
In a context where there’s an ‘image’ context member, you can use context_pointer_set() in layout code to overwrite it (with the reference to the image you want to show). This is basically what allows datablocks to be pinned in the properties editor.
I’m actually not sure how to use it right, and I believe it is limited to a very few use cases, where another script or maybe hard layout code picks up the referenced context pointer. To show a preview image, you can just use the direct reference.
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
row = layout.row()
# NOTE: works only at 1:1 panel zoom!
split = row.split(110 / (context.region.width - 45))
split.template_preview(bpy.data.textures['.hidden'], show_buttons=False)
def register():
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
i tried it again and again, but it does not update the image
i searched for other usages of template_preview in this forum to test it and i found this: bpy.context.active_object.active_material
this shows the selected material
i still have the problem, if i change material color or select an other object with an other material it does not change the preview in my panel.
why does it not update the image (or is this a bug)?
it shows me the material of the selected object in two different places of the blender ui.
the one is under view_3d >> tools and the another one under properties >> window >> object
when i add two objects and give each of them an other material, the preview under properties >> window >> object updates,
but not the preview under view_3d >> tools
what is wrong, is there the code wrong, is this intended or is this a bug in blender (i use the newest version).
(i tried it with my addon to move it to properties >> window > object and that worked, but i want it to have it under view_3d >> tools)