2
$\begingroup$

I've created an own UIList for an addon. It's just used to display some properties of Action (as that one doesn't have a properties panel in the Action Editor), so it must get populated with actions and not with user input.

It actually must be updated manually, with a button I added below it. Althought this already works, I think it's not nice, so I was wondering if there was any way to update the list automatically.

I tried to override the draw method and override it there, but then the List (and the panel in general) isn't displayed at all.

def draw(self, context):
        # LIST UPDATE
        bpy.types.UIList.draw(self, context)

Here's my UIList implementation:

class MyUIList(bpy.types.UIList): 
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):

        custom_icon = 'OBJECT_DATAMODE'

        if self.layout_type in {'DEFAULT', 'COMPACT'}:
            layout.label(bpy.data.actions[item.Index].name, icon = custom_icon)

        elif self.layout_type in {'GRID'}:
            layout.alignment = 'CENTER'
            layout.label("", icon = custom_icon)

Thanks in advance!

$\endgroup$
  • 3
    $\begingroup$ Good thread here blenderartists.org/forum/…. Also surely your line 7 above could be layout.label(item.name) as bpy.data and "actions" are passed to the template_list layout. $\endgroup$ – batFINGER Sep 9 '15 at 6:17
  • 1
    $\begingroup$ @batFINGER Why not converting this into an answer? Might be also interesting: blender.stackexchange.com/a/14203/3710 $\endgroup$ – p2or Sep 9 '15 at 10:46
1
$\begingroup$

Thanks to @batFINGER and @poor comments, I've been able to do this, so I'm gonna post it here for if someone has the same problem.

The trick had to be done in the panel draw method, when drawing the UIList:

row.template_list("MyList", "", bpy.data, "actions", context.scene, "myListIndex")

The third and fourth arguments are the place from were the list items will be get. I was using a custom list here (that just pointed to an action), so that was redundant. The fifth and sixth arguments are where the selected item index is stored, which in my case is in the Scene properties.

Thanks for your help!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.