Repository navigation
API turboframe.ui.explorer
Source: turboframe/ui/explorer.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
The file explorer: the open folder as a tree, its file operations, and files that unfold into their members.
ExplorerTree is a Textual DirectoryTree in Turbo Vision's style:
- Enter (or a double click) on a file opens it; on a folder, opens or closes it. A click puts the bar on a file.
- Right (or Space, or a click on the arrow) unfolds a folder, or a file that has members (its classes, methods, headings: the application says which); Left folds it, or goes up. Enter on a member opens its file there.
- Typing filters the tree (Backspace, Esc), in the whole folder: folders never opened are read for a match.
- Ins new file, F7 new folder, F2 rename, Del delete, Ctrl+X / Ctrl+C / Ctrl+V cut, copy, paste, Ctrl+R refresh,
Alt+F10 or a right click the local menu (
turboframe.ui.localmenu). A file or a folder dragged onto a folder moves there, after asking. - The folders shown open are watched for changes made outside the application (
turboframe.watch, with watchdog): only a folder whose entries changed is read again, and the bar and the scroll stay where they were. - Git's state of each file (
set_git, fromturboframe.git.marks) is drawn beside its name.
What a file unfolds into is the application's: an ExplorerTree subclass says which files unfold (unfolds), their members (members), a member's label (member_label), a folder's mark (folder_mark), the names it hides (HIDDEN_NAMES, HIDDEN_SUFFIXES) and what watches the folders (watcher_factory). A member is any object with children (its own members) and, to be told apart when the file is read again, a key; the default go_to_member selects its start to end offsets.
ExplorerWindow holds the tree (TREE, the class). ExplorerMixin is the application's side: it does the operations the tree asks for, and nothing is created, moved or deleted outside the open folder; open editors follow a renamed or moved file, and a file with unsaved changes is never replaced or closed by an operation. Its hooks (the folder, the editors, opening a file...) have defaults for turboframe.ui.editor.
CM_TREE_OPEN, CM_TREE_NEW_FILE, CM_TREE_NEW_FOLDER, CM_TREE_RENAME, CM_TREE_DELETE, CM_TREE_REFRESH, CM_TREE_CUT, CM_TREE_COPY, CM_TREE_PASTE, CM_TREE_MOVE, LOCAL_ACTIONS, TREE_HINT, MEMBERS_MAX_BYTES, GIT_COLOURS, FileEntry, MemberEntry, shown_entries, disk_entries, find_in_tree, default_watcher_factory, ExplorerTree, ProjectTree, ExplorerWindow, local_menu, bad_name, ExplorerMixin
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
dict (10 entries)
'Ins new file · F7 folder · F2 rename · Del delete · Alt+F10 menu'
2000000
dict (8 entries)
class FileEntry(DirEntry)
FileEntry(path: Path, loaded: bool = False)A file the explorer can unfold into its members.
class MemberEntry(DirEntry)
MemberEntry(path: Path, loaded: bool = False, member: Any = None)A part of a file (a class, a method, a heading...): path is the file.
def shown_entries(node) -> frozenset[tuple[str, bool]]What a folder's node shows, as (name, is a folder) pairs: read on the UI thread, a snapshot.
def disk_entries(folder: Path, shown: Callable[[Path], bool]) -> frozenset[tuple[str, bool]] | NoneWhat folder holds as the tree would show it (shown: the entries it keeps), or None when it is gone or unreadable. Disk only, nothing of the UI: it runs in a worker thread.
def find_in_tree(root: Path, query: str, shown: Callable[[Path], bool], limit: int = 300, budget: int = 50000) -> list[Path]The files and folders under root whose name holds query (case ignored), as the tree shows them (shown): at most limit, after looking at budget entries at most.
def default_watcher_factory()turboframe.watch.FolderWatcher when watchdog is installed (the watch extra), else None.
class ExplorerTree(FilteredTree, DirectoryTree, TVViewMixin)
ExplorerTree(path: str | Path, *, icons: str = 'plain', **kwargs)The open folder: Ins new file, F7 new folder, F2 rename, Del delete, Ctrl+R refresh, Alt+F10 (or a right click) the local menu; Ctrl+X cuts, Ctrl+C copies, Ctrl+V pastes in the folder under the bar, Esc forgets what was cut; a file or a folder dragged onto a folder moves there (the application asks first).
The application's parts are hooks: unfolds, members, member_label, folder_mark, forget_folder_marks, HIDDEN_NAMES, HIDDEN_SUFFIXES and watcher_factory (a callable taking on_change and on_error, as FolderWatcher; None: the folders are not watched, Ctrl+R refreshes).
-
shown(cls, path: Path) -> bool: The tree showspath(HIDDEN_NAMESandHIDDEN_SUFFIXESare left out). Called from threads too: it looks at the name only. -
unfolds(path: Path) -> bool:path(a file) unfolds into its members. None does by default. -
members(path: Path, text: str) -> list: The members ofpath, whose text (from its editor, unsaved changes included, or from the disk) istext. None by default. -
member_label(member: Any) -> Text: A member's row: itslabel(ortext) by default. -
folder_mark(path: Path) -> Text | str | None: What follows a folder's name (an addon's version, for example), or None. None by default. -
forget_folder_marks() -> None: The tree is read again: marks kept for folders may be stale. -
member_text(path: Path) -> str | None: The text whose memberspathunfolds into: its editor's (app.editors()), else the file's when it is text of at mostMEMBERS_MAX_BYTES(None: no members). -
hint() -> str: The status line's text while the tree has the focus. stop_watching() -> None-
watched_folders() -> list[Path]: The folder and each folder shown open, shallow ones first (they come first under the limit): what is watched, each alone. Closed folders are read when they open. -
watch_update() -> None: The watched folders follow the open ones (after the tree changed: once per refresh). -
set_clipboard(path: Path | None, cut: bool = False) -> None: What Ctrl+V pastes (None: nothing); a cut one is drawn dim. -
set_icons(mode: str) -> None:turboframe.ui.icons.PLAINorMARKS(a file's mark where a folder has its arrow). -
set_git(files: dict[Path, str], folders: set[Path], ignored: set[Path]) -> None: What git says of the files (turboframe.git.marks): drawn beside their names. filter_paths(paths)filter_text_of(node) -> strmove_cursor(node, animate: bool = False) -> None-
fill_members(node) -> None: The members of the file ofnode(member_text, thenmembers); those unfolded stay so. -
refresh_members(path: Path | None) -> None:pathchanged (saved, or edited in its editor): every unfolded node of it shows its members as they are now. -
action_unfold() -> None: Right: a folder or a file opens (its files, its members); on an open one, to its first. -
action_fold() -> None: Left: an open folder or file closes; on anything else, to what holds it. -
action_toggle_node() -> None: Space: a folder or a file that unfolds opens or closes. -
member(property): The member under the bar, if the bar is on one. apply_filter() -> Noneaction_request(action: str) -> None-
drop_target(x: float, y: float): The folder node a drag let go at (x, y) would go into, or None (outside, where it already is, or inside the folder dragged). cursor_screen_at() -> tuple[int, int]-
target_folder(property): Where new files go: the folder under the bar, or the folder of the file under it. -
reload_node(node) -> AwaitComplete: Textual's, unless the tree has gone (its window closed, the application quitting) before or while it reloads: a move, a paste or a rename still at work then has nothing left to show. -
async reveal(path: Path) -> None: Reload the folders on the way topathand put the bar on it.
A reload that just ended may still have its folders queued for the tree's loader, which fills them again (new nodes): the node found then hangs from nothing. It is looked for again once the loader is done; and once it is done, the bar must still be there (the loader may fill a folder again after the bar was put in it). For a few seconds: a busy machine takes its time.
class ProjectTree(FilteredTree, DirectoryTree, TVViewMixin)
ProjectTree(path: str | Path, *, icons: str = 'plain', **kwargs)The open folder: Ins new file, F7 new folder, F2 rename, Del delete, Ctrl+R refresh, Alt+F10 (or a right click) the local menu; Ctrl+X cuts, Ctrl+C copies, Ctrl+V pastes in the folder under the bar, Esc forgets what was cut; a file or a folder dragged onto a folder moves there (the application asks first).
The application's parts are hooks: unfolds, members, member_label, folder_mark, forget_folder_marks, HIDDEN_NAMES, HIDDEN_SUFFIXES and watcher_factory (a callable taking on_change and on_error, as FolderWatcher; None: the folders are not watched, Ctrl+R refreshes).
-
shown(cls, path: Path) -> bool: The tree showspath(HIDDEN_NAMESandHIDDEN_SUFFIXESare left out). Called from threads too: it looks at the name only. -
unfolds(path: Path) -> bool:path(a file) unfolds into its members. None does by default. -
members(path: Path, text: str) -> list: The members ofpath, whose text (from its editor, unsaved changes included, or from the disk) istext. None by default. -
member_label(member: Any) -> Text: A member's row: itslabel(ortext) by default. -
folder_mark(path: Path) -> Text | str | None: What follows a folder's name (an addon's version, for example), or None. None by default. -
forget_folder_marks() -> None: The tree is read again: marks kept for folders may be stale. -
member_text(path: Path) -> str | None: The text whose memberspathunfolds into: its editor's (app.editors()), else the file's when it is text of at mostMEMBERS_MAX_BYTES(None: no members). -
hint() -> str: The status line's text while the tree has the focus. stop_watching() -> None-
watched_folders() -> list[Path]: The folder and each folder shown open, shallow ones first (they come first under the limit): what is watched, each alone. Closed folders are read when they open. -
watch_update() -> None: The watched folders follow the open ones (after the tree changed: once per refresh). -
set_clipboard(path: Path | None, cut: bool = False) -> None: What Ctrl+V pastes (None: nothing); a cut one is drawn dim. -
set_icons(mode: str) -> None:turboframe.ui.icons.PLAINorMARKS(a file's mark where a folder has its arrow). -
set_git(files: dict[Path, str], folders: set[Path], ignored: set[Path]) -> None: What git says of the files (turboframe.git.marks): drawn beside their names. filter_paths(paths)filter_text_of(node) -> strmove_cursor(node, animate: bool = False) -> None-
fill_members(node) -> None: The members of the file ofnode(member_text, thenmembers); those unfolded stay so. -
refresh_members(path: Path | None) -> None:pathchanged (saved, or edited in its editor): every unfolded node of it shows its members as they are now. -
action_unfold() -> None: Right: a folder or a file opens (its files, its members); on an open one, to its first. -
action_fold() -> None: Left: an open folder or file closes; on anything else, to what holds it. -
action_toggle_node() -> None: Space: a folder or a file that unfolds opens or closes. -
member(property): The member under the bar, if the bar is on one. apply_filter() -> Noneaction_request(action: str) -> None-
drop_target(x: float, y: float): The folder node a drag let go at (x, y) would go into, or None (outside, where it already is, or inside the folder dragged). cursor_screen_at() -> tuple[int, int]-
target_folder(property): Where new files go: the folder under the bar, or the folder of the file under it. -
reload_node(node) -> AwaitComplete: Textual's, unless the tree has gone (its window closed, the application quitting) before or while it reloads: a move, a paste or a rename still at work then has nothing left to show. -
async reveal(path: Path) -> None: Reload the folders on the way topathand put the bar on it.
A reload that just ended may still have its folders queued for the tree's loader, which fills them again (new nodes): the node found then hangs from nothing. It is looked for again once the loader is done; and once it is done, the bar must still be there (the loader may fill a folder again after the bar was put in it). For a few seconds: a busy machine takes its time.
class ExplorerWindow(TVWindow)
ExplorerWindow(root: Path, *, icons: str = 'plain', number: int = 0)The open folder's tree (TREE, an application's ExplorerTree), in a window that moves, grows and zooms; Window > Tile leaves it out (it arranges the editors). Its close icon asks the application, request_close(window), when it has that.
def local_menu(has_selection: bool, can_paste: bool = False, extra: list[MenuItem | Separator] | None = None) -> MenuThe explorer's local menu; extra: an application's own items, after a separator.
def bad_name(name: str, *, up: bool = False) -> str | NoneWhy name cannot be made (None: it can); up: .. is fine (the caller checks that the result stays in the folder).
class ExplorerMixinThe explorer's file operations, mixed into a DesktopApp.
The application's parts are hooks with defaults: folder (the open folder), editors(), open_file(path) (async), discard_editor(window), explorer_window(), go_to_member(window, member), paths_moved(old, new) (extend it with super(): what else follows a moved file), extra_local_items(tree) and extra_local_action(tree, command) (the application's own local menu items), after_tree_action(tree, action) and explorer_cursor_moved(tree). EXPLORER is the window's class and NEW_FILE_EXAMPLE the path the New file dialog shows as an example.
-
editors() -> list[EditorWindow]: The editor windows (the files open):EditorWindowinstances by default. Defers to another mixin's (turboframe.ui.editing.EditorMixin) when there is one. explorer_window() -> ExplorerWindow | None-
show_explorer(*, focus: bool = True) -> ExplorerWindow | None: The explorer offolder, opened if it is not (None without a folder), on top. -
async open_file(path: Path) -> EditorWindow | None:pathin its editor (opened if it is not), on top; None when it cannot be opened (said). Defers to another mixin's (EditorMixin) when there is one. -
discard_editor(window: EditorWindow) -> None: Closewindowwithout asking (its file was deleted or replaced, and it held no changes). Defers to another mixin's (EditorMixin) when there is one. -
go_to_member(window: EditorWindow, member: Any) -> None: Selectmemberinwindow: itsstarttoendoffsets in the text by default. -
paths_moved(old: Path, new: Path) -> None: A file or a folder was renamed or moved: the editors of it, or of what it holds, follow. -
extra_local_items(tree: ExplorerTree) -> list[MenuItem | Separator]: The application's own items for the local menu (with commands of its own), shown after the explorer's. -
async extra_local_action(tree: ExplorerTree, command: int) -> None: One ofextra_local_itemswas chosen. -
after_tree_action(tree: ExplorerTree, action: str) -> None: An operation of the tree ended (the files may have changed). -
explorer_cursor_moved(tree: ExplorerTree) -> None: The bar moved in the tree (a status line can showtree.hint()). tree_action(tree: ExplorerTree, action: str, at: tuple[int, int] | None = None) -> None-
relative_name(path: Path) -> str:pathas the dialogs name it: relative to the folder, with/(.for the folder itself). -
in_folder(path: Path) -> bool:pathis the open folder or inside it (..resolved, links followed where they exist). async create_entry(tree: ExplorerTree, *, folder: bool) -> Path | Noneasync rename_entry(tree: ExplorerTree) -> Path | None-
copy_name(target: Path) -> Path:notes copy.txt,notes copy 2.txt... (a copy in its own folder). -
async transfer(tree: ExplorerTree, source: Path, folder: Path, *, copy: bool) -> Path | None: Move (or copy)sourceintofolder: what follows a moved file follows it (paths_moved). Asks before replacing a file; a folder is never merged into another, nor put inside itself. -
async paste_entry(tree: ExplorerTree) -> Path | None: Ctrl+V: what was cut goes to the folder under the bar (what was copied, a copy of it). -
async move_entry(tree: ExplorerTree) -> Path | None: Move to...: the folder typed (from the open folder's) or chosen with Browse. -
drop_entry(tree: ExplorerTree, source: Path, folder: Path) -> Path | None: A drag let go on a folder: asked first (a drag in a terminal is easy to slip). -
async delete_entry(tree: ExplorerTree) -> bool: Del: after asking (and saying which windows hold unsaved changes to it); never the open folder.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links