{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys, os\n", "# sys.path.insert(0, os.path.abspath('..'))\n", "import ipywe.fileselector\n", "import ipywidgets as ipyw" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Single file selector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.')\n", "fsel.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print fsel.selected" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Single directory selector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', type='directory')\n", "fsel.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print fsel.selected" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Single directory selector with \"new directory\" button" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(\n", " instruction='select file', start_dir='.', type='directory', newdir_toolbar_button=True)\n", "fsel.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print fsel.selected" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multiple files selector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', multiple=True)\n", "fsel.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print fsel.selected" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multiple directories selector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', type='directory', multiple=True)\n", "fsel.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print fsel.selected" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Single file selector with callback" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def callback(selected):\n", " print selected\n", "fsel= ipywe.fileselector.FileSelectorPanel(instruction='select file', start_dir='.', next=callback)\n", "fsel.show()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Custom layout\n", "valid widget names:\n", "* select\n", "* select_multiple\n", "* button" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fsel= ipywe.fileselector.FileSelectorPanel(\n", " instruction='select file', start_dir='.',\n", " custom_layout=dict(select=ipyw.Layout(height=\"200px\", width=\"600px\"),\n", " button=ipyw.Layout(height=\"70px\"))\n", ")\n", "fsel.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# A UI with more than just the file selector\n", "In this example we show that the file selector can be used in a container with other UI elements.\n", "\n", "The initial interface has a header and footer, and the file selector is in between them.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as ipyw\n", "from IPython.display import display\n", "# create UI elements\n", "# - header\n", "header = ipyw.HTML(\"