euporie.preview.tabs.notebook

A notebook which renders cells one cell at a time.

Functions

add_setting(name, default, help_, description)

Register a new config item.

Classes

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

The main notebook container class.

Box(body[, padding, padding_left, ...])

Add padding around a container.

Cell(index, json, kernel_tab)

A kernel_tab cell element.

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.

DynamicContainer(get_container)

Container class that dynamically returns any Container.

FastDictCache(get_value[, size])

Fast, lightweight cache which keeps at most size items.

PreviewNotebook(app[, path, use_kernel_history])

A notebook tab which renders cells sequentially.

PrintingContainer(children[, width, ...])

A container which displays all it's children in a vertical list.

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

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

Window([content, width, height, z_index, ...])

Container that holds a control.

class euporie.preview.tabs.notebook.PreviewNotebook(app: BaseApp, path: Path | None = None, use_kernel_history: bool = False)

Bases: euporie.core.tabs.notebook.BaseNotebook

A notebook tab which renders cells sequentially.

after_render(app: Application[Any]) None

Close the tab if all cells have been rendered.

allow_stdin: bool = False
before_render(app: Application[Any]) None

Run the cell before rendering it if needed.

bg_init = False
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

Clean up render hooks before the tab is closed.

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(index: int) euporie.core.widgets.cell.Cell

Render a cell by its index.

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 | None = None) None

Resume rendering the app 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

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] = {}
multiple_cells_selected: Filter
name: str | None = None
property path_name: str

Return the path name.

post_init_kernel() None

Optionally start kernel after it is loaded.

pre_init_kernel() None

Filter cells before kernel is loaded.

print_title() None

Print a notebook’s filename.

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