Skip to content

custom_file_dialog

Mihaly Konda edited this page Jul 9, 2025 · 4 revisions

custom_file_dialog

version: v1.0.7

File dialogs customized by a JSON file.

object CFDType

Singleton object of the type _CFDType, containing the types of custom file dialogs (CFD) defined in the source JSON file.


function get_path_types()

def get_path_types(fetch_data: bool = False) -> list[str | CFDData]

Returns the available custom file dialog (CFD) types.

Parameters:

  • fetch_data: A flag requesting the CFDData objects themselves. The default is False.

function merge_json()

def merge_json(path: str) -> None

Takes an external JSON dialog data file and merges its contents to the package's own file. This way if you create dialogs you can reuse them in another project.

Parameters:

  • path: Path to the external JSON dialog data file.

dataclass CFDData

Data describing a configuration for a given custom file dialog (CFD).

Parameters:

  • path_id: Unique text identifier of the path.
  • window_title: Title to set for the dialog.
  • dialog_type: Numeric identifier for open/save file or open directory.
  • file_type_filter: String filter for file handler dialogs (e.g. "JSON (*.json)").
  • path: Absolute path to start browsing from.

def __eq__(self, other) -> bool

Custom comparison rule, comparing each field.


def soft_eq(self, other) -> bool

Custom soft comparison rule, comparing only the ID.


@property
def as_dict(self) -> dict

Returns a dictionary containing the set values.


@classmethod
def from_dict(cls, src: dict) -> PathData

Returns an instance built from a dictionary.

Parameters:

  • src: A dictionary containing data to build an instance, extracted from the handled JSON file.

function _import_json()

def _import_json(full_id_key: bool = False) -> dict[str, CFDData] | None

Imports data from the handled JSON file.

Parameters:

  • full_id_key: A flag marking whether to keep the full ID as key or to format it (default) beforehand.

Returns: A dictionary with keys of path IDs and values of CFDData objects, imported from the handled JSON file (or None if there is no such file).


class _FileDialogDataEditor(QDialog)

An editor for developer use.

def __init__(self) -> None

Initializer for the class.


def _setup_ui(self) -> None

Sets up the user interface: GUI objects and layouts.


def _setup_connections(self) -> None

Sets up the connections of the GUI objects.


def _export_json(self) -> None

Exports data to the handled JSON file.


def _reset_inputs(self) -> None

Resets the input fields to their default values.


def _slot_new_type_toggled(self) -> None

Sets the visibility of the type selector based on the control combobox.


def _slot_type_selection_changed(self) -> None

Updates the GUI according to the control combobox.


def _update_type_list_combobox(self) -> None

Updates the combobox from the type list.


def _slot_delete_data(self) -> None

Attempts to delete the set data, updating the GUI.


def _slot_export_data(self) -> None

Adds the set data to the stored dictionary and exports it, updating the GUI.


class _CFDType(metaclass=Singleton)

A class for Enum-like access to custom file dialog (CFD) types.


def __init__(self) -> None

Initializer for the class.


def __getattr__(self, name: str) -> PathData | None

Returns a CFDData object identified by the passed string if there are CFD types loaded.

Parameters:

  • name: The unique identifier of a path.

function custom_dialog()

def custom_dialog(parent: QWidget, cfd_data: CFDData, custom_title: str = None) -> tuple[bool, str | None]

Opens a file dialog of the requested type.

Parameters:

  • parent: The widget from which the dialog is requested.
  • cfd_data: An object defining the appearance and path of the dialog.
  • custom_title: A custom title for the dialog. The default is None, which means that the one defined in the 'path_data' is used.

Returns: A tuple containing the success flag and the selected path or None if the selection is unsuccessful.

API reference

Base/technical modules:

Other modules

Clone this wiki locally