How can I dynamically update the dropdown menu text for an Omniverse extension?

252 views Asked by At

I am creating a custom extension for Omniverse Create using the built-in omni library. I have a simple window that creates a dropdown menu (CollapsableFrame) with a TreeView inside of it:

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}})

I also have a function that I am using to listen for selection changes:

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

What I have currently will update the self._items_count value, but the dropdown text does not update. How can I achieve this?

1

There are 1 answers

0
Tony On

Just needed to make a reference to the 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}})

Then update by modifying the title property:

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:'