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.
subtype='DIR_PATH'option when creating aStringProperty. 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