-
-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jsTree based FileTreeSelector #6837
Open
philippjfr
wants to merge
34
commits into
main
Choose a base branch
from
tree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
8c2c88c
Add jsTree based FileTreeSelector
philippjfr 4c79770
Fix style
philippjfr e45198c
Redesign loading of children
philippjfr 4615d4e
Remove time.sleep
philippjfr da5b109
Allow navigating FileSelector with double click (#6843)
philippjfr 5bedf2b
Allow RemoteFileSystem on FileSelector
philippjfr 5c81e76
Allow cascading and add only_files parameter
philippjfr 8f66682
Factor out base class
philippjfr 1b92194
Fix lint
hoxbro 554aa0e
Fix deprecated warnings
hoxbro b16e491
Try to fix tests
hoxbro c26be1a
Make it so you can pass in a FileSystem, instead of a Provider
hoxbro f7c9134
Update FileSelector with remote section
hoxbro 11ac107
Add docs about FileTree
hoxbro 264f795
Add s3fs to example feature
hoxbro 80e5f6f
Lower-pin s3fs
hoxbro 4cdb779
Update to JS_URLS
hoxbro d67c39e
Add max_depth option
hoxbro 78ec71f
Add max_depth to _rename
hoxbro 11e5ebb
Add disabled option
hoxbro cc90206
Add cascade_to_disabled to ts model
hoxbro f23e0f2
Remove commented out console.log
hoxbro 0f3da03
Add FileTreeSelector
philippjfr 37a2977
Keep state synced
philippjfr 697046a
Further sync fixes
philippjfr 748b08f
Improve style and allow navigation on click
philippjfr 103ffde
Ensure sync does not trigger loop
philippjfr 1fb25e9
Fix lint
hoxbro 1c0cd0f
Merge branch 'main' into tree
hoxbro af7e75c
Ignore tree
hoxbro d4d2871
Merge branch 'main' into tree
hoxbro 32896f7
Pin pydeck
hoxbro c946a85
Add first round of unit test
hoxbro 3b5f675
Add skip if s3fs is not available
hoxbro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import panel as pn\n", | ||
"pn.extension('tree')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The `FileTree` widget allows browsing the filesystem on the server and selecting one or more files in a directory.\n", | ||
"\n", | ||
"Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](../how_to/interactivity/index.md). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](../../how_to/links/index.md) or [how to use them as part of declarative UIs with Param](../../how_to/param/index.html).\n", | ||
"\n", | ||
"#### Parameters:\n", | ||
"\n", | ||
"For details on other options for customizing the component see the [layout](../../how_to/layout/index.md) and [styling](../../how_to/styling/index.md) how-to guides.\n", | ||
"\n", | ||
"##### Core\n", | ||
"\n", | ||
"* **`directory`** (str): The directory to browse (cannot access files above this directory).\n", | ||
"* **`file_pattern`** (str, default='*'): A glob-like query expression to limit the displayed files.\n", | ||
"* **`only_files`** (bool, default=False): Whether to only allow selecting files.\n", | ||
"* **`root_directory`** (str, default=None): If set to non-None value overrides directory parameter as the root\n", | ||
"directory beyond which users cannot navigate.\n", | ||
"* **`sort`** (bool): Whether to sort notes alphabetically.\n", | ||
"* **`value`** (list[str]): A list of file names.\n", | ||
"\n", | ||
"\n", | ||
"___" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The `FileTree` widget allows exploring the specified directory on the server's filesystem and any directories contained within it.\n", | ||
"\n", | ||
"The actual file selector displays the contents of the current directory, to show content of a sub-directory click on an arrow and the `FileTree` will expand with that sub-directories content. Selecting files or directories is as easy clicking on the Checkbox." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"files = pn.widgets.FileTree('~')\n", | ||
"files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To get the currently selected files simply access the `value` parameter:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"files.value" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Remote filesystem\n", | ||
"\n", | ||
"By using the power of [`fsspec`](https://filesystem-spec.readthedocs.io/en/latest/) we can connect to remote filesystems. In the example below we use the `s3fs` package to connect to a remote S3 server" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import s3fs\n", | ||
"\n", | ||
"fs = s3fs.S3FileSystem(anon=True)\n", | ||
"\n", | ||
"s3_files = pn.widgets.FileTree(directory=\"s3://datasets.holoviz.org\", fs=fs)\n", | ||
"s3_files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"s3_files.value" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python", | ||
"pygments_lexer": "ipython3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Defines custom jsTree bokeh model to render Ace editor. | ||
""" | ||
from __future__ import absolute_import | ||
|
||
from bokeh.core.properties import ( | ||
Any, Bool, List, Nullable, | ||
) | ||
from bokeh.events import ModelEvent | ||
from bokeh.models.layouts import LayoutDOM | ||
|
||
from ..config import config | ||
from ..io.resources import JS_URLS, bundled_files | ||
from ..util import classproperty | ||
|
||
|
||
class NodeEvent(ModelEvent): | ||
|
||
event_name = 'node_event' | ||
|
||
def __init__(self, model, data=None): | ||
self.data = data | ||
super().__init__(model=model) | ||
|
||
|
||
class jsTree(LayoutDOM): | ||
""" | ||
A Bokeh model that wraps around a jsTree editor and renders it inside | ||
a Bokeh plot. | ||
""" | ||
|
||
__css_raw__ = [ | ||
f"{config.npm_cdn}/jstree@3.3.16/dist/themes/default/style.min.css", | ||
] | ||
|
||
__resources__ = [ | ||
f"{config.npm_cdn}/jstree@3.3.16/dist/themes/default/32px.png", | ||
f"{config.npm_cdn}/jstree@3.3.16/dist/themes/default/throbber.gif" | ||
] | ||
|
||
@classproperty | ||
def __css__(cls): | ||
cls.__css_raw__ = cls.__css_raw__[:1] | ||
return bundled_files(cls, 'css') | ||
|
||
__javascript_raw__ = [ | ||
JS_URLS['jQuery'], | ||
f"{config.npm_cdn}/jstree@3.3.16/dist/jstree.min.js" | ||
] | ||
|
||
@classproperty | ||
def __javascript__(cls): | ||
return bundled_files(cls) | ||
|
||
plugins = List(Any) | ||
cascade = Bool(default=True) | ||
checkbox = Bool(default=True) | ||
multiple = Bool(default=True) | ||
show_icons = Bool(default=True) | ||
show_dots = Bool(default=False) | ||
show_stripes = Bool(default=True) | ||
sort = Bool(default=True) | ||
_new_nodes = Nullable(List(Any)) | ||
|
||
# Callback properties | ||
checked = List(Any) | ||
nodes = List(Any) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced these icons, let's see if we can get rid of this.