Link a child menu and keep its icon flags¶
Turn an existing slot into a link to a child menu with a new icon, keeping the slot’s label, presentation and icon flags.
Read the child menu’s UID from
read_pm()or the menu list. Do not construct it.Read the slot and split its icon flags (
#,!,^) from the icon name.Save the link and the new icon name with the old flags.
before = pme.editing.read_pm(pm_uid, slot_uids=[slot_uid])
slot = before["slots"][0]
# Keep the leading flags and replace only the icon name.
old_icon = slot["icon"]
icon_flags = old_icon[:len(old_icon) - len(old_icon.lstrip("#!^"))]
result = pme.editing.update_slots(
pm_uid,
{slot_uid: {
"mode": "MENU",
"menu_target_uid": child_uid,
"icon": icon_flags + "TOOL_SETTINGS",
"auto_icon": False,
}},
expected_version=before["version"],
expected={slot_uid: slot},
)
assert result["status"] == "committed", result
Choose an icon that fits the child’s category. A Vector Menu draws its own Nest arrow.
For an icon-only edit, leave
modeandmenu_target_uidout. The presentation settings stay as saved; a Submenu does not need to become a Button to change its icon.menu_presentationis the placement of a linked Regular Menu. Nest gestures and Pie Menu confirmation settings are separate settings.
Check¶
result["slots"][0]["after"]hasmode"MENU",target_pm_uidequal tochild_uid, andiconstarting with the old flags.In the intended menu, the displayed icon, entering the child, selecting in it, and leaving it work as intended.
Functions used: read_pm(), update_slots(). Icon values are
described in Icon value, Menu slot text in
Menu slot text.