0

I'm defining a directory tree using a template_list...
(Looks similar to a Windows7 directory tree)  Everything works properly, showing the drives and initial expanded folders as expected...

But when I click one of the arrows (BoolProperty), nothing happens to the list...

Currently I'm using a simple code which clears and rebuilds the collection when an arrow is clicked,

The process calls an update function supplied to the BoolProperty on registration. When the function is invoked, it clears the collection property and does a recursive scan of the expanded folders using os.listdir(). If os.path.isdir() returns valid, a folder (PropertyGroup) is added and set. (If the directory is listed in the expanded directories, it's marked expanded and recursed)

def recurse(directory,level=0):
    global folders
    for entry in os.listdir(directory):
        fullpath=( '%s%s' if directory[-1]=='/' else '%s/%s' )%(directory,entry)
        if os.path.isdir(fullpath):
            folder=folders.add()
            folder.path=fullpath
            folder.name=entry
            folder.level=level
            if fullpath in expanded_directories:
                recurse(fullpath,level+1)
                folder.expand=True

def expand_toggle(folder,context):
    global toggle,expanded_directories
    # NOTE: folder.expand is set before getting here
    if toggle: # this should ONLY be True when folder.expand is clicked (not set)
        toggle=False # don't update when setting `folder.expand`

        if folder.expand: expanded_directories.append( folder.path )
        elif folder.path in expanded_directories: expanded_directories.remove( folder.path )

        # NOTE: the initial invoke of the dialog class does the same thing as here (no recursion).

        folders.clear()  # why doesn't this clear the UI?

        for drive in drives:
            folder=folders.add()
            folder.path=drive
            folder.name=drive.split('/')[-1] or '/'
            folder.level=0 # drives are the roots
            if drive in expanded_directories:
                recurse(drive,1)
                folder.expand=True # this would call this function (recursion depth error)

        toggle=True

If the BoolProperty is toggled True, the current path (StringProperty) is appended to the expanded directories. If toggled False and the path is appended, it's removed.

But the links to the folders (PropertyGroup items) are lost when .add() is called to update the CollectionProperty...

Meaning the added folder is not part of the group .add() was called from.
Instead it gets added to context.scene directly, which is useless...

Nothing changes in the UI.

How can I achieve the expected behaviour?

EDIT: if I re-open the dialog (without clearing the expanded folders (python list)), you can then see the changes.

Tcll
  • 201
  • 1
  • 9
  • 1
    I don't think people will be able to fully help you without seeing at least some of your code. Also, as an aside, what is the reason for creating your own file browser instead of using blender's? – Ray Mairlot Nov 28 '16 at 15:30
  • Yea, I don't think I'll be able to do much there, I can't simply copy/paste... maybe I should describe the process a bit better... it shouldn't be hard to help me without my code. and the reason for my own is because blender doesn't have a friendly folder-only selection interface.. file specification would simply confuse the user, since my export script exports the model, textures, animations, and even shaders to subdirectories in the specified directory. – Tcll Nov 28 '16 at 20:38
  • Yay, I figured out how to copy/paste a text document on this stupid thing. ^_^ – Tcll Nov 29 '16 at 13:27
  • 3
    Blender does have a folder-only interface if you use the subtype='DIR_PATH' option when creating a StringProperty. Here: http://blender.stackexchange.com/questions/26898/how-to-create-a-folder-dialog/26906 or use one of the 'Operator File Export' templates that comes with blender. – Ray Mairlot Nov 29 '16 at 13:32
  • Thanks, I did initially try the 'DIR_PATH' option on the "Minecraft Directory" string property, but clicking the button did nothing... your reference might help with that, but I still need to update a template list (the left one shown above) when selecting a character, so may as well just answer this question to answer that... lol – Tcll Nov 29 '16 at 13:39
  • Agree with @RayMairlot : Could argue the template list can be drawn in the Panel region of the filebrowser. If it's an export operator that subclasses ExportHelper, then self.filepath is updated on selection via the modal nature of the filebrowser. – batFINGER Nov 29 '16 at 14:42
  • Ok, for the unimportant stuff, this is designed to be a full export suite allowing you to select multiple characters with their associate animations to be expopted to a minecraft mod called CustomSteve. It completely validates everything needed and notifies you of errors in your character. Now if I was interested in using a limited UI, I would, but I want more control over what I'm doing. The fact that I'm using my own directory browser because I don't know how to properly use blender's is not important to the question. Would be nice if blender had better offline documentation. – Tcll Nov 29 '16 at 17:15
  • I should also mention another unimportant fact, that the GUI in the image is far from complete... I intend to have a lot more informative candy since I'm designing it to be noob-proof... all I need to know is how to get the UI to show the new or removed items, as the question asks. – Tcll Nov 29 '16 at 23:23

0 Answers0