radioviz.services.export_services

Export services for RadioViz application.

This module provides export functionality for saving data in various formats. It defines the ExportSpec dataclass, Exportable protocol, and ExportCoordinator class to manage the complete export workflow.

Classes

ExportCoordinator([parent])

Coordinator class for managing export operations.

ExportSpec(key, label, filter, ...)

Data class representing export specifications.

Exportable(*args, **kwargs)

Protocol defining the interface for exportable objects.

class radioviz.services.export_services.ExportCoordinator(parent: QObject | None = None)[source]

Bases: QObject

Coordinator class for managing export operations.

This class handles the complete export workflow, including: - Determining available export formats - Presenting format selection to the user when multiple options exist - Executing the actual export using the specified writer function

Initialize the export coordinator.

Parameters:

parent (QObject or None) – Parent QObject for Qt ownership management

_ask_user_for_format(specs: list[ExportSpec], parent: QWidget | None) ExportSpec | None[source]

Prompt user to select an export format.

Parameters:
  • specs (list[ExportSpec]) – List of available export specifications

  • parent (QWidget) – Parent widget for dialog window

Returns:

Selected export specification or None if cancelled

Return type:

ExportSpec or None

_choose_and_export(exportable: Exportable, specs: list[ExportSpec], parent_widget: QWidget | None) None[source]

Present format selection to user and export using chosen format.

Parameters:
  • exportable (Exportable) – Object to be exported

  • specs (list[ExportSpec]) – List of available export specifications

  • parent_widget (QWidget) – Parent widget for dialog windows

_export_with_spec(exportable: Exportable, spec: ExportSpec, parent_widget: QWidget | None) None[source]

Export using a specific export specification.

Opens a file dialog to get the destination path and calls the writer function.

Parameters:
  • exportable (Exportable) – Object to be exported

  • spec (ExportSpec) – Export specification to use

  • parent_widget (QWidget) – Parent widget for dialog windows

export(exportable: Exportable, parent_widget: QWidget | None) None[source]

Initiate the export process for an exportable object.

If the exportable has only one export specification, it will be used directly. Otherwise, the user will be prompted to select a format.

Parameters:
  • exportable (Exportable) – Object to be exported

  • parent_widget (QWidget) – Parent widget for dialog windows

class radioviz.services.export_services.ExportSpec(key: str, label: str, filter: str, default_suffix: str, suffix_map: dict[str, str], writer: Callable[[Path], None])[source]

Bases: object

Data class representing export specifications.

This class holds all the information needed to define how an object can be exported, including the export key, display label, file filters, default suffixes, and the actual writer function.

default_suffix: str

str: Default file suffix for this export format.

filter: str

str: File filter string for Qt file dialogs.

key: str

str: Unique identifier for the export specification.

label: str

str: Human-readable label for the export option.

suffix_map: dict[str, str]

dict[str, str]: Mapping from filter strings to their default suffixes.

writer: Callable[[Path], None]

Callable[[Path], None]: Function that performs the actual writing operation.

class radioviz.services.export_services.Exportable(*args, **kwargs)[source]

Bases: Protocol

Protocol defining the interface for exportable objects.

Any class implementing this protocol can be exported using the ExportCoordinator.

can_export_as() bool[source]

Check if this object can be exported.

Returns:

True if the object can be exported, False otherwise

Return type:

bool

get_export_specs() list[ExportSpec][source]

Get available export specifications for this object.

Returns:

List of export specifications

Return type:

list[ExportSpec]