euporie.notebook.tabs.notebook

Contain the main class for a notebook file.

Functions

add_cmd(**kwargs)

Add a command to the centralized command system.

add_setting(name, default, help_, description)

Register a new config item.

cast(typ, val)

Cast a value to a type.

deepcopy(x[, memo, _nil])

Deep copy operation on arbitrary Python objects.

get_app()

Get the current active (running) Application.

get_cmd(name)

Get a command from the centralized command system by name.

load_registered_bindings(*names[, config])

Assign key-bindings to commands based on a dictionary.

register_bindings(bindings)

Update the key-binding registry.

Classes

BaseNotebook(app[, path, kernel, comms, ...])

The main notebook container class.

Cell(index, json, kernel_tab)

A kernel_tab cell element.

ClipboardData([text, type])

Text on the clipboard.

Condition(func)

Turn any callable into a Filter.

ConditionalContainer(content, filter)

Wrapper around any other container that can change the visibility.

Dimension([min, max, weight, preferred])

Specified dimension (width/height) of a user control or window.

KernelTab(app[, path, kernel, comms, ...])

A Tab which connects to a kernel.

Line([char, width, height, collapse, style])

Draw a horizontal or vertical line.

MarginContainer(margin, target)

A container which renders a stand-alone margin.

MouseEventType(value[, names, module, ...])

Notebook(app[, path, kernel, comms, ...])

Interactive notebooks.

Pattern(char[, pattern])

Fill an area with a repeating background pattern.

ScrollbarMargin([display_arrows, ...])

Margin displaying a scrollbar.

ScrollingContainer(children[, height, ...])

A scrollable container which renders only the currently visible children.

VSplit(children[, window_too_small, align, ...])

Several layouts, one stacked left/right of the other. ::.

deque

deque([iterable[, maxlen]]) --> deque object

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

class euporie.notebook.tabs.notebook.Notebook(app: BaseApp, path: Path | None = None, kernel: Kernel | None = None, comms: dict[str, Comm] | None = None, use_kernel_history: bool = True, json: dict[str, Any] | None = None)

Bases: euporie.core.tabs.notebook.BaseNotebook

Interactive notebooks.

A tab which allows running and editing a notebook.

add(index: int, source: str = '', **kwargs: Any) None

Create a new cell at a given index.

Parameters
  • index – The position at which to insert a new cell

  • source – The contents of the new cell

  • kwargs – Additional parameters for the cell

add_cell_above() None

Inert a cell above the current selection.

add_cell_below() None

Inert a cell below the current selection.

allow_stdin: bool = True
bg_init = True
property cell: euporie.core.widgets.cell.Cell

Return the currently selected Cell in this Notebook.

property cells: Sequence[Cell]

Return the currently selected Cells in this Notebook.

change_kernel(msg: str | None = None, startup: bool = False) None

Prompt the user to select a new kernel.

check_edit_mode() bool

Determine if the notebook is (or should be) in edit mode.

clipboard: list[Cell]
close(cb: Callable | None = None) None

Check if the user want to save an unsaved notebook, then close the file.

Parameters

cb – A callback to run if after closing the notebook.

comm_close(content: dict, buffers: Sequence[bytes]) None

Close a notebook Comm.

comm_msg(content: dict, buffers: Sequence[bytes]) None

Respond to a Comm message from the kernel.

comm_open(content: dict, buffers: Sequence[bytes]) None

Register a new kernel Comm object in the notebook.

container: AnyContainer
copy(slice_: slice | None = None) None

Add a copy of the selected cells to the Notebook’s clipboard.

copy_outputs(slice_: slice | None = None) None

Copy the outputs of the selected cells.

cut(slice_: slice | None = None) None

Remove cells from the notebook and them to the Notebook’s clipboard.

default_callbacks: MsgCallbacks
delete(slice_: slice | None = None) None

Delete cells from the notebook.

edit_mode = False
enter_edit_mode() None

Enter cell edit mode.

exit_edit_mode() None

Leave cell edit mode.

file_extensions: set[str] = {'.ipynb'}
focus() None

Focus the tab (or make it visible).

get_cell_by_id(cell_id: str) euporie.core.widgets.cell.Cell | None

Return a reference to the Cell container with a given cell id.

