pyqt_reactive.protocols.preview_formatter

Preview formatter registry for customizable list item previews.

Allows applications to register custom formatters for specific config types to control how they appear in list item previews.

Functions

register_preview_formatter(config_type, ...)

Register a preview formatter for a config type.

Classes

PreviewFormatterRegistry()

Registry for preview formatters by config type.

class pyqt_reactive.protocols.preview_formatter.PreviewFormatterRegistry[source]

Registry for preview formatters by config type.

Applications can register formatters for specific config types to customize how fields are displayed in list item previews.

Example

from pyqt_reactive.protocols import PreviewFormatterRegistry

def format_zarr_config(config, field_name):
if field_name == ‘compression’:

return f”comp={config.compression[:3]}” # Abbreviate

return str(getattr(config, field_name))

PreviewFormatterRegistry.register(ZarrConfig, format_zarr_config)

classmethod register(config_type: Type, formatter: Callable[[Any, str], str]) None[source]

Register a formatter for a config type.

Parameters:
  • config_type – Config class to format

  • formatter – Formatter function taking (config, field_name) -> str

classmethod get_formatter(config_type: Type) Callable[[Any, str], str] | None[source]

Get formatter for a config type.

Parameters:

config_type – Config class

Returns:

Formatter function if registered, None otherwise

classmethod format_field(config: Any, field_name: str) str | None[source]

Format a field using registered formatter if available.

Parameters:
  • config – Config instance

  • field_name – Field name to format

Returns:

Formatted string if formatter available, None otherwise

pyqt_reactive.protocols.preview_formatter.register_preview_formatter(config_type: Type, formatter: Callable[[Any, str], str]) None[source]

Register a preview formatter for a config type.

Parameters:
  • config_type – Config class

  • formatter – Formatter function