2019-04-25 22:55:58 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# ipyfilechooser examples"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"from ipyfilechooser import FileChooser\n",
|
|
|
|
"import os\n",
|
|
|
|
"\n",
|
|
|
|
"# Create new FileChooser:\n",
|
|
|
|
"# Path: current directory\n",
|
|
|
|
"# File: test.txt\n",
|
2019-06-19 22:41:26 +00:00
|
|
|
"# Title: <b>FileChooser example</b>\n",
|
2019-04-25 22:55:58 +00:00
|
|
|
"# Show hidden files: no\n",
|
2019-11-26 21:37:54 +00:00
|
|
|
"# Use the default path and filename as selection: yes\n",
|
2020-07-24 00:34:27 +00:00
|
|
|
"# Only show folders: no\n",
|
2019-04-25 22:55:58 +00:00
|
|
|
"fdialog = FileChooser(\n",
|
|
|
|
" os.getcwd(),\n",
|
|
|
|
" filename='test.txt',\n",
|
2019-06-19 22:41:26 +00:00
|
|
|
" title='<b>FileChooser example</b>',\n",
|
2019-11-26 21:37:54 +00:00
|
|
|
" show_hidden=False,\n",
|
2020-02-14 22:34:47 +00:00
|
|
|
" select_default=True,\n",
|
2020-07-24 00:34:27 +00:00
|
|
|
" show_only_dirs=False\n",
|
2019-04-25 22:55:58 +00:00
|
|
|
")\n",
|
|
|
|
"\n",
|
|
|
|
"display(fdialog)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Get the selected value\n",
|
|
|
|
"fdialog.selected"
|
|
|
|
]
|
|
|
|
},
|
2019-12-03 22:00:44 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Callback example\n",
|
2020-01-24 23:46:30 +00:00
|
|
|
"def change_title(chooser):\n",
|
|
|
|
" chooser.title = '<b>Callback function executed</b>'\n",
|
2019-12-03 22:00:44 +00:00
|
|
|
"\n",
|
|
|
|
"# Register callback function\n",
|
2019-12-04 22:33:32 +00:00
|
|
|
"fdialog.register_callback(change_title)"
|
2019-12-03 22:00:44 +00:00
|
|
|
]
|
|
|
|
},
|
2019-06-19 22:41:26 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Set or change the title\n",
|
2019-12-03 22:00:44 +00:00
|
|
|
"fdialog.title = '<b>Select the output file</b>'"
|
2019-06-19 22:41:26 +00:00
|
|
|
]
|
|
|
|
},
|
2019-04-25 22:55:58 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-02-14 23:03:41 +00:00
|
|
|
"# Show hidden files, change rows to 10, and hide folder icons\n",
|
2019-04-25 22:55:58 +00:00
|
|
|
"fdialog.show_hidden = True\n",
|
2020-02-14 23:03:41 +00:00
|
|
|
"fdialog.rows = 10\n",
|
2021-09-15 22:04:27 +00:00
|
|
|
"fdialog.dir_icon = None"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Change folder icon to `os.sep` and append it to the folder name\n",
|
|
|
|
"fdialog.dir_icon = os.sep\n",
|
|
|
|
"fdialog.dir_icon_append = True"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Restrict navigation\n",
|
|
|
|
"fdialog.sandbox_path = '/Users/jdoe'"
|
2019-04-25 22:55:58 +00:00
|
|
|
]
|
|
|
|
},
|
2020-07-24 00:34:27 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Switch to folder-only mode\n",
|
|
|
|
"fdialog.show_only_dirs = True"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Switch back to standard mode\n",
|
|
|
|
"fdialog.show_only_dirs = False"
|
|
|
|
]
|
|
|
|
},
|
2020-10-03 11:57:12 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Set a file filter pattern (uses https://docs.python.org/3/library/fnmatch.html)\n",
|
|
|
|
"fdialog.filter_pattern = '*.txt'"
|
|
|
|
]
|
|
|
|
},
|
2021-02-07 22:44:51 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Set multiple file filter patterns (uses https://docs.python.org/3/library/fnmatch.html)\n",
|
|
|
|
"fdialog.filter_pattern = ['*.jpg', '*.png']"
|
|
|
|
]
|
|
|
|
},
|
2019-04-25 22:55:58 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Change the default path and filename\n",
|
|
|
|
"fdialog.default_path = os.path.abspath(os.path.join(os.getcwd(), '..'))\n",
|
|
|
|
"fdialog.default_filename = 'foobar.txt'"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Reset to defaults and clear the selected value\n",
|
|
|
|
"fdialog.reset()"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# String representation\n",
|
|
|
|
"print(fdialog)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"# Print the version number\n",
|
|
|
|
"import ipyfilechooser\n",
|
|
|
|
"ipyfilechooser.__version__"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "Python 3",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2020-07-24 00:34:27 +00:00
|
|
|
"version": "3.8.3"
|
2019-04-25 22:55:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
2020-02-14 22:34:47 +00:00
|
|
|
"nbformat_minor": 4
|
2019-04-25 22:55:58 +00:00
|
|
|
}
|