euporie.core.widgets.forms

Contain input widgets.

Functions

abstractmethod(funcobj)

A decorator indicating abstract methods.

align(ft[, how, width, style, placeholder, ...])

Align formatted text at a given width.

cast(typ, val)

Cast a value to a type.

ceil(x, /)

Return the ceiling of x as an Integral.

explode_text_fragments(fragments)

Turn a list of (style_str, text) tuples into another list where each string is exactly one character.

floor(x, /)

Return the floor of x as an Integral.

fragment_list_len(fragments)

Return the amount of characters in this text fragment list.

fragment_list_width(fragments)

Return the character width of this text fragment list.

get_app()

Get the current active (running) Application.

has_focus(value)

Enable when this buffer has the focus.

merge_key_bindings(bindings)

Merge multiple Keybinding objects together.

to_filter(bool_or_filter)

Accept both booleans and Filters as input and turn it into a Filter.

to_formatted_text(value[, style, auto_convert])

Convert the given value (which can be formatted text) into a list of text fragments.

Classes

ABCMeta(name, bases, namespace, /, **kwargs)

Metaclass for defining Abstract Base Classes (ABCs).

AfterInput(text[, style])

Insert text after the input.

Always()

Always enable feature.

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

Draw a border around any container.

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

Add padding around a container.

BufferControl([buffer, input_processors, ...])

Control for visualising the content of a Buffer.

Button(text, on_click, None] | None = None, ...)

A clickable button widget.

Checkbox([text, on_click, prefix, style, ...])

A toggleable checkbox widget.

Condition(func)

Turn any callable into a Filter.

ConditionalCompleter(completer, filter)

Wrapper around any other completer that will enable/disable the completions depending on whether the received condition is satisfied.

ConditionalContainer(content, filter)

Wrapper around any other container that can change the visibility.

ConditionalKeyBindings(key_bindings[, filter])

Wraps around a KeyBindings. Disable/enable all the key bindings according to the given (additional) filter.::.

ConditionalProcessor(processor, filter)

Processor that applies another processor, according to a certain condition. Example::.

ConditionalSplit(vertical, *args, **kwargs)

A split container where the orientation depends on a filter.

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

A tuple of four bools with directions.

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

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

Dropdown(options[, labels, index, indices, ...])

A dropdown widget, allowing selection of an item from a menu of options.

Event(sender[, handler])

Simple event to which event handlers can be attached. For instance::.

ExpandingBufferControl([buffer, ...])

A sub-class of BufferControl which expands to the available width.

Filter()

Base class for any filter to activate/deactivate a feature, depending on a condition.

Float(content[, top, right, bottom, left, ...])

Float for use in a FloatContainer.

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

Alignment of formatted text.

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

Control that displays formatted text.

KeyBindings()

A container for a set of key bindings.

Label(value[, style, html])

A label widget which displays rich text.

LabelledWidget(body, label[, style, ...])

A widget which applies a label to another widget.

MarginContainer(margin, target)

A container which renders a stand-alone margin.

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

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

Mouse event, sent to UIControl.mouse_handler.

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

Progress([start, stop, step, value, ...])

A progress-bar widget.

ProgressControl([start, stop, step, value, ...])

A control which draws a progress-bar.

ScrollbarMargin([display_arrows, ...])

Margin displaying a scrollbar.

Select(options, labels, index, indices, ...)

A select widget, which allows one or more items to be selected from a list.

SelectableWidget(options[, labels, index, ...])

Base class for widgets where one or more items can be selected.

Shadow(body)

Draw a shadow underneath/behind this container.

SimpleCache([maxsize])

Very simple cache that discards the oldest item when the cache size is exceeded.

SizedMask([size])

Mask with restricted number of True items.

Slider(options, labels, index, indices, ...)

A slider widget with an optional editable readout.

SliderControl(slider[, show_arrows, ...])

A control to display a slider.

Swatch(color, str] =, width, height, style, ...)

An widget which displays a given color.

Text([text, style, height, min_height, ...])

A text input widget.

TextArea([text, multiline, password, lexer, ...])

A simple input field.

ToggleButton(text, on_click, ...)

A toggleable button widget.

ToggleButtons(options, labels, index, ...)

A widget where an option is selected using mutually exclusive toggle-buttons.

ToggleableWidget()

Base class for toggleable widgets.

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

Content generated by a user control.

UIControl()

Base class for all user interface controls.

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

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

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

The validation state of a buffer.

Validator()

Abstract base class for an input validator.

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

Container that holds a control.

WordCompleter(words[, ignore_case, ...])

