Usage Examples#

Initialize BrowserBar and Set Path#

from omni.kit.widget.browser_bar import BrowserBar

# Initialize the BrowserBar with custom handlers
browser_bar = BrowserBar(
    visited_history_size=20,
    apply_path_handler=lambda path: print(f"Path applied: {path}"),
    branching_options_handler=lambda path, callback: ["Option1", "Option2"]
)

# Set a path and add it to the history
browser_bar.set_path("/path/to/directory")

Selecting an Item from the Navigation Menu#

from omni.kit.widget.browser_bar import BrowserBar

# Initialize the BrowserBar for demonstration
browser_bar = BrowserBar(
    visited_history_size=20,
    apply_path_handler=lambda path: print(f"Path applied: {path}"),
    branching_options_handler=lambda path, callback: ["Option1", "Option2"]
)

# Adding dummy paths to history for demonstration
browser_bar.set_path("path_one")
browser_bar.set_path("path_two")
browser_bar.set_path("path_three")

# Simulate selecting an item from the navigation menu
menu_item_index = 1  # Index of the item to select from the navigation menu
browser_bar._visited_menu.model.selected_index = menu_item_index

# The path field will be updated to the selected path
selected_path = browser_bar.path
print(f"Selected Path from navigation menu: {selected_path}")
# Expected outputs
# Path applied: path_two
# Current Path after navigating back: path_two/

Clean Up BrowserBar Resources#

from omni.kit.widget.browser_bar import BrowserBar

# Initialize the BrowserBar for demonstration
browser_bar = BrowserBar(
    visited_history_size=20,
    apply_path_handler=lambda path: print(f"Path applied: {path}"),
    branching_options_handler=lambda path, callback: ["Option1", "Option2"]
)

# Assuming 'browser_bar' has already been initialized
# Destroy the BrowserBar to clean up resources
browser_bar.destroy()