euporie.core.widgets.page

Contain containers which display children at full height vertially stacked.

Functions

cast(typ, val)

Cast a value to a type.

get_app()

Get the current active (running) Application.

run_in_thread_with_context(func, *args[, daemon])

Run a function in an thread, but make sure it uses the same contextvars.

to_container(container)

Make sure that the given object is a Container.

to_dimension(value)

Turn the given object into a Dimension object.

walk(container[, skip_hidden])

Walk through layout, starting at this container.

Classes

BoundedWritePosition(xpos, ypos, width, ...)

A write position which also hold bounding box information.

Char([char, style])

Represent a single character in a Screen.

ChildRenderInfo(parent, child)

A class which holds information about a ScrollingContainer child.

Container()

Base class for user interface layout.

DiInt([top, right, bottom, left])

A tuple of four integers with directions.

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

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

MouseEvent(position, event_type, button, ...)

Mouse event, sent to UIControl.mouse_handler.

MouseEventType(value[, names, module, ...])

MouseHandlers()

Two dimensional raster of callbacks for mouse events.

MouseModifier(value[, names, module, ...])

Point(x, y)

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

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

Screen([default_char, initial_width, ...])

Two dimensional buffer of Char instances.

ScrollOffsets([top, bottom, left, right])

Scroll offsets for the Window class.

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

A scrollable container which renders only the currently visible children.

UIContent(get_line, StyleAndTextTuples] = >, ...)

Content generated by a user control.

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

Container that holds a control.

WindowRenderInfo(window, ui_content, ...)

Render information for the last render time of this control.

WritePosition(xpos, ypos, width, height)

class euporie.core.widgets.page.BoundedWritePosition(xpos: int, ypos: int, width: int, height: int, bbox: euporie.core.data_structures.DiInt)

Bases: prompt_toolkit.layout.screen.WritePosition

A write position which also hold bounding box information.

class euporie.core.widgets.page.ChildRenderInfo(parent: ScrollingContainer, child: AnyContainer)

Bases: object

A class which holds information about a ScrollingContainer child.

blit(screen: prompt_toolkit.layout.screen.Screen, mouse_handlers: prompt_toolkit.layout.mouse_handlers.MouseHandlers, left: int, top: int, cols: slice, rows: slice) None

Copy the rendered child from the local screen to the main screen.

All locations are adjusted, allowing the pre-rendered child to be placed at any location on the main screen.

Parameters
  • screen – The main screen to copy the pre-rendered screen data to

  • mouse_handlers – The mouse handler collection to copy the pre-rendered handelers to

  • left – The left-most column in which to start placing the data

  • top – The upper row in which to start placing the data

  • cols – The columns to copy

  • rows – The rows to copy

invalidate() None

Flag the child’s rendering as out-of-date.

property layout_hash: int

Return a hash of the child’s current layout.

render(available_width: int, available_height: int, style: str = '') None

Render the child container at a given size.

Parameters
  • available_width – The height available for rendering

  • available_height – The width available for rendering

  • style – The parent style to apply when rendering

class euporie.core.widgets.page.PrintingContainer(children: Callable | Sequence[AnyContainer], width: AnyDimension = None, key_bindings: KeyBindingsBase | None = None)

Bases: prompt_toolkit.layout.containers.Container

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

property children: Sequence[AnyContainer]

Return the container’s children.

get_children() list[prompt_toolkit.layout.containers.Container]

Return a list of all child containers.

get_key_bindings() KeyBindingsBase | None

Return the container’s key bindings.

is_modal() bool

When this container is modal, key bindings from parent containers are not taken into account if a user control in this container is focused.

preferred_height(width: int, max_available_height: int) prompt_toolkit.layout.dimension.Dimension

Return the preferred height, equal to the sum of the child heights.

preferred_width(max_available_width: int) prompt_toolkit.layout.dimension.Dimension

Calculate and returns the desired width for this container.

reset() None

Reet the state of this container and all the children.

Does nothing as this container is used for dumping output.

write_to_screen(screen: prompt_toolkit.layout.screen.Screen, mouse_handlers: prompt_toolkit.layout.mouse_handlers.MouseHandlers, write_position: prompt_toolkit.layout.screen.WritePosition, parent_style: str, erase_bg: bool, z_index: int | None) None

Render the container to a Screen instance.

All children are rendered vertically in sequence.

Parameters
class euporie.core.widgets.page.ScrollingContainer(children: Callable[[], Sequence[AnyContainer]] | Sequence[AnyContainer], height: AnyDimension = None, width: AnyDimension = None, style: str | Callable[[], str] = '')

Bases: prompt_toolkit.layout.containers.Container

A scrollable container which renders only the currently visible children.

property children: Sequence[AnyContainer]

Return the current children of this container instance.

get_child(index: int | None = None) AnyContainer

Return a rendered instance of the child at the given index.

If no index is given, the currently selected child is returned.

Parameters

index – The index of the child to return.

Returns

A rendered instance of the child.

get_child_render_info(index: int | None = None) euporie.core.widgets.page.ChildRenderInfo

Return a rendered instance of the child at the given index.

If no index is given, the currently selected child is returned.

Parameters

index – The index of the child to return.

Returns

A rendered instance of the child.

get_children() list[prompt_toolkit.layout.containers.Container]

Return the list of currently visible children to include in the layout.

get_key_bindings() prompt_toolkit.key_binding.key_bindings.KeyBindingsBase | None

Returns a KeyBindings object. These bindings become active when any user control in this container has the focus, except if any containers between this container and the focused user control is modal.

is_modal() bool

When this container is modal, key bindings from parent containers are not taken into account if a user control in this container is focused.

property known_sizes: dict[int, int]

A dictionary mapping child indices to height values.

mouse_scroll_handler(mouse_event: MouseEvent) NotImplementedOrNone

Mouse handler to scroll the pane.

pre_render_children(width: int, height: int) None

Render all unrendered children in a background thread.

preferred_height(width: int, max_available_height: int) prompt_toolkit.layout.dimension.Dimension

Return the preferred height only if one is provided.

preferred_width(max_available_width: int) prompt_toolkit.layout.dimension.Dimension

Do not provide a preferred width - grow to fill the available space.

render_info: WindowRenderInfo | None
reset() None

Reet the state of this container and all the children.

scroll(n: int) NotImplementedOrNone

Scroll up or down a number of rows.

Parameters

n – The number of rows to scroll, negative for up, positive for down

Returns

NotImplemented is scrolling is not allowed, otherwise

None

scroll_to(index: int) None

Scroll a child into view.

Parameters

index – The child index to scroll into view

select(index: int, extend: bool = False, position: int | None = None, scroll: bool = True) None

Select a child 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 in indices of the currently selected children.

property selected_slice: slice

Return the currently selected slice.

validate_slice(slice_: slice) slice

Ensure a slice describes a valid range of children.

property vertical_scroll: int

The best guess at the absolute vertical scroll position.

write_to_screen(screen: prompt_toolkit.layout.screen.Screen, mouse_handlers: prompt_toolkit.layout.mouse_handlers.MouseHandlers, write_position: prompt_toolkit.layout.screen.WritePosition, parent_style: str, erase_bg: bool, z_index: int | None) None

Write the actual content to the screen.

Children are rendered only if they are visible and have changed, and the output is cached to a separate screen object stored in a :py:ChildRenderInfo. The cached rendering of the children which are actually visible are then copied to the screen. This results in faster rendering of the scrolling container, and makes scrolling more performant.

Parameters