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[, is_new])

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.

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(*args, **kwargs)

Container that holds a control.

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

Bases: 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: Cell

Load the current cell’s data into our cell instance.

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.

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 | 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

Load the notebook’s main container.

async load_history() None

Load kernel history.

async load_lsps() None

We do not need LSP support for preview notebook.

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]] = {}
multiple_cells_selected: Filter
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

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: 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