StageModel#
- class omni.kit.widget.stage.StageModel(
- stage: Stage,
- flat=False,
- load_payloads=False,
- check_missing_references=False,
- **kwargs,
Bases:
AbstractItemModel
The item model that watches the stage.
Methods
__init__
(stage[, flat, load_payloads, ...])StageModel provides the model for TreeView of Stage Widget, which also manages all StageItems.
can_item_have_children
(item)Checks if the given item can have children.
destroy
()Destroys the instance, notifies column delegates and clear all subs and resources.
drop
(target_item, source[, drop_location])Drop handler called when dropping something to the item.
drop_accepted
(target_item, source[, ...])Called to highlight the target when drag and dropping.
filter
([add, remove, clear])Updates the filter type names and refreshes the stage items with the new filter types.
filter_by_text
(filter_name_text)Filter stage model items by text.
find
(path)Finds the item with the given path if it's populated already.
find_full_chain
(path)Returns the list of all the parent nodes and the node representing the given path.
get_drag_mime_data
(item)Returns MIME (Multipurpose Internet Mail Extensions) data for dropping this item elsewhere.
Return dict of filters.
get_item_children
(item)Gets the sorted children of the given item.
Gets item value model count.
Gets the sort policy for builtin columns.
Gets a list of current selected stage items.
Deprecated.
rename_prim
(prim_path, new_name)Renames a prim to the new name given.
reset
()Forces a full update of items.
set_item_value_model_count
(count)Internal method to set column count.
set_items_sort_key_func
(key_fn[, reverse])Sets the key function to sort item children.
set_items_sort_policy
(items_sort_policy)This is the old way to sort builtin columns (name, type, and visibility), which can only sort one builtin column at a time, and it will clear all existing sort functions customized by `append_column_sort_key_func` and only sort column specified by `items_sort_policy`.
set_selected_stage_items
(selections[, undo])Sets a list of selections.
Subscribe to changes when stage items are destroyed with fn.
Subscribe to changes when stage items are selected or unselected.
Create/remove dirty items that was collected from TfNotice.
Attributes
It will always check missing references now.
Whether to support reorder children by drag and dropping.
Gets the exclusion types.
Whether the model is in flat mode or not.
Gets the item that represents the absolute root.
Whether to show abstract prims.
Instructs stage delegate to show all inactive prims.
Instructs stage delegate to show prim's displayName from USD or path name.
Whether to show prims that have no def.
Gets the stage for the model.
Gets the usd context for the model.
- __init__(
- stage: Stage,
- flat=False,
- load_payloads=False,
- check_missing_references=False,
- **kwargs,
StageModel provides the model for TreeView of Stage Widget, which also manages all StageItems.
- Parameters:
stage (Usd.Stage) – USD stage handle.
- Keyword Arguments:
flat (bool) – If True, all StageItems will be children of the root node. This option only applies to filtering mode.
load_payloads (bool) – Whether payloads should be loaded automatically during stage traversal.
check_missing_references (bool) – Deprecated.
children_reorder_supported (bool) – Whether to enable children reordering for drag and drop. False by default.
show_prim_displayname (bool) – Whether to show prim’s displayName from metadata or path name. False by default.
show_undefined_prims (bool) – Whether to show prims that have no def. False by default.
show_inactive_prims (bool) – Whether to show inactive prims. True by default.
show_abstract_prims (bool) – Whether to show abstract prims. True by default.
- can_item_have_children(
- item: StageItem | None,
Checks if the given item can have children. By default, if can_item_have_children is not provided, it will call get_item_children to get the count of children, so implementing this function to make sure we do lazy load for all items.
- Parameters:
item (Optional[StageItem]) – The item to check.
- Returns:
The result.
- Return type:
bool
- destroy()#
Destroys the instance, notifies column delegates and clear all subs and resources.
- drop(target_item, source, drop_location=-1)#
Drop handler called when dropping something to the item. When drop_location is -1, it means to drop the source item on top of the target item. When drop_location is not -1, it means to drop the source item between items.
- drop_accepted(
- target_item,
- source,
- drop_location=-1,
Called to highlight the target when drag and dropping.
- filter(add=None, remove=None, clear=None) bool #
Updates the filter type names and refreshes the stage items with the new filter types. In most cases we need to filter by several types, so this method allows to add, remove and set the list of types to filter and updates the items if necessary.
- Keyword Arguments:
add (Optional[Dict]) – A dictionary of this form: {“type_name_string”, lambda prim: True}. When lambda is True, the prim will be shown.
remove (Optional[Union[str, Dict, list, set]]) – Removes filters by name if the filter name is in “remove”.
clear – Removes all existing filters. When used with `add`, it will remove existing filters first and then add the newly given ones.
- Returns:
True if the model has filters. False otherwise.
- filter_by_text(filter_name_text)#
Filter stage model items by text. Currently, only single word that’s case-insensitive or prim path are supported.
- Parameters:
filter_name_text (str) – The filter text.
- find(
- path: Path,
Finds the item with the given path if it’s populated already.
- Parameters:
path (Sdf.Path) – Path to find item of.
- Returns:
The found item
- Return type:
- find_full_chain(
- path: Path | str | None,
Returns the list of all the parent nodes and the node representing the given path. If path is empty or there’s no root item, returns None.
- Parameters:
path (Optional[Union[Sdf.Path, str]]) – Path to find item of.
- Returns:
Found items.
- Return type:
List[StageItem]
- get_drag_mime_data(
- item: StageItem,
Returns MIME (Multipurpose Internet Mail Extensions) data for dropping this item elsewhere.
- Parameters:
item (StageItem) – The source item.
- Returns:
The MIME data constructed of item paths.
- Return type:
str
- get_filters() Dict #
Return dict of filters.
- Returns:
The filters dictionary.
- Return type:
Dict
- get_item_children(
- item: StageItem | None,
Gets the sorted children of the given item. Returns the root item when item is None. If filtering is on, will return a filtered list of child items.
- get_item_value_model_count(
- item: StageItem | None,
Gets item value model count.
- Parameters:
item (Optional[StageItem]) – Unused.
- Returns:
The item value model count.
- Return type:
int
- get_items_sort_policy() StageItemSortPolicy #
Gets the sort policy for builtin columns.
- Returns:
The sort policy.
- Return type:
- get_selected_stage_items() List[StageItem] #
Gets a list of current selected stage items.
- Returns:
A list of stage items.
- Return type:
List[StageItem]
- refresh_item_names()#
Deprecated.
- rename_prim(
- prim_path: Path,
- new_name: str,
Renames a prim to the new name given.
- Parameters:
prim_path (Sdf.Path) – The prim path to rename.
new_name (str) – The new name to rename to.
- Returns:
Whether the ranme is performed successfully.
- Return type:
bool
- reset()#
Forces a full update of items.
- set_item_value_model_count(count: int)#
Internal method to set column count.
- Parameters:
count (int) – Count value to set.
- set_items_sort_key_func(
- key_fn: Callable[[StageItem], None],
- reverse=False,
Sets the key function to sort item children.
- Parameters:
key_fn (Callable[[StageItem], None]) – The function that’s used to sort children of item, which be passed to list.sort as key function, for example, `lambda item: item.name`. If `key_fn` is None and `reverse` is True, it will reverse items only. Or if `key_fn` is None and `reverse` is False, it will clear sort function.
reverse (bool) – By default, it’s ascending order to sort with key_fn. If this flag is True, it will sort children in reverse order.
- set_items_sort_policy(
- items_sort_policy: StageItemSortPolicy,
This is the old way to sort builtin columns (name, type, and visibility), which can only sort one builtin column at a time, and it will clear all existing sort functions customized by `append_column_sort_key_func` and only sort column specified by `items_sort_policy`. For more advanced sorting, see function `append_column_sort_key_func`, which supports chaining sort for multiple columns.
- Parameters:
items_sort_policy (StageItemSortPolicy) – The sort policy to set.
- set_selected_stage_items(
- selections: List[StageItem],
- undo=False,
Sets a list of selections.
It also sets selections for omni.kit.selection if this stage model manages the stage from a UsdContext.
- Parameters:
selections (List[StageItem]) – Non-empty selection list to be set.
undo (bool) – If the selection for omni.kit.selection can be undo. Defaults to False.
- subscribe_stage_items_destroyed(
- fn: Callable[[List[StageItem]], None],
Subscribe to changes when stage items are destroyed with fn. Return the object that will automatically unsubscribe when destroyed.
- Parameters:
fn (Callable[[List[StageItem]], None]) – The event handler.
- Returns:
The subscription object.
- Return type:
EventSubscription
- subscribe_stage_items_selection_changed(
- fn: Callable[[], None],
Subscribe to changes when stage items are selected or unselected. Return the object that will automatically unsubscribe when destroyed.
Why StageModel manages its own selection list is because omni.kit.selection only manages those selections that are valid prims. Valid prims are those ones that exist in the stage and active. We also need to support UX for those items that are inactive to do batch operations with them. Therefore, StageModel maintains its own selection list that is iosolated with omni.kit.selection, and it also keeps up with the omni.kit.selection events if necessary.
- Parameters:
fn (Callable[[], None]) – The event handler to notify when selections are changed.
- Returns:
The subscription object.
- Return type:
EventSubscription
- update_dirty()#
Create/remove dirty items that was collected from TfNotice. Can be called at any time to pump changes.
- property check_missing_references#
It will always check missing references now.
- Type:
Deprecated
- property children_reorder_supported: bool#
Whether to support reorder children by drag and dropping.
- Returns:
The setting value.
- Return type:
bool
- property exclusion_types: List[str] | None#
Gets the exclusion types.
- Returns:
The exclusion types if set, else None.
- Return type:
Optional[List[str]]
- property flat: bool#
Whether the model is in flat mode or not. When in flat mode, all items will be the children of the root item, and empty children for other items.
It will return False when show_prim_displayname is True, or when model has not filter text, even if this property is set to True. That means flat mode is currently used for searching only and show_prim_displayname is False.
- property root: StageItem#
Gets the item that represents the absolute root.
- Returns:
The root item.
- Return type:
- property show_abstract_prims: bool#
Whether to show abstract prims.
- Returns:
bool
- property show_inactive_prims: bool#
Instructs stage delegate to show all inactive prims.
- Returns:
bool
- property show_prim_displayname: bool#
Instructs stage delegate to show prim’s displayName from USD or path name.
- Returns:
bool
- property show_undefined_prims: bool#
Whether to show prims that have no def.
- Returns:
bool
- property stage: Stage#
Gets the stage for the model.
- Returns:
The underlying usd stage for the model.
- Return type:
Usd.Stage
- property usd_context: UsdContext#
Gets the usd context for the model.
- Returns:
The underlying usd context for the model.
- Return type:
omni.usd.UsdContext