Explorer

FileExplorer

class kable.explorer.FileExplorer(root)[source]

Bases: Tree

A file explorer widget with Git-aware styling and hidden file filtering.

Parameters:

root (Path)

__init__(root)[source]

Initialize the file explorer.

Parameters:

root (Path) – Root directory to display.

on_mount()[source]

Load Git metadata and build the file tree.

Return type:

None

build_tree(node, path, ignore=False)[source]

Recursively populate the tree view.

Parameters:
  • node (TreeNode) – Parent tree node.

  • path (Path) – Directory being traversed.

  • ignore (bool) – Whether descendants should be treated as ignored.

Return type:

None

add_file_node(node, file_path, is_ignored=False)[source]

Add a file node to the tree.

Parameters:
  • node (TreeNode) – Parent tree node.

  • file_path (Path) – Path to the file.

  • is_ignored (bool) – Whether the file is Git ignored.

Return type:

None

is_git_ignored(path)[source]

Check whether a path is ignored by Git.

Parameters:

path (Path) – Path to check.

Returns:

True if the path is ignored.

Return type:

bool

on_tree_node_selected(event)[source]

Handle tree node selection.

Directories are expanded or collapsed. Files emit a FileClicked message.

Parameters:

event (NodeSelected) – Tree selection event.

Return type:

None

ishidden(path)[source]

Check whether a file or directory is hidden.

On Windows this uses the hidden file attribute.

Parameters:

path (Path) – Path to check.

Returns:

True if the path is hidden.

Return type:

bool

get_status(path)[source]

Retrieve the cached Git status of a file.

Parameters:

path (Path) – File path.

Returns:

Git status code or an empty string.

Return type:

str

Confirm

class kable.explorer.Confirm(prompt)[source]

Bases: ModalScreen[bool]

Modal confirmation dialog.

Parameters:

prompt (str)

__init__(prompt)[source]

Initialize the confirmation dialog.

Parameters:

prompt (str) – Message displayed to the user.

Return type:

None

compose()[source]

Create the dialog layout.

Returns:

Widgets that make up the dialog.

Return type:

Iterable[Widget]

on_button_pressed(event)[source]

Handle confirmation button presses.

Selecting Yes dismisses the dialog with True. Selecting No dismisses the dialog with False.

Parameters:

event (Pressed) – Button press event.

Return type:

None