euporie.core.tabs.notebook

Contain the main class for a notebook file.

Functions

abstractmethod(funcobj)

A decorator indicating abstract methods.

add_setting(name, default, help_, description)

Register a new config item.

edit_in_editor(filename[, line_number])

Suspend the current app and edit a file in an external editor.

get_cell_id(cell_json)

Return the cell ID field defined in a cell JSON object.

get_cmd(name)

Get a command from the centralized command system by name.

open_comm(comm_container, content, buffers)

Create a new object respsenting a Comm.

read_nb(fp[, as_version, fmt, config])

Read a notebook from a file name or a file object

standard_b64decode(s)

Decode bytes encoded with the standard Base64 alphabet.

write_nb(nb, fp[, version, fmt, config])

Write a notebook to a file name or a file object

Classes

ABCMeta(name, bases, namespace, /, **kwargs)

Metaclass for defining Abstract Base Classes (ABCs).

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

The main notebook container class.

Cell(index, json, kernel_tab[, is_new])

A kernel_tab cell element.

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

A Tab which connects to a kernel.

MsgCallbacks

Typed dictionary for named message callbacks.

Never()

Never enable feature.

UntitledPath(*args[, protocol])

A path for untitled files, as needed for LSP servers.

abstractproperty([fget, fset, fdel, doc])

A decorator indicating abstract properties.

partial

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

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

Bases: KernelTab

The main notebook container class.

allow_stdin: bool = False
bg_init = True
abstract property cell: Cell

Return the current cell.

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

Prompt the user to select a new kernel.

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.

comms: dict[str, Comm]
completers: list[Completer]
container: AnyContainer
property current_input: KernelInput

Return the currently active kernel input, if any.

default_callbacks: MsgCallbacks
edit_mode = False
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the tab (or make it visible).

formatters: list[Formatter]
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.

history: History
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.

inspectors: list[Inspector]
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

Task to 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.

abstract load_container() AnyContainer

Abcract method for loading the notebook’s main container.

async load_history() None

Load kernel history.

async load_lsps() None

Load the LSP clients.

load_widgets_from_metadata() None

Load widgets from state saved in notebook metadata.

lsp_after_save_handler(lsp: LspClient) None

Tell the the LSP we saved a document.

lsp_before_save_handler(lsp: LspClient) None

Tell the the LSP we are about to save a document.

lsp_change_handler(lsp: LspClient) None

Tell the LSP server a file metadata has changed.

lsp_close_handler(lsp: LspClient) None

Tell the LSP we opened a file.

lsp_open_handler(lsp: LspClient) None

Tell the LSP we opened a file.

lsp_update_diagnostics(lsp: LspClient) None

Process a new diagnostic report from the LSP.

lsps: list[LspClient]
property metadata: dict[str, Any]

Return a dictionary to hold notebook / kernel metadata.

mime_types: ClassVar[set[str]] = {}
name: str | None = None
new_output_default(output_json: dict[str, Any], own: bool) None

Add a new output without a cell to the currently selected cell.

property path_name: str

Return the path name.

post_init_kernel() None

Load the notebook container after the kernel has been loaded.

pre_init_kernel() None

Run stuff before the kernel is loaded.

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

Refresh the notebook.

refresh_cell(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() Report

Return the current diagnostic reports.

report_kernel_error(error: Exception | None) None

Report a kernel error to the user.

reports: WeakKeyDictionary[LspClient, Report]
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_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

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(cell_index: int, extend: bool = False, position: int | None = None, scroll: bool = False) None

Select a cell.

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_status(status: str) None

Call when kernel status changes.

suggester: AutoSuggest
property title: str

Return the tab title.

weight: int = 0