mafw.steering_gui.views.database_editor

Expose the database editor UI for steering file configuration.

Author:

Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)

Description:

Provide a widget to edit database backend, transport, authentication, and backend parameters without touching the builder.

Module Attributes

DEFAULT_BACKEND

Default backend selection for the database editor.

DEFAULT_URLS

Mapping of backend identifiers to URL prefixes.

DEFAULT_PRAGMAS

Default SQLite pragma values used for parameter seeding.

DEFAULT_SERVER_PORTS

Default service ports used by server backends.

DEFAULT_URL_PLACEHOLDERS

Placeholder URL examples for each backend.

Classes

AuthenticationWidget([parent])

Widget exposing authentication configuration for server databases.

DatabaseEditor([parent])

Widget that exposes database backend selection and layered configuration.

ParametersWidget([parent])

Widget that manages backend-specific parameters.

TransportWidget([parent])

Widget exposing the database transport layer (URL).

class mafw.steering_gui.views.database_editor.AuthenticationWidget(parent: QWidget | None = None)[source]

Bases: QWidget

Widget exposing authentication configuration for server databases.

get_data() dict[str, Any][source]

Return the authentication mapping for the current method.

has_required_fields() bool[source]

Return whether required fields for the selected method are populated.

set_backend(backend: str) None[source]

Enable or disable auth inputs based on backend.

set_data(auth: Mapping[str, Any] | None) None[source]

Populate widget values from the auth mapping.

property file_browse_button: QToolButton

Expose browse button for tests.

property file_edit: QLineEdit

Expose password file edit for tests.

property method_combo: QComboBox

Expose method combo for tests.

property password_edit: QLineEdit

Expose password edit for tests.

property username_edit: QLineEdit

Expose username edit for tests.

class mafw.steering_gui.views.database_editor.DatabaseEditor(parent: QWidget | None = None)[source]

Bases: QWidget

Widget that exposes database backend selection and layered configuration.

_detect_backend_from_url(url: str | None) str[source]

Determine the backend type from the given URL.

This method analyses the provided URL to identify the corresponding backend type by matching URL prefixes or extracting the protocol. If no match is found, it defaults to the current backend or the default backend.

Parameters:

url – The URL string to be analysed for backend detection.

Returns:

A string representing the detected backend type.

_normalize_config(config: dict[str, Any] | None) dict[str, Any][source]

Normalize the configuration dictionary to ensure consistent backend, URL, authentication, and parameters.

This method processes the input configuration dictionary to extract and normalize values for backend type, URL, authentication details, and backend-specific parameters, ensuring defaults are applied where necessary.

Parameters:

config – A dictionary containing configuration details such as backend, URL, authentication, and parameters. If None, defaults are applied.

Returns:

A dictionary with normalized configuration values including backend, URL, enabled status, authentication, parameters, and pragmas.

get_data() dict[str, Any][source]

Return a normalized view of the current database configuration.

is_enabled() bool[source]

Return whether the database configuration group is active.

set_data(config: dict[str, Any] | None) None[source]

Populate the UI from a configuration dictionary without emitting signals.

class mafw.steering_gui.views.database_editor.ParametersWidget(parent: QWidget | None = None)[source]

Bases: QWidget

Widget that manages backend-specific parameters.

current_table_values() dict[str, Any][source]

Return the current backend table mapping.

get_data() dict[str, dict[str, Any]][source]

Return the full backend parameter mapping.

set_backend(backend: str) None[source]

Switch the visible parameter table to the given backend.

set_data(parameters: Mapping[str, Mapping[str, Any]] | None, backend: str) None[source]

Populate the widget with the provided backend parameter mapping.

property table: QTableView

Expose the parameter table for tests.

class mafw.steering_gui.views.database_editor.TransportWidget(parent: QWidget | None = None)[source]

Bases: QWidget

Widget exposing the database transport layer (URL).

get_url() str[source]

Return the current URL string.

is_valid() bool[source]

Return whether the URL can be parsed.

set_backend(backend: str) None[source]

Switch the transport view according to the backend.

set_url(url: str) None[source]

Update the URL field without emitting signals.

property sqlite_memory_button: QToolButton

Expose the SQLite memory button for tests.

property sqlite_open_button: QToolButton

Expose the SQLite open button for tests.

property url_edit: QLineEdit

Expose the active URL edit widget for external tests.

mafw.steering_gui.views.database_editor.DEFAULT_BACKEND = 'sqlite'

Default backend selection for the database editor.

mafw.steering_gui.views.database_editor.DEFAULT_PRAGMAS: dict[str, Any] = {'cache_size': -64000, 'foreign_keys': 1, 'journal_mode': 'wal', 'synchronous': 0}

Default SQLite pragma values used for parameter seeding.

mafw.steering_gui.views.database_editor.DEFAULT_SERVER_PORTS: dict[str, int] = {'mysql': 3306, 'postgresql': 5432}

Default service ports used by server backends.

mafw.steering_gui.views.database_editor.DEFAULT_URLS: dict[str, str] = {'mysql': 'mysql://', 'postgresql': 'postgresql://', 'sqlite': 'sqlite:///'}

Mapping of backend identifiers to URL prefixes.

mafw.steering_gui.views.database_editor.DEFAULT_URL_PLACEHOLDERS: dict[str, str] = {'mysql': 'mysql://localhost:3306/mydb', 'postgresql': 'postgresql://localhost:5432/mydb', 'sqlite': 'sqlite:////path/to/db'}

Placeholder URL examples for each backend.