def __init__(self, initial_value='', default=''):
if initial_value == '':
try:
initial_value = iris.sample_data_path('')
except ValueError:
initial_value = ''
# Define the file system path for input files.
self._path = ipywidgets.Text(
description='Path:',
value=initial_value,
width="100%")
# Observe the path.
self._path.observe(self._handle_path, names='value')
# Use default path value to initialise file options.
options = []
if os.path.exists(self._path.value):
options = glob.glob('{}/*'.format(self._path.value))
options.sort()
default_list = []
for default_value in default.split(','):
if default_value in options:
default_list.append(default_value)
default_tuple = tuple(default_list)
# Defines the files selected to be loaded.
self._files = ipywidgets.SelectMultiple(
description='Files:',
options=OrderedDict([(os.path.basename(f), f)
for f in options]),
value=default_tuple,
width="100%"
)
self.deleter = ipywidgets.Button(description='delete tab',
height='32px', width='75px')
hbox = ipywidgets.HBox(children=[self._files, self.deleter])
self._box = ipywidgets.Box(children=[self._path, hbox], width="100%")
评论列表
文章目录