Navigate Menu Tree with code

On my project, navigation is done using the menu tree, but there is also a home button on the header dock as a short cut to get back to the main page. When the user clicks the home button, they are directed back as expected, but the menu tree doesn’t update. How could I use code to set the selected item in the menu tree?

EDIT:
My menu tree has multiple levels. If I am on level 0, and hit the home button, then there is no problem. If I have drilled into the menu and am now on level 3 of the menu tree, when I hit the home button, the menu tree just stays on level 3. I need to make it go back to level 0.

I would use system.perspective.sendMessage and consider to use page scope to avoid collision in the session (think on multiple tabs in the browser).

Use that function in the shortcut button and let the menu tree to hear the message and set the corresponding prop value.

Assuming you’re changing background color of active tab. You can check for page.props.path is equal to the target path of that item, if it’s equal change the color.

Yes that is how I would do it. The only part I don’t know is what the corresponding prop value is. It doesn’t seem to have one.

That isn’t the issue. I have that part figured out. The problem is that if I have navigated 2 or three levels into the menu tree, then I hit the home button, the menu tree doesn’t go back to level 0.

I have the same issue. Menu Tree has no property or method to drive or force the selected item. We have to post a feature request !

Ohh, I just got your problem. Anyways here is a workaround. I should warn is not supported and is a nasty approach.

On MenuTree Component, I have this Message Handlers Named “resetMenuTree”:

from threading import Timer
def reset(sameAligment):
	self.props.layoutAlignment = sameAligment
currentAligment = self.props.layoutAlignment
newAligment = 'left' if currentAligment == 'right' else 'right'
self.props.layoutAlignment = newAligment
Timer(0.2, reset, [currentAligment]).start()

And on a button I’m just calling the message:

Here is the result

2 Likes

This seems to break the submenus