Created
April 12, 2019 18:44
-
-
Save jsignell/cf7ab50d6794966aff8aafcbf2b2749d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from collections import OrderedDict | |
import panel as pn | |
path = os.getcwd() | |
down = '│' | |
right = '└──' | |
def expand_dir(event): | |
"""For a dir - populate with subdirs""" | |
def has_children(parent): | |
return os.path.isdir(parent) | |
def get_children(parent): | |
return sorted(os.listdir(got)) | |
def populate_value(parent, child): | |
return os.path.join(parent, child) | |
got = event.new[0] | |
obj = event.obj | |
old = list(event.obj.options.items()) | |
name = next(k for k, v in old if v == got) | |
index = next(i for i, (k, v) in enumerate(old) if v == got) | |
if right in name: | |
prefix = f'{name.split(right)[0]}{down} {right}' | |
else: | |
prefix = right | |
if has_children(got): | |
items = get_children(got) | |
for i, item in enumerate(items): | |
value = populate_value(got, item) | |
old.insert(index+i+1, (f'{prefix} {item}', value)) | |
event.obj.options = dict(old) | |
items = [p for p in sorted(os.listdir(path)) if not p.startswith('.')] | |
options = OrderedDict(zip(items, (os.path.join(path, item) for item in items))) | |
select = pn.widgets.MultiSelect(options=options, size=14) | |
select.param.watch(expand_dir, 'value') | |
row = pn.Row(select) | |
row.servable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment