import carb
import omni.ui as ui
import omni.kit.app
from omni.kit.menu.core import uiMenu, uiMenuItem, IconMenuBaseDelegate
# Ensure the required extension is enabled
omni.kit.app.get_app().get_extension_manager().set_extension_enabled_immediate("omni.kit.menu.core", True)
# Create a custom menu delegate
class CustomMenuDelegate(IconMenuBaseDelegate):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.load_settings("omni.kit.menu.utils")
# Instantiate the custom delegate
custom_delegate = CustomMenuDelegate()
# Create the root menu
menu_root = uiMenu(
"Custom Menu",
enabled=True,
delegate=custom_delegate,
tearable=False,
glyph="menu_prim.svg",
menu_checkable=True,
menu_hotkey_text="Hotkey Text",
submenu=False,
)
# Add menu items to the root menu
# Created items need retained to prevent auto garbage collection
holder = []
icon_path1 = carb.tokens.get_tokens_interface().resolve("${omni.ui}/data/icons/RenderCheckMark.svg")
icon_path2 = carb.tokens.get_tokens_interface().resolve("${kit}/resources/glyphs/cog.svg")
icon_path3 = carb.tokens.get_tokens_interface().resolve("${kit}/resources/icons/lights/distant_light.png")
with menu_root:
holder.append(uiMenuItem("Menu Item 1", enabled=True, glyph="cog.svg", menu_checkable=True))
holder.append(uiMenuItem("Menu Item 2", enabled=True, glyph=icon_path1, menu_hotkey_text="Ctrl+M"))
holder.append(uiMenuItem("Menu Item 3", enabled=True, glyph=icon_path2))
holder.append(uiMenuItem("Menu Item 4", enabled=True, glyph=icon_path3))
# Show the menu at a specific position
menu_root.show_at(100, 100)