我正在使用内置
omni
库为 Omniverse Create 创建自定义扩展。我有一个简单的窗口,它创建一个下拉菜单 (CollapsableFrame
),其中有一个 TreeView
:
self._window = ui.Window("My Window", width = 300, height = 200)
self._items_count = 0
with self._window.frame:
with ui.VStack():
with ui.CollapsableFrame(f'My List {self._items_count} items:', collapsed = True):
tree_view = ui.TreeView(
self._model_all_usd,
root_visible = False,
header_visible = False,
columns_resizable = True,
column_widths = [ui.Fraction(0.4), ui.Fraction(0.3)],
style = {"TreeView.Item": {"margin": 4}})
我还有一个用于监听选择更改的功能:
def _on_stage_event(self, event):
if event.type == int(omni.usd.StageEventType.SELECTION_CHANGED):
// do stuff
self._items_count += 1 # increase count whenever the selection changes
我当前拥有的将更新
self._items_count
值,但下拉文本不会更新。我怎样才能实现这个目标?
只需参考
CollapsableFrame
:
with self._window.frame:
with ui.VStack():
self._dropdown_frame = ui.CollapsableFrame(f'My List {self._items_count} items:', collapsed = True)
with self._dropdown_frame:
tree_view = ui.TreeView(
self._model_all_usd,
root_visible = False,
header_visible = False,
columns_resizable = True,
column_widths = [ui.Fraction(0.4), ui.Fraction(0.3)],
style = {"TreeView.Item": {"margin": 4}})
然后通过修改
title
属性进行更新:
def _on_stage_event(self, event):
if event.type == int(omni.usd.StageEventType.SELECTION_CHANGED):
// do stuff
self._items_count += 1 # Increase count whenever the selection changes
self._dropdown_frame.title = f'My List {self._items_count} items:'