Menu Tree - event.path validation

Good morning,

I'm working on a project where I need to check which item in the MenuTree was clicked. Using event.path, I have the item's index, but when I try to use it in an if statement to trigger an action, nothing happens.

Here's the code:

def runAction(self, event):
    clicked_item_path = event.path
    if clicked_item_path == [0,1]:
        self.getSibling("EmbeddedView").props.path = "View_Moldeo_L1"

Make sure you use the onItemClicked event. Then you can do something like this:

def runAction(self, event):
	if event.enabled: # check if item is enabled
		self.getSibling("EmbeddedView").props.path = event.label
		
		# or if you need custom view paths #

		clicked_item = event.label.lower()
		if clicked_item == "some_string":
			view = "View_Moldeo_L1"
		elif clicked_item == "some_other_string":
			view = "View_Moldeo_L2"
		else:
			return
			
		self.getSibling("EmbeddedView").props.path = view

1 Like

The method you mentioned worked.

Thanks, Hayes.

1 Like

If you did need the full path for some reason, it seems the path value is a pyArray. You might need to cast it to a list for comparison.

if list(event.path) == [0,1]: