tree widget
SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- class omni.flux.utils.widget.tree_widget.TreeDelegateBase
Bases:
omni.ui._ui.AbstractItemDelegate
- DEFAULT_IMAGE_ICON_SIZE = 24.000000px
- __init__()
A base Delegate class to be overridden and used with the TreeWidget.
- build_branch(model: _TreeModelBase, item: _TreeItemBase, column_id: int, level: int, expanded: bool)
Create a branch widget that opens or closes the subtree. To define the build function, override _build_branch.
- build_header(column_id: int)
Create a header at the top of the tree. To define the build function, override _build_header.
- build_widget(model: _TreeModelBase, item: _TreeItemBase, column_id: int, level: int, expanded: bool)
Create a widget per item. To define the build function, override _build_widget. This function wraps the widget in a frame with an on-click listener.
- abstract property default_attr: dict[str, None]
- destroy()
- property selection: list['_TreeItemBase']
Get the currently selected items
Return the object that will automatically unsubscribe when destroyed.
- subscribe_item_clicked(function: Callable[[bool, _TreeModelBase, _TreeItemBase], None])
Return the object that will automatically unsubscribe when destroyed.
- subscribe_item_expanded(function)
Return the object that will automatically unsubscribe when destroyed.
- class omni.flux.utils.widget.tree_widget.TreeItemBase(children: Optional[list['TreeItemBase']] = None)
Bases:
omni.ui._ui.AbstractItem
- __init__(children: Optional[list['TreeItemBase']] = None)
A base Item class to be overridden and used with the TreeWidget.
- abstract property can_have_children: bool
- property children: list['TreeItemBase']
- abstract property default_attr: dict[str, None]
- destroy()
- class omni.flux.utils.widget.tree_widget.TreeModelBase
Bases:
omni.ui._ui.AbstractItemModel
,Generic
[omni.flux.utils.widget.tree_widget.model.T
]- __init__()
A base Model class to be overridden and used with the TreeWidget.
- can_item_have_children(self: omni.ui._ui.AbstractItemModel, parentItem: omni.ui._ui.AbstractItem = None) bool
Returns true if the item can have children. In this way the delegate usually draws +/- icon.
### Arguments:
- id :
The item to request children from. If it’s null, the children of root will be returned.
- abstract property default_attr: dict[str, None]
- destroy()
- iter_items_children(items: Optional[Iterable[omni.flux.utils.widget.tree_widget.model.T]] = None, recursive=True) Iterable[omni.flux.utils.widget.tree_widget.model.T]
Iterate through a collection of items’ children
- Parameters
items – The collection of items to get children from
recursive – Whether to get the children recursively or only the direct children
- class omni.flux.utils.widget.tree_widget.TreeWidget(model: _TreeModelBase, delegate: _TreeDelegateBase, select_all_children: bool = True, validate_action_selection: bool = True, **kwargs)
Bases:
omni.ui._ui.TreeView
- __init__(model: _TreeModelBase, delegate: _TreeDelegateBase, select_all_children: bool = True, validate_action_selection: bool = True, **kwargs)
A tree widget that extends the built-in ui.TreeView.
- Parameters
model – The tree widget’s model
delegate – The tree widget’s delegate
select_all_children – Whether the tree should select all children items when selecting a parent item or not
validate_action_selection – Whether the selection should be validated & updated to include the item being right-clicked on or not
kwargs – The same arguments ui.TreeView exposes
- abstract property default_attr: dict[str, None]
- destroy(self: omni.ui._ui.Widget) None
Removes all the callbacks and circular references.
- iter_visible_children(items=None, recursive: bool = True)
Iterate through expanded children of items
- Parameters
items – The collection of items to get children from
recursive – Whether to get the children recursively or only the direct children
- on_selection_changed(items: list[_TreeItemBase])
Function to be called whenever the tree widget selection widget changes (set_selection_changed_fn).
The base implementation selects children when selecting a parent if _select_all_children is True
- Parameters
items – The list of items selected
- subscribe_selection_changed(callback: Callable[[list[_TreeItemBase]], None]) _EventSubscription