qgis_deployment_toolbelt.profiles.qgis_customization_xml_handler module

Read and write the QGIS UI customization file (QGISCUSTOMIZATION.xml), replacement of QGISCUSTOMIZATION3.ini since QGIS 4.

See: https://github.com/qgis/QGIS/blob/master/src/app/qgscustomization.cpp

class qgis_deployment_toolbelt.profiles.qgis_customization_xml_handler.QgisCustomizationXmlHelper(xml_filepath: Path)

Bases: object

Helper to manipulate the QGIS 4+ UI customization file (QGISCUSTOMIZATION.xml).

FORMAT_VERSION: str = '1'
ROOT_ITEMS: tuple[str, ...] = ('BrowserItems', 'Docks', 'Menus', 'StatusBarWidgets', 'ToolBars')
__init__(xml_filepath: Path) → None

Instanciation.

Parameters:

xml_filepath (Path) – path to the QGISCUSTOMIZATION.xml file. It may not exist.

is_splash_screen_set() → bool

Determine if a custom splash screen is set and enabled.

Returns:

True if a splash screen path is set and the customization enabled.

Return type:

bool

read() → Element | None

Parse the customization file.

Raises:

QgisCustomizationXmlError – if the file can’t be parsed or is not a QGIS customization file.

Returns:

root element or None if the file does not exist.

Return type:

ET.Element | None

set_splash_screen(splash_screen_filepath: Path | None = None, switch: bool = True) → bool

Add/remove the splash screen path in the customization file.

Adding it also enables the customization, otherwise QGIS ignores it.

Parameters:
  • splash_screen_filepath (Path | None, optional) – path to the splash screen image. Required if switch is True. Defaults to None.

  • switch (bool, optional) – True to add, False to remove. Defaults to True.

Raises:

ValueError – if switch is True but splash_screen_filepath is not defined.

Returns:

True if the file is in the expected state.

Return type:

bool

write(root: Element) → None

Write the customization file, formatted as QGIS does.

Parameters:

root (ET.Element) – root element to write.