Simple autocompletion on a list of words.

WritePosition(xpos, ypos, width, height)

deque

deque([iterable[, maxlen]]) --> deque object

finalize(obj, func, /, *args, **kwargs)

Class for finalization of weakrefable objects

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

class euporie.core.widgets.forms.Button(text: AnyFormattedText, on_click: Callable[[Button], None] | None = None, on_mouse_down: Callable[[Button], None] | None = None, disabled: FilterOrBool = False, width: int | None = None, style: str | Callable[[], str] = 'class:input', border: GridStyle | None =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔ , show_borders: DiBool | None = None, selected: bool = False, key_bindings: KeyBindingsBase | None = None, mouse_handler: Callable[[MouseEvent], NotImplementedOrNone] | None = None)

Bases: object

A clickable button widget.

default_mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

get_key_bindings() KeyBindingsBase

Key bindings for the Button.

get_style() str

Return the style for the button given its current state.

get_text_fragments() StyleAndTextTuples

Return the list of formatted text fragments which define the button.

property width: int

The width of the button.

class euporie.core.widgets.forms.Checkbox(text: AnyFormattedText = '', on_click: Callable[[ToggleableWidget], None] | None = None, prefix: tuple[str, str] = ('☐', '☑'), style: str = 'class:input', selected: bool = False, disabled: FilterOrBool = False, key_bindings: KeyBindingsBase | None = None)

Bases: euporie.core.widgets.forms.ToggleableWidget

A toggleable checkbox widget.

container: AnyContainer
disabled: Filter
key_bindings: KeyBindingsBase | None
mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Focus on mouse down and toggle state on mouse up.

on_click: Event
selected: bool
toggle() None

Toggle the selected state and trigger the “clicked” callback.

class euporie.core.widgets.forms.Dropdown(options: list[Any], labels: Sequence[AnyFormattedText] | None = None, index: int | None = None, indices: list[int] | None = None, n_values: int | None = None, multiple: FilterOrBool = False, max_count: int | None = None, on_change: Callable[[SelectableWidget], None] | None = None, style: str | Callable[[], str] = 'class:input', arrow: str = '⯆', disabled: FilterOrBool = False)

Bases: euporie.core.widgets.forms.SelectableWidget

A dropdown widget, allowing selection of an item from a menu of options.

button_text() StyleAndTextTuples

Return the text to display on the button.

property index: int | None

Return the first selected index.

property indices: list[int]

Return a list of the selected indices.

key_bindings() KeyBindingsBase

Return key-bindings for the drop-down widget.

load_container() AnyContainer

Load the widget’s container.

property mask: list[bool]

Get mask of selected options.

menu_fragments() StyleAndTextTuples

Return formatted text fragment to display in the menu.

mouse_handler(i: int, mouse_event: prompt_toolkit.mouse_events.MouseEvent) None

Handle mouse events.

property style: str

Return the widget’s style.

toggle_item(index: int) None

Toggle the selection status of the option at a given index.

toggle_menu(button: euporie.core.widgets.forms.ToggleButton) None

Show or hide the menu.

property value: Any

Return the selected value.

property values: list[Any]

Return a list of the selected values.

class euporie.core.widgets.forms.ExpandingBufferControl(buffer: Buffer | None = None, input_processors: list[Processor] | None = None, include_default_input_processors: bool = True, lexer: Lexer | None = None, preview_search: FilterOrBool = False, focusable: FilterOrBool = True, search_buffer_control: OptionalSearchBuffer = None, menu_position: Callable[[], int | None] | None = None, focus_on_click: FilterOrBool = False, key_bindings: KeyBindingsBase | None = None, expand: FilterOrBool = True)

Bases: prompt_toolkit.layout.controls.BufferControl

A sub-class of BufferControl which expands to the available width.

create_content(width: int, height: int, preview_search: bool = False) prompt_toolkit.layout.controls.UIContent

Create a UIContent.

get_invalidate_events() Iterable[Event[object]]

Return the Window invalidate events.

get_key_bindings() KeyBindingsBase | None

When additional key bindings are given. Return these.

is_focusable() bool

Tell whether this user control is focusable.

mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Mouse handler for this control.

move_cursor_down() None

Request to move the cursor down. This happens when scrolling down and the cursor is completely at the top.

move_cursor_up() None

Request to move the cursor up.

preferred_height(width: int, max_available_height: int, wrap_lines: bool, get_line_prefix: GetLinePrefixCallable | None) int | None
preferred_width(max_available_width: int) int | None

Enure text box expands to available width.

Parameters

