API
Lifecycle
Resource
Various classes representing unresolved AST attributes |
|
Handles storing Python modules |
|
Various utilities for handling resources |
Style
Utilities to parse CSS rules |
|
Handles storing styling rules |
Widgets
XML
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- stylesheet: list[StylesheetData]
- class modern_urwid.compiler.SignalData
Bases:
TypedDict- callback: UnresolvedResource
- 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.compile_widget(file_path: Path | str, context: CompileContext | None = None) tuple[Widget, dict[str, Widget]]
Compile an XML file to an urwid Widget
- Parameters:
file_path (pathlib.Path | str) – The file path to the layout file
context (CompileContext, optional) – The compile context to use when parsing. May be needed for styling.
- Returns:
Two values: the root urwid
Widget, and a dictionary mapping any widgets to their respectivemu:idtag- Return type:
- modern_urwid.compiler.gen_random_key(length)
Context
- class modern_urwid.context.CompileContext(base_dir: Path, widget_registry: WidgetRegistry = None, style_registry: StyleRegistry = None, module_registry: ModuleRegistry = None)
Bases:
objectCompile 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
- get_local(name: str | None = None) LocalData
Get the
LocalDataentry 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:
- 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
Decorators
Constants
This module contains all of the constants used in modern_urwid.
Module variables:
XML_NS- XML namespace for modern-urwidRESOURCE_CHAR- The character used to reference resources from ResourceHandlerDEFAULT_STYLE- The default style for widgets