euporie.notebook.tabs.console

Contain the main class for a notebook file.

Functions

new_code_cell([source])

Create a new code cell, without validation.

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

BaseConsole(app[, path, use_kernel_history, ...])

Base class for Consoles.

Border(body, border, style, str] =, ...)

Draw a border around any container.

CellOutputArea(json, parent[, style])

An area below a cell where one or more cell outputs can be shown.

Condition(func)

Turn any callable into a Filter.

ConditionalContainer(content, filter[, ...])

Wrapper around any other container that can change the visibility.

Console(app[, path, use_kernel_history, ...])

Console tab implementation for the Notebook application.

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

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

FocusedStyle(body[, style_focus, style_hover])

Apply a style to child containers when focused or hovered.

FormattedTextControl([text, style, ...])

Control that displays formatted text.

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

Several layouts, one stacked above/under the other.

KernelInput(kernel_tab[, text, multiline, ...])

Kernel input text areas.

MarginContainer(margin, target)

A container which renders a stand-alone margin.

ScrollbarMargin([display_arrows, ...])

Margin displaying a scrollbar.

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

A scrollable container which renders only the currently visible children.

StdInput(kernel_tab)

A widget to accept kernel input.

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

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

Window(*args, **kwargs)

Container that holds a control.

partial(func, /, *args, **keywords)

Create a new function with partial application of the given arguments and keywords.

class euporie.notebook.tabs.console.Console(app: BaseApp, path: Path | None = None, use_kernel_history: bool = True, connection_file: str = '')

Bases: BaseConsole

Console tab implementation for the Notebook application.

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

Prompt the user to select a new kernel.

clear_output(wait: bool = False) None

Remove all cells from history.

Parameters:

wait – If True, clear output when new output is generated.

close(cb: Callable | None = None) None

Shut down kernel when 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]
complete(content: dict | None = None) None

Re-render any changes.

completers: list[Completer]
container: AnyContainer
property current_input: KernelInput

Return the currently active kernel input, if any.

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

Focus the tab (or make it visible).

formatters: list[Formatter]
history: History
init_kernel(kernel: BaseKernel | 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.

input_box: KernelInput
inspectors: list[Inspector]
interrupt_kernel() None

Interrupt the current Notebook’s kernel.

kernel: BaseKernel
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.

Returns:

The file extension including the leading dot.

lang_info: dict[str, Any]
property language: str

The language of the current kernel.

load_container() HSplit

Build the main application layout.

async load_history() None

Load kernel history.

async load_lsps() None

Load the LSP clients.

lsp_add_cell(lsp: LspClient) None

Notify the LSP of a new cell.

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.

property lsp_cell: LspCell

Return a LSP cell representation of the current input.

lsp_change_handler(lsp: LspClient) None

Tell the LSP server a file 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_input(input_json: dict[str, Any], own: bool, force: bool = False) None

Create new cell inputs in response to kernel execute_input messages.

Parameters:
  • input_json – The input data from the kernel message.

  • own – Whether this input originated from this console.

  • force – Whether to force rendering even if it’s our own input.

new_output(output_json: dict[str, Any], own: bool) None

Handle new output from the kernel.

Parameters:
  • output_json – The output data from the kernel message.

  • own – Whether this output originated from this console.

property path_cell: Path

Return the virtual path of the console as a notebook cell.

property path_nb: Path

Return the virtual path of the console as a notebook.

post_init_kernel() None

Start the kernel after if has been loaded.

pre_init_kernel() None

Run stuff before the kernel is loaded.

prompt(text: str, count: int | None = None, offset: int = 0, show_busy: bool = False) StyleAndTextTuples

Determine what should be displayed in the prompt of the cell.

refresh(now: bool = True) None

Refresh the console display.

refresh_cell(cell: Any) None

Trigger the refresh of a notebook cell.

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

Reset the state of the tab.

restart_kernel(cb: Callable | None = None) None

Restart the current Notebook’s kernel.

run(buffer: Buffer | None = None) None

Run the code in the input box.

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

Save the current file.

property selected_indices: list[int]

Return a list of the currently selected cell indices.

set_kernel_info(info: dict) None

Receive and process kernel metadata.

Parameters:

info – Kernel information dictionary.

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

Set the text for the next prompt.

stdin_box: StdInput
suggester: AutoSuggest
switch_kernel(factory: KernelFactory) None

Shut down the current kernel and change to another.

property title: str

Return the tab title.

validate_input(code: str) bool

Determine if the entered code is ready to run.

Parameters:

code – The code to validate.

Returns:

True if the code is complete and ready to execute.

weight: int = 0
write_file(path: Path) None

Write the tab’s data to a path.

Not implement in the base tab.

Parameters:

path – An path at which to save the file