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_core/ui/drawers/_utils.py
17
18
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_core/ui/drawers/_utils.py
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}"
    if not hasattr(enum_to_str, "_cache"):
        enum_to_str._cache = {}  # type: ignore
    value: str | None = enum_to_str._cache.get(cachekey)
    if value is not None:
        return value

    if hasattr(enum, "valueToKey"):
        value = enum.valueToKey(enum_value)
    else:
        meta_object = QStyle.staticMetaObject
        enum_index = meta_object.indexOfEnumerator(enum.__name__)
        meta_enum = meta_object.enumerator(enum_index)
        value = f"{meta_enum.valueToKey(enum_value)}-{widget}"

    enum_to_str._cache[cachekey] = value

    return value

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_core/ui/drawers/_utils.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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.

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