max_available_width – The maximum available width

Returns

The desired width, which is the maximum available

reset() None
property search_buffer: prompt_toolkit.buffer.Buffer | None
property search_buffer_control: prompt_toolkit.layout.controls.SearchBufferControl | None
property search_state: prompt_toolkit.search.SearchState

Return the SearchState for searching this BufferControl. This is always associated with the search control. If one search bar is used for searching multiple BufferControls, then they share the same SearchState.

class euporie.core.widgets.forms.Label(value: AnyFormattedText, style: str | Callable[[], str] = 'class:input', html: FilterOrBool = False)

Bases: object

A label widget which displays rich text.

get_value() AnyFormattedText

Return the current value of the label, converting to formatted text.

class euporie.core.widgets.forms.LabelledWidget(body: AnyContainer, label: AnyFormattedText, style: str = 'class:input', vertical: FilterOrBool = False, html: FilterOrBool = False)

Bases: object

A widget which applies a label to another widget.

property html: prompt_toolkit.filters.base.Filter

Get the HTML filter value.

class euporie.core.widgets.forms.Progress(start: float | int = 0, stop: float | int = 100, step: float | int = 1, value: float | int = 0, vertical: FilterOrBool = False, style: str | Callable[[], str] = 'class:input')

Bases: object

A progress-bar widget.

add_style(extra: str) Callable[[], str]

Add an additional style to the widget’s base style.

property value: float | int

Return the current value of the proegress-bar.

class euporie.core.widgets.forms.ProgressControl(start: float | int = 0, stop: float | int = 100, step: float | int = 1, value: float | int = 0, vertical: Union[prompt_toolkit.filters.base.Filter, bool] = False)

Bases: prompt_toolkit.layout.controls.UIControl

A control which draws a progress-bar.

create_content(width: int, height: int) prompt_toolkit.layout.controls.UIContent

Get or render content for a given output size.

get_invalidate_events() Iterable[Event[object]]

Return a list of Event objects. This can be a generator. (The application collects all these events, in order to bind redraw handlers to these events.)

get_key_bindings() KeyBindingsBase | None

The key bindings that are specific for this user control.

Return a KeyBindings object if some key bindings are specified, or None otherwise.

