Clearing the contents of a Combo Box

Hello All,

Now this might be something super easy but I have been struggling to figure this out.
I have a Combo box in the Extension that I am building for Managing/Creating variants. This Combo box is responsible for showing all “Variant” Prims in a given USD Stage and the Tree View below it gets populated based on the selection. The problem now is, that when user clicks “Add Variant prim” or makes any change to the stage, I would want to re-populate the Combo Box as well. But for some reason I could not find a simple “clearAll” method on the widget’s “model”. Any Ideas? Even if someone can point me into the direction as to how I can get the total Item count in this model, I can have custom implementation for a “clearAll” method (I guess that is what Nvidia recommends anyways), so far “variantsCombo.model.get_item_children()” and “variantsCombo.model.get_item_value_model_count()” have failed me, but I am guessing that’s not even the right methods to get it.

P.S. I could do this by just verifying and only adding the new prims in the scene if they are a valid “Variant Prim” but there are many more cases where that wouldn’t work.

In general I have never worked with a model-view UI framework in the past, even with Qt I used to mostly deal with widgets, so it might just be my understanding of how models work in general.

Any help would be appreciated, Thank you !!

Regards
Tanay Dimri

Turns out this was just my lack of understanding of how Model-View Controllers work. I had to implement a custom cleaAll method to handle this from the model I was using to populate the combo box.
Posting the dummy code here, in case someone comes across this thread in the future:

class StringItem(ui.AbstractItem):
    def __init__(self, model):
        super().__init__()
        assert isinstance(model, ui.AbstractValueModel)
        self.model = model


class StringModel(ui.AbstractItemModel):
    def __init__(self, variantPrimPaths):
        super().__init__()

        self._current_index = ui.SimpleIntModel()
        self._current_index.add_value_changed_fn(
            lambda a: self._item_changed(None)
            )

        self._items = [
            StringItem(ui.SimpleStringModel(text))
            for text in variantPrimPaths
        ]

    def currentItem(self):
        self._current_item = self._items[self._current_index.get_value_as_int()]
        return self._current_item

    def getCurrentItemIndex(self):
        return self._current_index.get_value_as_int()

    def get_item_children(self, item):
        return self._items

    def get_item_value_model(self, item, column_id):
        if item is None:
            return self._current_index
        return item.model

    def append_child_item(self, parentItem, model):
        self._items.append(StringItem(model))
        self._item_changed(None)

    def clearAllItems(self):
        self._items = []
        self._item_changed(None)

Hope I got this correct and not using a “bad design” here.

Regards
Tanay Dimri

Thanks for sharing. I dunno if you watched the presentation, but the next UI update will include Variant UI controls natively.

1 Like

Hi Daryl,

I did see it in the presentation. Whereas this is more of an exercise where I felt like I could explore the Omnivers Kit API in general. So far, it’s easy to develop for…

Regards
Tanay Dimri

Hi Tanay, I’m very interested in this topic. Can you share your experience in customizing the UI?

How do you get your custom code to execute when Omniverse starts up - did you write an extension or some other means?

Hi Daryl,

Before I begin this response. I am no expert so please take this example as my understanding of how an extension UI should be built for Omniverse :)

I am building a custom extension for this. I started with exploring the extensions that come with Omniverse, understanding how they structure the entire package together. Took a couple of days to get the gist of it and now exploring the details of it. I have attached a minimal UI extension to this reply if that interests you. Simply clone this repo to a Extension search path (I prefer: “…\Documents\Kit\shared\exts”) on your machine and try it out in one of the Omni Apps.

Hope this helps :)

Regards
Tanay Dimri

1 Like