omni.kit.window.filepicker¶
Kit Filepicker Dialog and embeddable Widget.
This Kit extension provides both a popup dialog as well as an embeddable widget that
you can add to your code for browsing the filesystem. Incorporates
BrowserBarWidget
and FileBrowserWidget
into a general-purpose utility.
The filesystem can either be from your local machine or the Omniverse server.
Example
With just a few lines of code, you can create a ready-made dialog window. Then, customize it by setting any number of attributes.
- filepicker = FilePickerDialog(
“my-filepicker”, apply_button_label=”Open”, click_apply_handler=on_click_open, click_cancel_handler=on_click_cancel )
filepicker.show()
-
class
omni.kit.window.filepicker.
FilePickerDialog
(title: str, **kwargs)¶ Bases:
object
A popup window for browsing the filesystem and taking action on a selected file. Includes a browser bar for keyboard input with auto-completion for navigation of the tree view. For similar but different options, see also
FilePickerWidget
andFilePickerView
.- Parameters
title (str) – Window title. Default None.
- Keyword Arguments
width (int) – Window width. Default 1000.
height (int) – Window height. Default 600.
click_apply_handler (func) – Function that will be called when the user accepts the selection. Function signature: void apply_handler(file_name: str, dir_name: str).
click_cancel_handler (func) – Function that will be called when the user clicks the cancel button. Function signature: void cancel_handler(file_name: str, dir_name: str).
other – Additional args listed for
FilePickerWidget
-
add_connections
(connections: dict)¶ Adds specified server connections to the browser.
- Parameters
connections (dict) – A dictionary of name, path pairs. For example: {“C:”: “C:”, “ov-content”: “omniverse://ov-content”}. Paths to Omniverse servers should be prefixed with “omniverse://”.
-
property
current_filter_option
¶ Index of current filter option, range 0 .. num_filter_options.
- Type
-
destroy
()¶ Destructor.
-
get_current_directory
() → str¶ Returns the current directory fom the browser bar.
- Returns
The system path, which may be different from the displayed path.
- Return type
-
get_current_selections
(pane: int = 2) → List[str]¶ Returns current selected as list of system path names.
-
hide
()¶ Hides this dialog. Automatically called when “Cancel” buttons is clicked.
Navigates to a path, i.e. the path’s parent directory will be expanded and leaf selected.
- Parameters
path (str) – The path to navigate to.
-
refresh_current_directory
()¶ Refreshes the current directory set in the browser bar.
-
set_current_directory
(path: str)¶ Procedurally sets the current directory path.
- Parameters
path (str) – The full path name of the folder, e.g. “omniverse://ov-content/Users/me.
- Raises
RuntimeWarning – If path doesn’t exist or is unreachable.
-
set_filename
(filename: str)¶ Sets the filename in the file bar, at bottom of the dialog.
- Parameters
filename (str) – The filename only (and not the fullpath), e.g. “myfile.usd”.
-
show
(path: str = None)¶ Shows this dialog. Currently pops up atop all other windows but is not completely modal, i.e. does not take over input focus.
- Parameters
path (str) – If optional path is specified, then navigates to it upon startup.
-
class
omni.kit.window.filepicker.
FilePickerWidget
(title: str, **kwargs)¶ Bases:
object
An embeddable UI widget for browsing the filesystem and taking action on a selected file. Includes a browser bar for keyboard input with auto-completion for navigation of the tree view. For similar but different options, see also
FilePickerDialog
andFilePickerView
.- Parameters
title (str) – Widget title. Default None.
- Keyword Arguments
layout (int) – The overall layout of the window, one of: {LAYOUT_SPLIT_PANES, LAYOUT_SINGLE_PANE_SLIM, LAYOUT_SINGLE_PANE_WIDE, LAYOUT_DEFAULT}. Default LAYOUT_SPLIT_PANES.
current_directory (str) – View is set to display this directory. Default None.
current_filename (str) – Filename is set to this value. Default None.
splitter_offset (int) – Position of vertical splitter bar. Default 300.
show_grid_view (bool) – Displays grid view in the intial layout. Default True.
grid_view_scale (int) – Scales grid view, ranges from 0-5. Default 2.
show_only_collections ([str]) – List of collections to display, any combination of [“bookmarks”, “omniverse”, “my-computer”]. If None, then all are displayed. Default None.
allow_multi_selection (bool) – Allows multiple selections. Default False.
click_apply_handler (func) – Function that will be called when the user accepts the selection. Function signature: void apply_handler(file_name: str, dir_name: str).
click_cancel_handler (func) – Function that will be called when the user clicks the cancel button. Function signature: void cancel_handler(file_name: str, dir_name: str).
apply_button_label (str) – Alternative label for the apply button. Default “Okay”.
enable_file_bar (bool) – Enables/disables file bar. Default True.
enable_filename_input (bool) – Enables/disables filename input. Default True.
item_filter_options ([str]) – A list of filter options to determine which files should be listed. For example: [‘usd’, ‘wav’]. Default None.
item_filter_fn (func) – This user function should return True if the given tree view item is visible, False otherwise. To base the decision on which filter option is currently chosen, use the attribute filepicker.current_filter_option. Function signature: bool item_filter_fn(item:
FileBrowserItem
)error_handler (func) – This function is called with error messages when appropriate. It provides the calling app a way to display errors on top of writing them to the console window. Function signature: void error_handler(message: str).
show_real_path (bool) – Browser bar display system paths only, no aliased paths. Default True.
-
property
api
¶ Provides API methods to this widget.
- Type
-
property
current_filter_option
¶ Index of current filter option, range 0 .. num_filter_options.
- Type
-
destroy
()¶ Destructor.
-
class
omni.kit.window.filepicker.
FilePickerView
(title: str, **kwargs)¶ Bases:
object
An embeddable UI component for browsing the filesystem. This widget is more full-functioned than
FileBrowserWidget
but less so thanFilePickerWidget
. More specifically, this is one of the 3 sub-components of its namesakeFilePickerWidget
. The difference is it doesn’t have the Browser Bar (at top) or the File Bar (at bottom). This gives users the flexibility to substitute in other surrounding components instead.- Parameters
title (str) – Widget title. Default None.
- Keyword Arguments
layout (int) – The overall layout of the window, one of: {LAYOUT_SPLIT_PANES, LAYOUT_SINGLE_PANE_SLIM, LAYOUT_SINGLE_PANE_WIDE, LAYOUT_DEFAULT}. Default LAYOUT_SPLIT_PANES.
splitter_offset (int) – Position of vertical splitter bar. Default 300.
show_grid_view (bool) – Display grid view in the intial layout. Default True.
grid_view_scale (int) – Scales grid view, ranges from 0-5. Default 2.
show_only_collections (list[str]) – List of collections to display, any combination of [“bookmarks”, “omniverse”, “my-computer”]. If None, then all are displayed. Default None.
tooltip (bool) – Display tooltips when hovering over items. Default True.
allow_multi_selection (bool) – Allow multiple items to be selected at once. Default False.
mouse_pressed_fn (func) – Function called on mouse press. Function signature: void mouse_pressed_fn(pane: int, button: int, key_mode: int, item:
FileBrowserItem
)mouse_double_clicked_fn (func) – Function called on mouse double click. Function signature: void mouse_double_clicked_fn(pane: int, button: int, key_mode: int, item:
FileBrowserItem
)selection_changed_fn (func) – Function called when selection changed. Function signature: void selection_changed_fn(pane: int, selections: list[
FileBrowserItem
])drop_handler (func) – Function called to handle drag-n-drops. Function signature: void drop_fn(dst_item:
FileBrowserItem
, src_paths: [str])add_server_post_handler (func) – This handler is called whenever a server connection is added. A primary use of this callback is to update settings files or similar bookkeeping. Function signature: void add_server_post_handler(name: str, path: str).
delete_server_post_handler (func) – This handler is called whenever a server connection is deleted. A primary use of this callback is to update settings files or similar bookkeeping. Function signature: void delete_server_post_handler(name: str, path: str).
item_filter_fn (func) – This handler should return True if the given tree view item is visible, False otherwise. Function signature: bool item_filter_fn(item:
FileBrowserItem
)thumbnail_provider (func) – This callback provides a thumbnail to replace the default in the grid view. Signature str thumbnail_provider(item:
FileBrowserItem
, retry: bool)icon_provider (func) – This callback provides an icon to replace the default in the tree view. Signature str icon_provider(item:
FileBrowserItem
)badges_provider (func) – This callback provides the list of badges to layer atop the thumbnail in the grid view. Callback signature: [str] badges_provider(item:
FileBrowserItem
)error_handler (func) – This function is called with error messages when appropriate. It provides the calling app a way to display errors. Function signature: void error_handler(message: str).
-
add_bookmark_with_callback
(name: str, path: str, callback: Callable) → omni.kit.widget.filebrowser.model.FileBrowserModel¶ Creates a
FileBrowserModel
rooted at the given path, and connects its subtree to the tree view.- Parameters
name (str) – Name of the bookmark.
path (str) – Fullpath of the connection, e.g. “omniverse://ov-content”. Paths to Omniverse servers should contain the prefix, “omniverse://”.
callback (func) – Invokes this callback upon success. A typical use is to update settings. Function signature: void callback(name: str, path: str).
- Returns
FileBrowserModel
-
add_server_with_callback
(name: str, path: str, callback: Callable) → omni.kit.widget.filebrowser.model.FileBrowserModel¶ Creates a
FileBrowserModel
rooted at the given path, and connects its subtree to the tree view.- Parameters
name (str) – Name, label really, of the connection.
path (str) – Fullpath of the connection, e.g. “omniverse://ov-content”. Paths to Omniverse servers should contain the prefix, “omniverse://”.
callback (func) – Invokes this callback upon success. A typical use is to update saved settings. Function signature: void callback(name: str, path: str).
- Returns
FileBrowserModel
- Raises
RuntimeWarning – If unable to add server.
-
all_connections
(collection: str = None) → [<class ‘str’>]¶ Returns all connection names for the specified collection.
-
property
collections
¶ Dictionary of collections, e.g. ‘bookmarks’, ‘omniverse’, ‘my-computer’.
- Type
-
delete_bookmark_with_callback
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, callback: Callable)¶ Deletes the given bookmark.
- Parameters
item (
FileBrowserItem
) – Bookmark item.callback (func) – Invokes this callback upon success. A typical use is to update settings. Function signature: void callback(name: str, path: str).
-
delete_server_with_callback
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, callback: Callable)¶ Disconnects the subtree rooted at the given item.
- Parameters
item (
FileBrowserItem
) – Root of subtree to disconnect.callback (func) – Invokes this callback upon success. A typical use is to update settings. Function signature: void callback(name: str, path: str).
-
get_item_children
(item: omni.kit.widget.filebrowser.model.FileBrowserItem)¶ Returns list of children for specified item.
- Parameters
item (
FileBrowserItem
) – Parent item.- Returns
[
FileBrowserItem
]
-
get_root
(pane: int = None) → omni.kit.widget.filebrowser.model.FileBrowserItem¶ Returns the root item of the specified pane.
- Parameters
pane (int) – One of {TREEVIEW_PANE, LISTVIEW_PANE}.
-
get_selections
(pane: int = None) → [<class ‘omni.kit.widget.filebrowser.model.FileBrowserItem’>]¶ Returns list of currently selected items.
- Parameters
pane (int) – One of {TREEVIEW_PANE, LISTVIEW_PANE}.
- Returns
list[
FileBrowserItem
]
-
has_connection_with_name
(name: str, collection: str = None) → bool¶ Returns True if speficied connection exists within the collection.
-
is_bookmark
(item: omni.kit.widget.filebrowser.model.FileBrowserItem) → bool¶ Returns true if given item is a bookmarked item.
- Parameters
item (
FileBrowserItem
) – Item in question.- Returns
bool
-
is_connection_point
(item: omni.kit.widget.filebrowser.model.FileBrowserItem) → bool¶ Returns true if given item is a direct child of a collection node.
- Parameters
item (
FileBrowserItem
) – Item in question.- Returns
bool
-
mount_user_folders
(folders: dict)¶ Mounts given set of user folders under the local collection.
- Parameters
folders (dict) – Name, path pairs.
-
reconnect_server
(item: omni.kit.widget.filebrowser.model.FileBrowserItem)¶ Reconnects the server at the given path. Clears out any cached authentication tokens to force the action.
- Parameters
item (
FileBrowserItem
) – Connection item.
-
refresh_ui
(item: omni.kit.widget.filebrowser.model.FileBrowserItem = None)¶ Redraws the subtree rooted at the given item. If item is None, then redraws entire tree.
- Parameters
item (
FileBrowserItem
) – Root of subtree to redraw. Default None, i.e. root.
-
rename_bookmark_with_callback
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, new_name: str, callback: Callable)¶ Renames the bookmark item. Note: doesn’t change the connection itself, only how it’s labeled in the tree view.
- Parameters
item (
FileBrowserItem
) – Bookmark item.new_name (str) – New name.
callback (func) – Invokes this callback upon success. A typical use is to update settings. Function signature: void callback(name: str, path: str, old_name: str).
-
rename_server_with_callback
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, new_name: str, callback: Callable)¶ Renames the connection item. Note: doesn’t change the connection itself, only how it’s labeled in the tree view.
- Parameters
item (
FileBrowserItem
) – Root of subtree to disconnect.new_name (str) – New name.
callback (func) – Invokes this callback upon success. A typical use is to update settings. Function signature: void callback(name: str, path: str, old_name: str).
-
select_and_center
(item: omni.kit.widget.filebrowser.model.FileBrowserItem)¶ Selects and centers the view on the given item, expanding the tree if needed.
- Parameters
item (
FileBrowserItem
) – The selected item.
-
show_model
(model: omni.kit.widget.filebrowser.model.FileBrowserModel)¶ Displays the model on the right side of the split pane
-
class
omni.kit.window.filepicker.
FilePickerModel
(theme='NvidiaDark', timeout=3.0)¶ Bases:
object
The model class for
FilePickerWidget
.-
add_saved_connection
(name: str, path: str)¶ When a connection is added, update the settings dictionary.
-
assert_settings_name_exists
(settings_name: str)¶ Checks that specified setting exists. If not, then create empty placeholder.
- Parameters
settings_name (str) – Name of the setting.
-
property
collections
¶ The collections loaded for this widget
- Type
[
FileBrowseItem
]
-
create_folder_with_callback
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, folder_name: str, callback: Callable = None)¶ Creates folder under given item. Upon success, executes the given callback.
-
delete_items_with_callback
(items: [<class 'omni.kit.widget.filebrowser.model.FileBrowserItem'>], callback: Callable = None)¶ Deletes given items. Upon success, executes the given callback.
- Parameters
items ([
FileBrowserItem
]) – Items to delete.callback (func) – Callback to execute upon success. Function signature is void callback([str]).
- Raises
-
delete_saved_bookmark
(name: str, path: str)¶ When a connection is deleted, update the settings dictionary.
-
delete_saved_connection
(name: str, path: str)¶ When a connection is deleted, update the settings dictionary.
-
filter_item
(item: omni.kit.widget.filebrowser.model.FileBrowserItem) → bool¶ Default item filter callback. Returning True displays the item.
- Parameters
item (
FileBrowseritem
) – Item in question.- Returns
bool
-
find_item_from_path
(path: str) -> (<class 'omni.kit.widget.filebrowser.model.FileBrowserItem'>, <class 'omni.kit.widget.filebrowser.model.FileBrowserItem'>)¶ Helper function to search given subtree and return item with matching path name.
- Parameters
path (str) – Path of item to search for.
- Returns
Tuple(
FileBrowserItem
,FileBrowserItem
) First element of tuple is the item found; second is the collection that the item was found in.
-
get_asset_type
(item: omni.kit.widget.filebrowser.model.FileBrowserItem) → str¶ Returns asset type of given item.
- Parameters
item (
FileBrowseritem
) – Item in question.- Returns
str
-
get_badges
(item: omni.kit.widget.filebrowser.model.FileBrowserItem) → List[str]¶ Returns fullpaths to badges for given item. Override this method to implement custom badges.
- Parameters
item (
FileBrowseritem
) – Item in question.- Returns
[str]
-
get_displayed_path
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, path: str = '') → str¶ Returns displayed path, as opposed to the system path. I.e. this is the path derived by traversing from the root of the tree view to the given item. The tree view path may be different from the system path if some folder names are aliased, e.g. symbolic links.
- Parameters
item (FileBrowserItem) – Specified item.
path (str, optional) – Path should be left empty initially and extended recursively.
- Returns
str
-
get_icon
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, expanded: bool) → str¶ Returns fullpath to icon for given item. Override this method to implement custom icons.
- Parameters
item (
FileBrowseritem
) – Item in question.expanded (bool) – True if item is expanded.
- Returns
str
-
get_thumbnail
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, local_only: bool) -> (<class 'str'>, <class 'bool'>)¶ Returns fullpath to thumbnail for given item. Override this method to implement custom thumbnails.
-
is_asset_type
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, asset_type: str) → bool¶ Returns True if given item is of specified type.
- Parameters
item (
FileBrowseritem
) – Item in question.asset_type (str) – Tested type name.
- Returns
bool
-
register_file_extensions
(asset_type: str, exts: [<class 'str'>], replace: bool = False)¶ Adds an asset type to the recognized list.
-
rename_saved_bookmark
(name: str, path: str, prev_name: str)¶ When a connection is deleted, update the settings dictionary.
-
-
class
omni.kit.window.filepicker.
FilePickerAPI
(model: omni.kit.window.filepicker.model.FilePickerModel = None, view: omni.kit.window.filepicker.view.FilePickerView = None)¶ Bases:
object
This class defines the API methods for
FilePickerWidget
.-
add_connections
(connections: dict)¶ Adds specified server connections to the tree browser. To facilitate quick startup time, doesn’t check whether the connection is actually valid.
- Parameters
connections (dict) – A dictionary of name, path pairs. For example: {“C:”: “C:”, “ov-content”: “omniverse://ov-content”}. Paths to Omniverse servers should be prefixed with “omniverse://”.
Adds menu item, with corresponding callbacks, to the context menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’), this name must be unique across the context menu.
glyph (str) – Associated glyph to display for this menu item.
click_fn (func) – This callback function is executed when the menu item is clicked. Function signature: void fn(name: str, path: str), where name is menu name and path is absolute path to clicked item.
show_fn (func) – Returns True to display this menu item. Function signature: bool fn(path: str). For example, test filename extension to decide whether to display a ‘Play Sound’ action.
- Returns
Name of menu item if successful, None otherwise.
- Return type
Adds menu item, with corresponding callbacks, to the list view menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’), this name must be unique across the list view menu.
glyph (str) – Associated glyph to display for this menu item.
click_fn (func) – This callback function is executed when the menu item is clicked. Function signature: void fn(name: str, path: str), where name is menu name and path is absolute path to clicked item.
show_fn (func) – Returns True to display this menu item. Function signature: bool fn(path: str). For example, test filename extension to decide whether to display a ‘Play Sound’ action.
- Returns
Name of menu item if successful, None otherwise.
- Return type
Deletes the menu item, with the given name, from the context menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’).
Deletes the menu item, with the given name, from the list view menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’).
-
get_current_directory
() → str¶ Returns the current directory fom the browser bar.
- Returns
The system path, which may be different from the displayed path.
- Return type
-
get_current_selections
(pane: int = 2) → List[str]¶ Returns current selected as list of system path names.
-
get_subdirs_from_path
(path: str) → List[str]¶ Returns list of subdirectories for given path.
- Parameters
path (str) – Path.
Navigates to a path, i.e. the path’s parent directory will be expanded and leaf selected. This method is used to process the path coming from the browser bar.
- Parameters
path (str) – The path to navigate to.
-
refresh_current_directory
()¶ Refreshes the current directory set in the browser bar.
-
set_current_directory
(path: str)¶ Procedurally sets the current directory. Use this method to set the path in the browser bar.
- Parameters
path (str) – The full path name of the folder, e.g. “omniverse://ov-content/Users/me.
- Raises
RuntimeWarning – If path doesn’t exist or is unreachable.
-
set_filename
(filename: str)¶ Sets the filename in the file bar, at bottom of the dialog. The file is not required to already exist.
- Parameters
filename (str) – The filename only (and not the fullpath), e.g. “myfile.usd”.
-
subscribe_bookmarks_settings_changed
()¶ Updates bookmarks when settings changed.
-
subscribe_connections_settings_changed
()¶ Updates connections when settings changed.
-
-
class
omni.kit.window.filepicker.
ContextMenu
(**kwargs)¶ Bases:
object
Creates popup menu for the hovered FileBrowserItem. In addition to the set of default actions below, users can add more via the add_menu_item API.
- Keyword Arguments
rename_item_fn – void rename_item(item: FileBrowserItem, new_name: str). Default None.
create_folder_fn – void create_folder(item: FileBrowserItem, name: str). Default None.
add_bookmark_fn – void add_bookmark(item: FileBrowserItem, name: str). Default None.
delete_bookmark_fn – void delete_bookmark(item: FileBrowserItem). Default None.
delete_items_fn – void delete_items(items: [FileBrowserItem]). Default None.
reconnect_server_fn – void reconnect_server(item: FileBrowserItem). Default None.
remove_connection_fn – void remove_connection(item: FileBrowserItem). Default None.
refresh_item_fn – void refresh_item(item: FileBrowserItem). Default None.
Adds menu item, with corresponding callbacks, to this context menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’), this name must be unique across the context menu.
glyph (str) – Associated glyph to display for this menu item.
onclick_fn (func) – This callback function is executed when the menu item is clicked. Function signature: void fn(name: str, path: str), where name is menu name and path is absolute path to clicked item.
show_fn (func) – Returns True to display this menu item. Function signature: bool fn(path: str). For example, test filename extension to decide whether to display a ‘Play Sound’ action.
- Returns
Name of menu item if successful, None otherwise.
- Return type
-
property
context
¶ Provides data to the callback. Available keys are {‘item’, ‘is_bookmark’, ‘is_connection’, ‘selected’}
- Type
Deletes the menu item, with the given name, from this context menu.
- Parameters
name (str) – Name of the menu item (e.g. ‘Open’).
omni.ui.Menu
The menu widget
-
show
(item: omni.kit.widget.filebrowser.model.FileBrowserItem, is_bookmark: bool = False, is_connection_point: bool = False, selected: [<class 'omni.kit.widget.filebrowser.model.FileBrowserItem'>] = [])¶ Creates the popup menu from definition for immediate display. Receives as input, information about the item. These values are made available to the callback via the ‘context’ dictionary.
- Parameters
item (FileBrowseritem) – Item for which to create menu.,
is_bookmark (bool) – True if this item is a bookmark. Default False.
is_connection_point (bool) – True if item is a connection point. Default False.
selected ([FileBrowserItem]) – List of currently selected items. Default [].