import sys, os
# sys.path.insert(0, os.path.abspath('..'))
import ipywe.fileselector
import ipywidgets as ipyw
fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.')
fsel.show()
print fsel.selected
fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', type='directory')
fsel.show()
print fsel.selected
fsel= ipywe.fileselector.FileSelectorPanel(
instruction='select file', start_dir='.', type='directory', newdir_toolbar_button=True)
fsel.show()
print fsel.selected
fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', multiple=True)
fsel.show()
print fsel.selected
fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', type='directory', multiple=True)
fsel.show()
print fsel.selected
def callback(selected):
print selected
fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', next=callback)
fsel.show()
fsel= ipywe.fileselector.FileSelectorPanel(
instruction='select file', start_dir='.',
custom_layout=dict(select=ipyw.Layout(height="200px", width="600px"),
button=ipyw.Layout(height="70px"))
)
fsel.show()
In this example we show that the file selector can be used in a container with other UI elements.
The initial interface has a header and footer, and the file selector is in between them.
After the user choose the file, the event handler function "next" will be called and a new widget can be placed at the same position where the file selector was.
import ipywidgets as ipyw
from IPython.display import display
# create UI elements
# - header
header = ipyw.HTML("<h4>Header</h4>")
# - body
# * the file selector
fsel= ipywe.fileselector.FileSelectorPanel(
instruction='select file', start_dir='.', type='file', multiple=False,
)
# * the container of body UI element(s)
body = ipyw.VBox(children=[fsel.panel])
def next(selected):
# the file selector UI element will be closed already at this point
# create a new panel and add it to the body
new_panel = ipyw.Label("New panel")
body.children = [new_panel]
return
fsel.select_layout = ipyw.Layout(height="300px")
fsel.next = next # assign the event handler
# - footer
footer = ipyw.HTML("<h4>Footer</h4>")
# put everything together
container = ipyw.VBox(children=[header, body, footer])
display(container)