init_kernel(kernel: Kernel | None = None, comms: dict[str, Comm] | None = None, use_kernel_history: bool = False, connection_file: Path | None = None) None

Set up the tab’s kernel and related components.

interrupt_kernel() None

Interrupt the current Notebook’s kernel.

kernel: Kernel
kernel_died() None

Call if the kernel dies.

property kernel_display_name: str

Return the display name of the kernel defined in the notebook JSON.

property kernel_lang_file_ext: str

Return the display name of the kernel defined in the notebook JSON.

kernel_language: str
property kernel_name: str

Return the name of the kernel defined in the notebook JSON.

kernel_started(result: dict[str, Any] | None = None) None

Run when the kernel has started.

lang_file_ext() str

Return the file extension for scripts in the notebook’s language.

property language: str

Return the name of the kernel defined in the notebook JSON.

load() None

Load the notebook file from the file-system.

load_container() AnyContainer

Load the main notebook container.

async load_history() None

Load kernel history.

load_widgets_from_metadata() None

Load widgets from state saved in notebook metadata.

merge(slice_: slice | None = None) None

Merge two or more cells.

property metadata: dict[str, Any]

Return a dictionary to hold notebook / kernel metadata.

mime_types: set[str] = {'application/x-ipynb+json'}
mode() str

Return a symbol representing the current mode.

  • ^: Notebook mode

  • >: Navigation mode

  • I: Insert mode

  • v: Visual mode

Returns

A character representing the current mode

move(n: int, slice_: slice | None = None) None

Move a slice of cells up or down.

Parameters
  • slice – A slice describing the cell indices to move

  • n – The amount to move them by

multiple_cells_selected: Filter
name: str | None = 'Notebook Editor'
paste(index: int | None = None) None

Append the contents of the Notebook’s clipboard below the current cell.

property path_name: str

Return the path name.

post_init_kernel() None

Start the kernel after if has been loaded.

pre_init_kernel() None

Run stuff before the kernel is loaded.

reformat() None

Reformat all code cells in the notebooks.

refresh(slice_: slice | None = None, scroll: bool = True) None

Refresh the rendered contents of this notebook.

refresh_cell(cell: euporie.core.widgets.cell.Cell) None

Trigger the refresh of a notebook cell.

rendered_cells() list[euporie.core.widgets.cell.Cell]

Return a list of rendered notebooks’ cells.

report_kernel_error(error: Exception | None) None

Report a kernel error to the user.

reset() None

Reload the notebook file from the disk and re-render.

restart_kernel(cb: Callable | None = None) None

Restart the current Notebook’s kernel.

run_all(wait: bool = False) None

Run all cells.

run_cell(cell: Cell, wait: bool = False, callback: Callable[..., None] | None = None) None

Run a cell.

Parameters
  • cell – The rendered cell to run. If None, runs the currently selected cell.

  • wait – If True, blocks until cell execution is finished

  • callback – Function to run after completion

run_selected_cells(advance: bool = False, insert: bool = False) None

Run the currently selected cells.

Parameters
  • advance – If True, move to next cell. If True and at the last cell, create a new cell at the end of the notebook.

  • insert – If True, add a new empty cell below the current cell and select it.

save(path: Path | None = None, cb: Callable | None = None) None

Write the notebook’s JSON to the current notebook’s file.

Additionally save the widget state to the notebook metadata.

Parameters
  • path – An optional new path at which to save the tab

  • cb – A callback to run if after saving the notebook.

scroll_to(index: int) None

Scroll to a cell by index.

select(index: int, extend: bool = False, position: int | None = None, scroll: bool = True) None

Select a cell or adds it to the selection.

Parameters
  • index – The index of the cell to select

  • extend – If true, the selection will be extended to include the cell

  • position – An optional cursor position index to apply to the cell input

  • scroll – Whether to scroll the page

property selected_indices: list[int]

Return a list of the currently selected cell indices.

set_kernel_info(info: dict) None

Handle kernel info requests.

set_next_input(text: str, replace: bool = False) None

Handle set_next_input payloads, e.g. %load magic.

set_status(status: str) None

Call when kernel status changes.

split_cell() None

Split a cell into two at the cursor position.

property title: str

Return the tab title.

undelete() None

Insert the last deleted cell(s) back into the notebook.

undo_buffer: deque[tuple[int, list[Cell]]]
weight: int = 3