euporie.notebook.tabs

Tab for use in euporie notebook editor.

Modules

euporie.notebook.tabs.display

Contain a tab for displaying files.

euporie.notebook.tabs.edit

Contain a tab for displaying files.

euporie.notebook.tabs.json

Contain a tab for displaying JSON data.

euporie.notebook.tabs.log

Initiate logging for euporie.core.

euporie.notebook.tabs.notebook

Contain the main class for a notebook file.

Classes

DisplayTab(app[, path])

Tab class for displaying files.

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

Tab class for editing text files.

JsonTab(app[, path])

Tab class for JSON data.

LogView(app[, path])

A tab which allows you to view log entries.

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

Interactive notebooks.

WebTab(app, path)

Tab class for displaying files.

class euporie.notebook.tabs.DisplayTab(app: BaseApp, path: Path | None = None)

Bases: Tab

Tab class for displaying files.

close(cb: Callable | None = None) None

Close a tab with a callback.

Parameters:

cb – A function to call after the tab is closed.

container: AnyContainer
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the tab (or make it visible).

load_container() AnyContainer

Abcract method for loading the notebook’s main container.

mime_types: ClassVar[set[str]] = {'*', 'application/pdf', 'application/x-latex', 'image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'stream/std*', 'text/*', 'text/html', 'text/latex', 'text/markdown', 'text/x-markdown'}
name: str | None = 'File Viewer'
reset() None

Reset the state of the tab.

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

Save the current notebook.

property title: str

Return the tab title.

weight: int = 0
class euporie.notebook.tabs.EditorTab(app: BaseApp, path: Path | None = None, kernel: Kernel | None = None, comms: dict[str, Comm] | None = None, use_kernel_history: bool = False)

Bases: KernelTab

Tab class for editing text files.

allow_stdin: bool = True
bg_init = True
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
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the tab (or make it visible).

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

property language: str

Return the name of the kernel defined in the notebook JSON.

load() None

Load the text file.

load_container() AnyContainer

Load the “tab“‘s main container.

async load_history() None

Load kernel history.

async load_lsps() None

Load the LSP clients.

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 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]] = {'text/*'}
name: str | None = 'Text Editor'
property path_name: str

Return the path name.

property position: str

Return the position of the cursor in the document.

post_init_kernel() None

Load UI and file in background after kernel has inited.

pre_init_kernel() None

Run stuff before the kernel is loaded.

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.

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

Save the current file.

set_kernel_info(info: dict) None

Handle kernel info requests.

suggester: AutoSuggest
property title: str

Return the tab title.

weight: int = 1
class euporie.notebook.tabs.JsonTab(app: BaseApp, path: Path | None = None)

Bases: Tab

Tab class for JSON data.

close(cb: Callable | None = None) None

Close a tab with a callback.

Parameters:

cb – A function to call after the tab is closed.

container: AnyContainer
file_extensions: ClassVar[dict[str, None]] = {}
filte_types: ClassVar[set[str]] = {'.json'}
focus() None

Focus the tab (or make it visible).

load_container() AnyContainer

Abcract method for loading the notebook’s main container.

mime_types: ClassVar[set[str]] = {'*json'}
name: str | None = 'JSON Viewer'
reset() None

Reset the state of the tab.

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

Save the current notebook.

property title: str

Return the tab title.

weight: int = 0
class euporie.notebook.tabs.LogView(app: BaseApp, path: Path | None = None)

Bases: Tab

A tab which allows you to view log entries.

add_record(message: FormattedText) None

Add a single new record to the textarea.

Parameters:

message – The formatted log record to add

close(cb: Callable | None = None) None

Remove log queue handler hook on close.

container: AnyContainer
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the tab (or make it visible).

mime_types: ClassVar[set[str]] = {}
name: str | None = None
reset() None

Reset the state of the tab.

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

Save the current notebook.

property title: str

Return the title of this tab.

weight: int = 0
class euporie.notebook.tabs.Notebook(app: BaseApp, path: Path | None = None, kernel: Kernel | None = None, comms: dict[str, Comm] | None = None, use_kernel_history: bool = True, json: dict[str, Any] | None = None)

Bases: BaseNotebook

Interactive notebooks.

A tab which allows running and editing a notebook.

NOTEBOOK_EXTENSIONS = ['.ipynb', '.md', '.markdown', '.Rmd', '.py', '.coco', '.R', '.r', '.jl', '.cpp', '.ss', '.clj', '.scm', '.sh', '.ps1', '.q', '.m', '.wolfram', '.pro', '.js', '.ts', '.scala', '.rs', '.robot', '.resource', '.cs', '.fsx', '.fs', '.sos', '.java', '.groovy', '.sage', '.ml', '.hs', '.tcl', '.mac', '.gp', '.do', '.sas', '.xsh', '.qmd', '.myst', '.mystnb', '.mnb']
add(index: int, source: str = '', **kwargs: Any) None

Create a new cell at a given index.

Parameters:
  • index – The position at which to insert a new cell

  • source – The contents of the new cell

  • kwargs – Additional parameters for the cell

add_cell_above() None

Inert a cell above the current selection.

add_cell_below() None

Inert a cell below the current selection.

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

Return the currently selected Cell in this Notebook.

property cells: Sequence[Cell]

Return the currently selected Cells in this Notebook.

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

Prompt the user to select a new kernel.

check_edit_mode() bool

Determine if the notebook is (or should be) in edit mode.

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
copy(slice_: slice | None = None) None

Add a copy of the selected cells to the Notebook’s clipboard.

copy_outputs(slice_: slice | None = None) None

Copy the outputs of the selected cells.

property current_input: KernelInput

Return the currently active kernel input, if any.

cut(slice_: slice | None = None) None

Remove cells from the notebook and them to the Notebook’s clipboard.

default_callbacks: MsgCallbacks
delete(slice_: slice | None = None) None

Delete cells from the notebook.

edit_mode = False
enter_edit_mode() None

Enter cell edit mode.

exit_edit_mode() None

Leave cell edit mode.

file_extensions: ClassVar[dict[str, None]] = {'.R': None, '.Rmd': None, '.clj': None, '.coco': None, '.cpp': None, '.cs': None, '.do': None, '.fs': None, '.fsx': None, '.gp': None, '.groovy': None, '.hs': None, '.ipynb': None, '.java': None, '.jl': None, '.js': None, '.m': None, '.mac': None, '.markdown': None, '.md': None, '.ml': None, '.mnb': None, '.myst': None, '.mystnb': None, '.pro': None, '.ps1': None, '.py': None, '.q': None, '.qmd': None, '.r': None, '.resource': None, '.robot': None, '.rs': None, '.sage': None, '.sas': None, '.scala': None, '.scm': None, '.sh': None, '.sos': None, '.ss': None, '.tcl': None, '.ts': None, '.wolfram': None, '.xsh': 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

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.

load_container() AnyContainer

Load the main notebook 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]
merge(slice_: slice | None = None) None

Merge two or more cells.

property metadata: dict[str, Any]

Return a dictionary to hold notebook / kernel metadata.

mime_types: ClassVar[set[str]] = {'application/x-ipynb+json'}
mode() str

Return a symbol representing the current mode.

  • ^: Notebook mode

  • >: Navigation mode

  • I: Insert mode

  • v: Visual mode

Returns:

A character representing the current mode

move(n: int, slice_: slice | None = None) None

Move a slice of cells up or down.

Parameters:
  • slice – A slice describing the cell indices to move

  • n – The amount to move them by

multiple_cells_selected: Filter
name: str | None = 'Notebook Editor'
paste(index: int | None = None) None

Append the contents of the Notebook’s clipboard below the current cell.

property path_name: str

Return the path name.

post_init_kernel() None

Start the kernel after if has been loaded.

pre_init_kernel() None

Run stuff before the kernel is loaded.

reformat() None

Reformat all code cells in the notebooks.

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

Refresh the rendered contents of this 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_all(wait: bool = False) None

Run all cells.

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

run_selected_cells(advance: bool = False, insert: bool = False) None

Run the currently selected cells.

Parameters:
  • advance – If True, move to next cell. If True and at the last cell, create a new cell at the end of the notebook.

  • insert – If True, add a new empty cell below the current cell and select it.

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

Select a cell or adds it to the selection.

Parameters:
  • index – The index of the cell to select

  • extend – If true, the selection will be extended to include the cell

  • position – An optional cursor position index to apply to the cell input

  • scroll – Whether to scroll the page

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_next_input(text: str, replace: bool = False) None

Handle set_next_input payloads, e.g. %load magic.

set_status(status: str) None

Call when kernel status changes.

split_cell() None

Split a cell into two at the cursor position.

suggester: AutoSuggest
property title: str

Return the tab title.

undelete() None

Insert the last deleted cell(s) back into the notebook.

weight: int = 3
class euporie.notebook.tabs.WebTab(app: BaseApp, path: Path | None)

Bases: Tab

Tab class for displaying files.

close(cb: Callable | None = None) None

Close a tab with a callback.

Parameters:

cb – A function to call after the tab is closed.

container: AnyContainer
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the webview when this tab is focused.

load_container() AnyContainer

Abcract method for loading the notebook’s main container.

load_url(url: str | Path, new_tab: bool = False, **kwargs: Any) bool

Load a new URL, or the URL in the address-bar.

mime_types: ClassVar[set[str]] = {'text/html', 'text/markdown'}
name: str | None = 'Web Viewer'
reset() None

Reset the state of the tab.

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

Save the current notebook.

property title: str

Return the tab title.

weight: int = 2