Skip to content

c2f4dt.utils.icons

c2f4dt.utils.icons

icon_path(name)

Return absolute path to an icon in the project icons/ directory.

Parameters:

Name Type Description Default
name str

Filename of the icon (e.g., '32x32_document-new.png').

required

Returns:

Type Description
str

Absolute path string. If not found, returns the original name,

str

allowing Qt to fallback gracefully (useful in dev).

Source code in src/c2f4dt/utils/icons.py
def icon_path(name: str) -> str:
    """Return absolute path to an icon in the project `icons/` directory.

    Args:
        name: Filename of the icon (e.g., '32x32_document-new.png').

    Returns:
        Absolute path string. If not found, returns the original name,
        allowing Qt to fallback gracefully (useful in dev).
    """
    # icons folder sits at project root beside c2f4dt/
    base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "c2f4dt/assets/icons"))
    path = os.path.join(base, name)
    return path if os.path.isfile(path) else name

qicon(name)

Convenience to create a QIcon from the project icons folder.

Source code in src/c2f4dt/utils/icons.py
def qicon(name: str) -> QtGui.QIcon:
    """Convenience to create a QIcon from the project icons folder."""
    return QtGui.QIcon(icon_path(name))