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.

parse_path(path[, resolve])

Parse and resolve a path.

read_nb(fp, as_version[, ...])

Read a notebook from a file as a NotebookNode of the given version.

standard_b64decode(s)

Decode bytes encoded with the standard Base64 alphabet.

write_nb(nb, fp[, version, ...])

Write a notebook to a file in a given nbformat version.

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)

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.

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: euporie.core.tabs.base.KernelTab

The main notebook container class.

allow_stdin: bool = False
bg_init = True
abstract property cell: euporie.core.widgets.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.

container: AnyContainer
default_callbacks: MsgCallbacks
edit_mode = False
file_extensions: set[str] = {}
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

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.

load_widgets_from_metadata() None

Load widgets from state saved in notebook metadata.

property metadata: dict[str, Any]

Return a dictionary to hold notebook / kernel metadata.

mime_types: set[str] = {}
name: str | None = None
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: 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_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.

property title: str

Return the tab title.

weight: int = 0