I'm currently trying to create sort of a "navigation" UI list with the parent/child concept like the outliner or any classic folder navigation. But I'm stuck at the part where I need my items to be dynamically hidden.

the problem is that this kind (if close: return) of code won't actually hide the drawing of an element, as the element will still be drawn

class EXAMPLE_UL_folder_navigation(bpy.types.UIList):

    def draw_item(self, context, layout, data, item, icon, active_data, active_propname):

        if not item:

        wm = bpy.context.window_manager
        if (item.parent!="") and not wm.scatter5.folder_navigation[item.parent].is_open:
            #Element will still be drawn, in an empty row
        #draw the row 
        row = layout.row(align=True)    


        row.prop(item,"is_open",icon="TRIA_DOWN" if item.is_open else "TRIA_RIGHT", icon_only=True, emboss=False)


enter image description here

In my code I try to re-create folders structure, here's a sample of how I get the structure

Mapping = []

def recur_dir_mapping(path, level=0, parent=""):

    global Mapping

        "level": level if (level==0) else level-1,

    for p in os.listdir(path): #order of list generated by listdir is important..
        p = os.path.join(path,p)

        if os.path.isfile(p):


        elif os.path.isdir(p):
            recur_dir_mapping(p, level=level+1, parent=path)

    return None 

and then how I create my UI list

        for i in range(len(collection_prop)):

        recur_dir_mapping( mypath )
        global Mapping

        for element in Mapping:

            #library navigation = every folder & files 
            e = collection_prop.add()
            e.name      = element["name"]
            e.path      = element["path"]
            e.parent    = element["parent"]
            e.is_folder = element["is_folder"]

        #Reset Mapping
        Mapping = []

But this is the easy part, the hard part is to truly "hide" elements dynamically, such as suggested in the gif above similar to the outliner

enter image description here

I'm sure this has been done many times in the past right? Maybe UI lists aren't a wise choice for such dynamic drawing


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.