0
$\begingroup$

I know a UIList class is not a big deal to write, but for multiple reasons, I'd like to write one class and use it for handling two PropertyCollection lists. So if I have a class for a UIList like this, can I use it more than once on the same panel for different data in each location in the layout where it's used? If not, what prevents that?

class MY_UL_CustomList(UIList):
    """Demo UIList."""

    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        custom_icon = 'FILE'

        if self.layout_type in {'DEFAULT', 'COMPACT'}:
            layout.label(text = str(index) + '  ' + item.name, icon = custom_icon)
        elif self.layout_type in {'GRID'}:
            layout.alignment = 'CENTER'
            layout.label(text==item.name, icon = custom_icon)
$\endgroup$
5
  • $\begingroup$ AFAIK there is nothing preventing use of more than one list in a panel. Related blender.stackexchange.com/questions/158440/… $\endgroup$
    – batFINGER
    Apr 7 at 4:51
  • $\begingroup$ @batFINGER: I thought of including that one as a link, but since he used to separate classes, I thought I should ask - in case there are non-obvious implications. I tested it, but thought it best to ask in case I was out of my depth. My problem, now, is that I've realized I'm not sure how to test just what data list it's using. I see the 3rd from last parameter, when called, is a string with the name of the list, but in the routine, it's scene, as in bpy.context.scene.my_list and I can't see how to be sure it's not using my_list instead of my_2nd_list. I may be posting a question about that. $\endgroup$
    – Tango
    Apr 7 at 5:07
  • $\begingroup$ Strike that - found out how to ID which data list I'm working with from within draw_item(). While I can't really get the actual list, I can check the class of the item I'm drawing and use that (as long as both UILists are using different types of data). $\endgroup$
    – Tango
    Apr 7 at 5:20
  • $\begingroup$ My gut feel you are going about this A about T. See docs.blender.org/api/current/… esp notes re list_id $\endgroup$
    – batFINGER
    Apr 7 at 5:34
  • $\begingroup$ @batFINGER That's a help, but how do I access the info passed to the UIList in template_list() from within the UIList class I create? I see list_id as a parameter, but I tried to see if it was in the class by accessing it, but it doesn't seem to be in the class. $\endgroup$
    – Tango
    Apr 7 at 6:45

Your Answer

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

Browse other questions tagged or ask your own question.