hchars = ('', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█')
is_focusable() bool

Tell whether this user control is focusable.

mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

When NotImplemented is returned, it means that the given event is not handled by the UIControl itself. The Window or key bindings can decide to handle this event as scrolling or changing focus.

Parameters

mouse_eventMouseEvent instance.

move_cursor_down() None

Request to move the cursor down. This happens when scrolling down and the cursor is completely at the top.

move_cursor_up() None

Request to move the cursor up.

preferred_height(width: int, max_available_height: int, wrap_lines: bool, get_line_prefix: GetLinePrefixCallable | None) int | None

Determine the height of the progress-bar depending on its orientation.

preferred_width(max_available_width: int) int | None

Determine the width of the progress-bar depending on its orientation.

render(width: int, height: int) list[StyleAndTextTuples]

Render the progressbar at a given size as lines of formatted text.

reset() None
vchars = ('', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
class euporie.core.widgets.forms.Select(options: list[Any], labels: Sequence[AnyFormattedText] | None = None, index: int | None = None, indices: list[int] | None = None, n_values: int | None = None, multiple: FilterOrBool = False, max_count: int | None = None, on_change: Callable[[SelectableWidget], None] | None = None, style: str | Callable[[], str] = 'class:input,select', rows: int | None = 3, prefix: tuple[str, str] = ('', ''), border: GridStyle | None =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔ , show_borders: DiBool | None = None, disabled: FilterOrBool = False, dont_extend_width: FilterOrBool = True, dont_extend_height: FilterOrBool = True)

Bases: euporie.core.widgets.forms.SelectableWidget

A select widget, which allows one or more items to be selected from a list.

property index: int | None

Return the first selected index.

property indices: list[int]

Return a list of the selected indices.

key_bindings() KeyBindingsBase

Key bindings for the selectable widget.

load_container() AnyContainer

Load the widget’s container.

property mask: list[bool]

Get mask of selected options.

mouse_handler(i: int, mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

property style: str

Return the widget’s style.

text_fragments() StyleAndTextTuples

Create a list of formatted text fragments to display.

toggle_item(index: int) None

Toggle the selection status of the option at a given index.

property value: Any

Return the selected value.

property values: list[Any]

Return a list of the selected values.

class euporie.core.widgets.forms.SelectableWidget(options: list[Any], labels: Sequence[AnyFormattedText] | None = None, index: int | None = None, indices: list[int] | None = None, n_values: int | None = None, multiple: FilterOrBool = False, max_count: int | None = None, on_change: Callable[[SelectableWidget], None] | None = None, style: str | Callable[[], str] = 'class:input', disabled: FilterOrBool = False)

Bases: object

Base class for widgets where one or more items can be selected.

property index: int | None

Return the first selected index.

property indices: list[int]

Return a list of the selected indices.

key_bindings() KeyBindingsBase

Key bindings for the selectable widget.

abstract load_container() AnyContainer

Abstract method for loading the widget’s container.

property mask: list[bool]

Get mask of selected options.

mouse_handler(i: int, mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

property style: str

Return the widget’s style.

toggle_item(index: int) None

Toggle the selection status of the option at a given index.

property value: Any

Return the selected value.

property values: list[Any]

Return a list of the selected values.

class euporie.core.widgets.forms.SizedMask(size: int | None = None)

Bases: Dict[int, bool]

Mask with restricted number of True items.

clear() None

Clear the dict’s items.

copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values
class euporie.core.widgets.forms.Slider(options: list[Any], labels: Sequence[AnyFormattedText] | None = None, index: int | None = None, indices: list[int] | None = None, n_values: int | None = None, multiple: FilterOrBool = False, max_count: int | None = None, on_change: Callable[[SelectableWidget], None] | None = None, style: str | Callable[[], str] = 'class:input', border: GridStyle =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔ , show_borders: DiBool | None = None, vertical: FilterOrBool = False, show_arrows: FilterOrBool = True, arrows: tuple[AnyFormattedText, AnyFormattedText] = ('-', '+'), show_readout: FilterOrBool = True, disabled: FilterOrBool = False)

Bases: euporie.core.widgets.forms.SelectableWidget

A slider widget with an optional editable readout.

accept_handler(buffer: Buffer) bool

Set the index to the value(s) entered in the readout buffer.

control: SliderControl
property index: int | None

Return the first selected index.

property indices: list[int]

Return a list of the selected indices.

key_bindings() KeyBindingsBase

Key bindings for the selectable widget.

load_container() AnyContainer

Build the slider’s container.

property mask: list[bool]

Get mask of selected options.

mouse_handler(i: int, mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

readout: Text
readout_len() int

Return the length of the readout text area.

readout_text(indices: list[int]) str

Return the readout text area value.

property style: str

Return the widget’s style.

toggle_item(index: int) None

Toggle the selection status of the option at a given index.

validate_readout(text: str) list[Any] | None

Confirm the value entered in the readout is value.

property value: Any

Return the selected value.

value_changed(slider: euporie.core.widgets.forms.SelectableWidget | None = None) None

Set the readout text when the slider value changes.

property values: list[Any]

Return a list of the selected values.

class euporie.core.widgets.forms.SliderControl(slider: euporie.core.widgets.forms.Slider, show_arrows: Union[prompt_toolkit.filters.base.Filter, bool] = True, handle_char: str = '●', track_char: str | None = None, selected_track_char: str | None = None, style: str = 'class:input')

Bases: prompt_toolkit.layout.controls.UIControl

A control to display a slider.

create_content(width: int, height: int) prompt_toolkit.layout.controls.UIContent

Create an cache the rendered control fragments.

get_invalidate_events() Iterable[Event[object]]

Return a list of Event objects. This can be a generator. (The application collects all these events, in order to bind redraw handlers to these events.)

get_key_bindings() KeyBindingsBase | None

Key bindings for the Slider.

is_focusable() bool

Tell whether this user control is focusable.

mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events given the slider’s orientation.

mouse_handler_(mouse_event: MouseEvent, loc: int) NotImplementedOrNone

Handle mouse events.

mouse_handler_arrow(mouse_event: MouseEvent, n: int = 0) NotImplementedOrNone

Handle mouse events on the slider’s arrows.

mouse_handler_handle(mouse_event: MouseEvent, handle: int = 0) NotImplementedOrNone

Handle mouse events on the slider’s handles.

mouse_handler_scroll(mouse_event: MouseEvent, handle: int | None = None) NotImplementedOrNone

Handle mouse scroll events.

mouse_handler_track(mouse_event: MouseEvent, index: int = 0) NotImplementedOrNone

Handle mouse events on the slider track.

move_cursor_down() None

Request to move the cursor down. This happens when scrolling down and the cursor is completely at the top.

move_cursor_up() None

Request to move the cursor up.

preferred_height(width: int, max_available_height: int, wrap_lines: bool, get_line_prefix: GetLinePrefixCallable | None) int | None

Return the preferred height of the slider control given its orientation.

preferred_width(max_available_width: int) int | None

Return the preferred width of the slider control given its orientation.

render_lines(width: int, height: int) list[StyleAndTextTuples]

Generate formatted text fragments to display the slider.

async repeat(mouse_event: MouseEvent, handler: Callable[..., NotImplementedOrNone], timeout: float = 0.25, **kwargs: Any) None

Repeat a mouse event after a timeout.

reset() None
property selected_handle: int

Return the currently selected slider handle.

set_index(handle: int = 0, ab: int | None = None, rel: int | None = None, fire: bool = True) NotImplementedOrNone

Set the selected index of the slider.

class euporie.core.widgets.forms.Swatch(color: str | Callable[[], str] = '#FFFFFF', width: int = 2, height: int = 1, style: str = 'class:swatch', border: GridStyle =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔, show_borders: DiBool | None = None)

Bases: object

An widget which displays a given color.

get_style() str

Compute the style for the swatch..

class euporie.core.widgets.forms.Text(text: str = '', style: str = 'class:input', height: int = 1, min_height: int = 1, multiline: FilterOrBool = False, expand: FilterOrBool = True, width: int | None = None, completer: Completer | None = None, options: list[str] | Callable[[], list[str]] | None = None, show_borders: DiBool | None = None, on_text_changed: Callable[[Buffer], None] | None = None, validation: Callable[[str], bool] | None = None, accept_handler: BufferAcceptHandler | None = None, placeholder: str | None = None, lexer: Lexer | None = None, input_processors: Sequence[Processor] | None = None, disabled: FilterOrBool = False, password: FilterOrBool = False, wrap_lines: FilterOrBool = False, prompt: AnyFormattedText | None = None)

Bases: object

A text input widget.

border_style() str

Calculate the style to apply to the widget’s border.

property text: str

Return the input’s text value.

class euporie.core.widgets.forms.ToggleButton(text: AnyFormattedText, on_click: Callable[[ToggleButton], None] | None = None, width: int | None = None, style: str | Callable[[], str] = 'class:input', border: GridStyle | None =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔ , show_borders: DiBool | None = None, selected: bool = False, disabled: FilterOrBool = False, key_bindings: KeyBindingsBase | None = None)

Bases: euporie.core.widgets.forms.ToggleableWidget

A toggleable button widget.

container: AnyContainer
disabled: Filter
key_bindings: KeyBindingsBase | None
mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Focus on mouse down and toggle state on mouse up.

on_click: Event
property selected: bool

Return the selection state of the toggle button.

toggle() None

Toggle the selected state and trigger the “clicked” callback.

class euporie.core.widgets.forms.ToggleButtons(options: list[Any], labels: Sequence[AnyFormattedText] | None = None, index: int | None = None, indices: list[int] | None = None, n_values: int | None = None, multiple: FilterOrBool = False, max_count: int | None = None, on_change: Callable[[SelectableWidget], None] | None = None, style: str | Callable[[], str] = 'class:input', border: GridStyle | None =  ▁▁  🮇 │▎ 🮇─┼▎  ▔▔ , disabled: FilterOrBool = False, vertical: FilterOrBool = False)

Bases: euporie.core.widgets.forms.SelectableWidget

A widget where an option is selected using mutually exclusive toggle-buttons.

get_button_style(index: int) Callable[[], str]

Return the current button style.

property index: int | None

Return the first selected index.

property indices: list[int]

Return a list of the selected indices.

key_bindings() KeyBindingsBase

Return key-bindings for the drop-down widget.

load_container() AnyContainer

Load the widget’s container.

property mask: list[bool]

Get mask of selected options.

mouse_handler(i: int, mouse_event: MouseEvent) NotImplementedOrNone

Handle mouse events.

property style: str

Return the widget’s style.

toggle_item(index: int) None

Toggle the selection status of the option at a given index.

update_buttons(widget: euporie.core.widgets.forms.SelectableWidget | None = None) None

Set the toggle buttons’ selection state when the selected index changes.

property value: Any

Return the selected value.

property values: list[Any]

Return a list of the selected values.

class euporie.core.widgets.forms.ToggleableWidget

Bases: object

Base class for toggleable widgets.

container: AnyContainer
disabled: Filter
key_bindings: KeyBindingsBase | None
mouse_handler(mouse_event: MouseEvent) NotImplementedOrNone

Focus on mouse down and toggle state on mouse up.

on_click: Event
selected: bool
toggle() None

Toggle the selected state and trigger the “clicked” callback.