2.66 template_list blues...(default draw_item code)?

Hi All,

With the official release of 2.66 I am looking into fixing my AddOns that use template_list.

Initially the fix was simple. All you had to do was paste “UI_UL_list”,"" in front of the original parameters and everything worked. However, with the official 2.66 release this no longer work.

row.template_list("UI_UL_list","",ob, "meshfoot_List", ob, "meshfoot_List_Index",4,5) 

I get a blank area, presumably because “UI_UL_List” does not exist in the official release. I thought there was going to be an automatic old style draw mechanism left in place?

This seems to leaves us with only one option. We have to write more code just to get back where we were yesterday.

I have looked at the API change docs here.
http://www.blender.org/documentation/blender_python_api_2_65_10/bpy.types.UIList.html

Does anyone have any default draw_item code that will just make the template_list work like it did in 2.65?

Thanks

It looks like something like this will work.


# ------- Template List Draw Routines -------
class ATOMS_265_UI_Template_List(bpy.types.UIList):
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        # draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code.
        if self.layout_type in {'DEFAULT', 'COMPACT'}:
            layout.label(text=item.name, translate=False, icon_value=icon)
        # 'GRID' layout type should be as compact as possible (typically a single icon!).
        elif self.layout_type in {'GRID'}:
            layout.alignment = 'CENTER'
            layout.label(text="", icon_value=icon)

But you have to remember to add the class name to the register/unregister for it to become available for template_list.


def register():
    # Panel
    bpy.utils.register_class(ATOMS_265_UI_Template_List)

def unregister():
    # Panel
    bpy.utils.unregister_class(ATOMS_265_UI_Template_List)

Then you can use it in a draw() like so…

row.template_list("ATOMS_265_UI_Template_List","meshfoot_entry",ob, "meshfoot_List", ob, "meshfoot_List_Index",4,5) 

I get a blank area, presumably because “UI_UL_List” does not exist in the official release.

I’m pretty sure that isn’t the case! It’s rather that you use it improperly.

All you had to do was paste “UI_UL_list”,"" in front of the original parameters and everything worked.

No, you gotta put “UI_UL_list”, “some_id_value” - without ID things will get messed up 'cause as soon as the default UI_UL_list is used multiple times in the same area, Blender won’t be able to distinguish between them and will therefore always chose the first.

Note that UI_UL_list works for collections which use the default name-StringProperty; these names will show as layout.labels. If you wanna show e.g. checkboxes of a BoolProperty, you need to use a custom class derived from UIList, and draw the checkbox items like layout.prop(item, “name_of_bool_prop”) in draw_item.

bpy.utils.register_class(ATOMS_265_UI_Template_List)

You don’t if you register all your classes via bpy.utils.register_module(name)

row.template_list(“ATOMS_265_UI_Template_List”,“meshfoot_entry”,ob, “meshfoot_List”, ob, “meshfoot_List_Index”,4,5)

Since you use a custom class here with a specific (unique) name - ATOMS_265_UI_Template_List - you don’t have to pass an id (meshfoot_entry)