Skip to content

_utils

Shared utilities used by AYONStyle drawer modules.

do_nothing(*args, **kwargs)

No-op stub used to suppress default Qt drawing for certain elements.

Source code in client/ayon_ui_qt/drawers/_utils.py
14
15
def do_nothing(*args, **kwargs):
    """No-op stub used to suppress default Qt drawing for certain elements."""

enum_to_str(enum, enum_value, widget)

Convert enum value to string representation.

Source code in client/ayon_ui_qt/drawers/_utils.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def enum_to_str(enum, enum_value: int, widget: str) -> str:
    """Convert enum value to string representation."""
    cachekey = f"{enum.__name__}_{enum_value}_{widget}"
    try:
        return enum_to_str._cache[cachekey]  # type: ignore
    except AttributeError:
        enum_to_str._cache = {}  # type: ignore
    except KeyError:
        pass

    try:
        enum_to_str._cache[cachekey] = enum.valueToKey(  # type: ignore
            enum_value
        )
    except AttributeError:
        meta_object = QStyle.staticMetaObject  # type: ignore
        enum_index = meta_object.indexOfEnumerator(enum.__name__)
        meta_enum = meta_object.enumerator(enum_index)
        enum_to_str._cache[cachekey] = (  # type: ignore
            f"{meta_enum.valueToKey(enum_value)}-{widget}"
        )

    return enum_to_str._cache[cachekey]  # type: ignore

style_font(style, w)

Create a QFont from a style dictionary.

Parameters:

Name Type Description Default
style dict

A dict with font-family, font-size, font-weight keys.

required
w QWidget | None

Optional widget (unused, kept for API consistency).

required

Returns:

Type Description
QFont

Configured QFont instance.

Source code in client/ayon_ui_qt/drawers/_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def style_font(style: dict, w: QWidget | None) -> QFont:
    """Create a QFont from a style dictionary.

    Args:
        style: A dict with font-family, font-size, font-weight keys.
        w: Optional widget (unused, kept for API consistency).

    Returns:
        Configured QFont instance.
    """
    import os
    import platform

    font = QFont()
    font.setHintingPreference(QFont.HintingPreference.PreferNoHinting)
    font.setFamily(style["font-family"])
    env_val = os.environ.get("AYON_UI_QT_FONT_OS")
    os_name = env_val.lower() if env_val else platform.system().lower()
    pt_size = style.get(f"font-size-{os_name}", style["font-size"])
    font.setPointSizeF(pt_size)
    font.setWeight(QFont.Weight(style["font-weight"]))
    return font