5
$\begingroup$

Note

I have tried to be deliberately detailed in this question: please scroll down to the bottom to see the summary of my question. Thank you.

Background

The UILayout template template_ID_preview gives a nice selection popup with a preview image for each element.

enter image description here

I am interested in tapping into this feature to improve display of selectors, but I can't find how to remove the "extra" features (outlined in red).


Here is some python code to show what I mean (MVCE in parts).

Minimal:

l.template_ID_preview(properties_texture.context_tex_datablock(context),
                      "active_texture",
                      new="texture.new",
                      rows=2, 
                      cols=5)

Complete:

import bpy
import properties_texture

def texture_selector(self, context):
    l = self.layout
    l.template_ID_preview(properties_texture.context_tex_datablock(context),
                          "active_texture",
                          new="texture.new",
                          rows=2,
                          cols=5)

def register():
    bpy.types.TEXTURE_PT_context_texture.append(texture_selector)


def unregister():
    bpy.types.TEXTURE_PT_context_texture.remove(texture_selector)

if __name__ == "__main__":
    register()

Verifiable:

To use this, right click on the active texture button, then select "edit source" to see it in the text editor.

enter image description here

Replace this line:

layout.template_ID(idblock, "active_texture", new="texture.new")

With this:

layout.template_ID_preview(idblock, "active_texture", new="texture.new", rows=2, cols=3)

Then hit Run Script. This will change the UI from this...

enter image description here

...to this:

enter image description here


The new argument is optional and, if left out, it removes the "+", but there is no such arg for the user count, fake user toggle, and unlink (although unlink is optional, its absence does not remove the associated "x" button).


Question

How can the preview be shown (highlighted in green in the first picture) while removing the rest? Would this only work with custom properties instead of, for example, active texture selection like I show in the screenshot?

I want the template to look more like this screenshot that doesn't have any other settings below the selector:

enter image description here

enter image description here

Please note that this is not the same as the preview for materials, textures, etc. that looks like this:

enter image description here

This is the same sort of thing that the sculpt brush selector tool uses to show a large preview for the brushes.


I don't know what version of Blender this was put in (I notice a lot of new ones since the last time I went through them), but there is now a "ui_previews_dynamic_enum" template in the text editor that demonstrates how to use an icon preview enum like this. It doesn't, of course, talk about linking it with built-in collections such as a materials list as @aliasguru mentions.

$\endgroup$
3
  • 1
    $\begingroup$ Suggest using template_preview $\endgroup$
    – batFINGER
    Dec 21, 2016 at 9:08
  • $\begingroup$ @batFINGER That is the built-in preview for material, textures, lamps, etc. I want a "selector" with the large preview. I have added another picture to my question to illustrate this. $\endgroup$
    – JakeD
    Dec 21, 2016 at 13:04
  • 3
    $\begingroup$ That type of customisation is a bit more involved. It is basically done using template_icon_view instead of template_ID_preview. But you need to indeed generate custom properties to hold the preview collection. Haven't tested if it could be combined somehow with existing collections, but honestly I doubt it. template_icon_view is really designed to show image content which is located somewhere on a file storage, like in the case of Pro_Lighting_Skies and the like. $\endgroup$
    – aliasguru
    Dec 21, 2016 at 13:52

1 Answer 1

2
$\begingroup$

There is a difference between "ID" properties and other runtime ones.
An ID property has the basic structure for Blender to save it in the file. Materials, textures, etc, are IDs (they are part of the .blend file), the HDR previews from that add-on are not (they are in a directory in the disk, and previewed in Blender, but they are not saved in a .blend, unless you actually load one into a texture which is then saved).

Firstly, you should understand if you are presenting ID or non-ID properties. If they are just temporary properties, template_icon_view should be used instead of template_ID_preview.

If you really want ID properties, then the selector comes with some more features for management of the data that is saved (rename, unlink, see the users). At the moment this is not optional, except the '+' to make a new one.
If you want just a preview with no management options, but also with no selector, there istemplate_preview. The buttons on the side are optional.

The template_icon_view was introduced along with the matcaps for Blender 2.66, but the ability to have custom previews from files is from 2.75. https://wiki.blender.org/index.php/User:Brita/Proposals/UIPreviews

$\endgroup$
1
  • $\begingroup$ I've also successfully implemented a file version in the add-on that I needed this for here. The code is released under the GPL 3 license, so it can be integrated into other projects as well. $\endgroup$
    – JakeD
    Apr 17, 2017 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .