API

Lifecycle

modern_urwid.lifecycle.controller

modern_urwid.lifecycle.manager

Resource

modern_urwid.resource.dummies

Various classes representing unresolved AST attributes

modern_urwid.resource.registry

Handles storing Python modules

modern_urwid.resource.utils

Various utilities for handling resources

Style

modern_urwid.style.css_parser

Utilities to parse CSS rules

modern_urwid.style.registry

Handles storing styling rules

Widgets

modern_urwid.widgets.builder

modern_urwid.widgets.generic_builder

modern_urwid.widgets.registry

modern_urwid.widgets.size_options

XML

modern_urwid.xml.ast

modern_urwid.xml.parser

Compiler

class modern_urwid.compiler.LayoutData

Bases: TypedDict

controller: UnresolvedResource | None
on_enter: UnresolvedResource | None
on_exit: UnresolvedResource | None
on_load: UnresolvedResource | None
class modern_urwid.compiler.Metadata

Bases: TypedDict

layout: LayoutData
resources: ResourceData
signals: list[SignalData]
class modern_urwid.compiler.ResourceData

Bases: TypedDict

python: list[dict[str, str]]
stylesheet: list[StylesheetData]
widget: list[dict[str, str]]
class modern_urwid.compiler.SignalData

Bases: TypedDict

callback: UnresolvedResource
name: str
class modern_urwid.compiler.StylesheetData

Bases: TypedDict

path: str
var: list[dict[str, str]]
modern_urwid.compiler.compile_meta_nodes(nodes: list[MetaNode]) Metadata
modern_urwid.compiler.compile_node(node: LayoutNode, ctx: CompileContext, root_style: dict[str, str] = {'background': '', 'background-adv': '', 'color': '', 'color-adv': '', 'monochrome': ''}, child_class: str | None = None) tuple[Widget, SizeOptions, Metadata]

Take the AST and CSS rules and create a widget

modern_urwid.compiler.parse_xml_layout(file_path: Path | str, context: CompileContext, name: str | None = None) tuple[Widget, Metadata]

Context

class modern_urwid.context.CompileContext(base_dir: Path, widget_registry: WidgetRegistry = None, style_registry: StyleRegistry = None, module_registry: ModuleRegistry = None)

Bases: object

Compile context applied to all layouts

Parameters:
  • base_dir (pathlib.Path) – The root directory for all referenced files

  • widget_registry (WidgetRegistry, optional) – The widget registery used for all layouts

  • style_registry (StyleRegistry, optional) – The style registery used for all layouts

  • module_registry (ModuleRegistry, optional) – The module registery used for all layouts

add_local(name: str)

Add a LocalData entry under the given name

get_custom(key: str, default: Any = None)

Get a custom data value

get_local(name: str | None = None) LocalData

Get the LocalData entry under the given name. Defaults to the current_key if no name is provided.

resolve_path(path: str | Path) Path

Resolve a path under the base directory

Parameters:

path (str | pathlib.Path) – The path to resolve

Returns:

The resolved path

Return type:

pathlib.Path

set_custom(key: str, value: Any)

Set a custom data value, accessible by any layout using this context

set_local_key(name: str)

Set the default key to use if get_local() is called with no arguments

class modern_urwid.context.LocalData

Bases: object

Local data applied to an individual controller

get(key: str, default: Any = None)
get_widget_by_id(id) Widget | None
set(key: str, value: Any)

Decorators

modern_urwid.decorators.assign_widget(id: str) Callable[[Callable[[...], T]], T]

Bind a widget.

This is a decorator to automatically assign a class variable to a widget. The function will be overwritten with the widget instance.

Constants

This module contains all of the constants used in modern_urwid.

Module variables:

  • XML_NS - XML namespace for modern-urwid

  • RESOURCE_CHAR - The character used to reference resources from ResourceHandler

  • DEFAULT_STYLE - The default style for widgets

Exceptions

exception modern_urwid.exceptions.InvalidTemplate

Bases: Exception

exception modern_urwid.exceptions.LayoutNotFound

Bases: Exception

exception modern_urwid.exceptions.LayoutNotSpecified

Bases: Exception

exception modern_urwid.exceptions.UnknownModule

Bases: Exception

exception modern_urwid.exceptions.UnknownTag

Bases: Exception