radioviz.services.save_services

Module for handling save operations in the application.

This module provides infrastructure for managing save operations for various savable objects. It includes the core classes and functions needed to implement save functionality with support for multiple formats and user interaction through dialog boxes.

The main components are:

Functions

normalize_save_path(path, selected_suffix)

Normalize the save path based on selected suffix.

Classes

Savable(*args, **kwargs)

Protocol for objects that can be saved.

SaveCoordinator([parent])

Coordinator for managing save operations.

SaveSpec(key, label, filter, default_suffix, ...)

Specification for a save operation.

class radioviz.services.save_services.Savable(*args, **kwargs)[source]

Bases: Protocol

Protocol for objects that can be saved.

Defines the interface that objects must implement to be savable.

can_save() bool[source]

Check if the object can be saved.

Returns:

True if object can be saved, False otherwise

Return type:

bool

can_save_as() bool[source]

Check if the object can be saved as a different file.

Returns:

True if object can be saved as, False otherwise

Return type:

bool

current_path() Path | str[source]

Get the current file path.

Returns:

Current file path or string representation

Return type:

Path or str

default_file_name() str[source]

Get the default file name for saving.

Returns:

Default file name

Return type:

str

get_save_specs() list[SaveSpec][source]

Get available save specifications.

Returns:

List of save specifications

Return type:

list[SaveSpec]

class radioviz.services.save_services.SaveCoordinator(parent: QWidget | None = None)[source]

Bases: QObject

Coordinator for managing save operations.

Handles the coordination of save operations including choosing between multiple formats and managing user interactions.

Initialize the save coordinator.

Parameters:

parent (QObject or None) – Parent QObject

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

Ask user to select a format for saving.

Parameters:
  • specs (list[SaveSpec]) – List of available save specifications

  • parent (QWidget) – Parent widget for dialog

Returns:

Selected save specification or None if cancelled

Return type:

SaveSpec or None

_choose_and_save(savable: Savable, specs: list[SaveSpec], parent_widget: QWidget | None) None[source]

Choose format and save the object.

Parameters:
  • savable (Savable) – Object to save

  • specs (list[SaveSpec]) – List of available save specifications

  • parent_widget (QWidget) – Parent widget for dialogs

_choose_and_save_as(savable: Savable, specs: list[SaveSpec], parent_widget: QWidget | None) None[source]

Choose format and save as the object.

Parameters:
  • savable (Savable) – Object to save

  • specs (list[SaveSpec]) – List of available save specifications

  • parent_widget (QWidget) – Parent widget for dialogs

_normalize_save_path(path: Path, selected_filter: str, spec: SaveSpec) Path[source]

Normalize the save path based on selected filter.

Parameters:
  • path (Path) – Original path

  • selected_filter (str) – Selected file filter

  • spec (SaveSpec) – Save specification

Returns:

Normalized path

Return type:

Path

_save_as_with_spec(savable: Savable, spec: SaveSpec, parent_widget: QWidget | None) None[source]

Save as using the specified save specification.

Parameters:
  • savable (Savable) – Object to save

  • spec (SaveSpec) – Save specification to use

  • parent_widget (QWidget) – Parent widget for dialogs

_save_with_spec(savable: Savable, spec: SaveSpec) None[source]

Save using the specified save specification.

Parameters:
  • savable (Savable) – Object to save

  • spec (SaveSpec) – Save specification to use

save(savable: Savable, parent_widget: QWidget | None) None[source]

Save the given savable object.

Parameters:
  • savable (Savable) – Object to save

  • parent_widget (QWidget) – Parent widget for dialogs

save_as(savable: Savable, parent_widget: QWidget | None) None[source]

Save the given savable object with a new name.

Parameters:
  • savable (Savable) – Object to save

  • parent_widget (QWidget) – Parent widget for dialogs

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

Bases: object

Specification for a save operation.

Defines the parameters required for saving data in a specific format.

radioviz.services.save_services.normalize_save_path(path: Path, selected_suffix: str) Path[source]

Normalize the save path based on selected suffix.

Parameters:
  • path (Path) – Original path

  • selected_suffix (str) – Selected file suffix without dot

Returns:

Normalized path

Return type:

Path