Usage Examples#

Register and Deregister Custom Context Menu#

from omni.kit.window.content_browser_registry import register_context_menu, deregister_context_menu

# Define callback functions for the context menu
def on_click():
    print("Context menu item clicked!")

def on_show():
    return True  # Always show this menu item

# Register a custom context menu
register_context_menu(name="my_context_menu", glyph="my_glyph", click_fn=on_click, show_fn=on_show)

# Deregister the custom context menu
deregister_context_menu(name="my_context_menu")

Register and Deregister Listview Menu#

from omni.kit.window.content_browser_registry import register_listview_menu, deregister_listview_menu

# Define callback functions for the listview menu
def on_click():
    print("Listview menu item clicked!")

def on_show():
    return True  # Always show this menu item

# Register a listview menu item
register_listview_menu(name="my_listview_menu", glyph="my_glyph", click_fn=on_click, show_fn=on_show)

# Deregister the listview menu item
deregister_listview_menu(name="my_listview_menu")

Register and Deregister Import Menu#

from omni.kit.window.content_browser_registry import register_import_menu, deregister_import_menu

# Define callback functions for the import menu
def on_click():
    print("Import menu item clicked!")

def on_show():
    return True  # Always show this menu item

# Register an import menu item
register_import_menu(name="my_import_menu", glyph="my_glyph", click_fn=on_click, show_fn=on_show)

# Deregister the import menu item
deregister_import_menu(name="my_import_menu")

Register and Deregister File Open Handler#

from omni.kit.window.content_browser_registry import register_file_open_handler, deregister_file_open_handler

# Define a callback function for the file open handler
def on_open_file():
    print("File open handler invoked!")

# Register a file open handler
register_file_open_handler(name="my_file_open_handler", open_fn=on_open_file, file_type=lambda: True)

# Deregister the file open handler
deregister_file_open_handler(name="my_file_open_handler")

Register and Deregister Selection Handlers#

from omni.kit.window.content_browser_registry import register_selection_handler, deregister_selection_handler

# Define a selection handler function
def on_selection():
    print("Selection handler invoked!")

# Register a selection handler
register_selection_handler(handler=on_selection)

# Deregister the selection handler
deregister_selection_handler(handler=on_selection)

Register and Deregister Search Delegate#

from omni.kit.window.content_browser_registry import register_search_delegate, deregister_search_delegate

# Define a mock search delegate (assuming SearchDelegate is a valid class)
class MockSearchDelegate:
    def search(self, query):
        print(f"Search delegate invoked with query: {query}")

# Create an instance of the mock search delegate
mock_search_delegate = MockSearchDelegate()

# Register the search delegate
register_search_delegate(search_delegate=mock_search_delegate)

# Deregister the search delegate
deregister_search_delegate(search_delegate=mock_search_delegate)