Isotropix Forums

Turning a list into a drop-down menu

Clarisse Scripting related topics

Turning a list into a drop-down menu

Unread postby gerdhofer » Mon Mar 02, 2020 7:22 pm

Hello,

I want to equip a script with a floating GUI, waiting for my input. I got everything running, except this one thing:

I have a list, e.g. menu_entries = ["Entry 1", "Entry 2", "Entry 3"] and I want to turn this list into a drop-down menu, where I can choose an option from, e.g. "Entry 2". In this special case, the entries are contexts from the current scene.

I was browsing through the SDK and the forum, but couldn't make this one work so far. Maybe I've just overseen something minor.

Thanks for your support,
Gerd
gerdhofer
 
Posts: 53
Joined: Thu Aug 30, 2018 11:05 am

Re: Turning a list into a drop-down menu

Unread postby anemoff » Tue Mar 03, 2020 11:08 am

Hello,

Here is an example to get you started:

python code

menu_entries = ['Entry 1', 'Entry 2', 'Entry 3']

class ListButtonListener(ix.api.EventObject):

def __init__(self, list_button):
""" Constructor"""

# init parent class EventObject
ix.api.EventObject.__init__(self)
# store the button we are connecting to so that we can reference it later
self.list_button = list_button
# connect the listener (self) to the list selection change event
self.connect(self.list_button, 'EVT_ID_LIST_BUTTON_SELECT', self.on_list_item_selected)

def on_list_item_selected(self, sender, event_id):
"""Event handler for the list button"""

selected_index = self.list_button.get_selected_item_index()
selected_label = self.list_button.get_selected_item_name()
print('Selected entry is: index = {}, label = "{}"'.format(selected_index, selected_label))


def show_custom_gui():
# create the parent window
window = ix.api.GuiWindow(ix.application, 0, 0, 400, 300, "List Button Test")

# create the list button and the entries
list_button = ix.api.GuiListButton(window, 0, 0, 200, 20)
for i, entry in enumerate(menu_entries):
# select the 1st and set the others unselected
selected = True if i == 0 else False
list_button.add_item(entry, selected)

# init list button listener
list_listener = ListButtonListener(list_button)

# show the window and loop until closed
window.show()
while window.is_shown():
ix.application.check_for_events()


# Run it
show_custom_gui()


GuiListButton documentation: https://www.clarissewiki.com/4.0/sdk/cl ... utton.html

Cheers,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: Turning a list into a drop-down menu

Unread postby gerdhofer » Tue Mar 03, 2020 11:26 am

Amazing! Thank you so much for the code. I really didn't think of creating a drop-down list this way.
gerdhofer
 
Posts: 53
Joined: Thu Aug 30, 2018 11:05 am


Return to Scripting