Page 1 of 1

Submenus

Posted: Sun Dec 03, 2017 7:44 pm
by BackRaw
Hello everyone,

how can I add a submenu to a PagedMenu? I've looked in the menus package but I couldn't find anything related to submenus, or, how to attach one to a PagedMenu, at least.

Edit: I know how to do it on my own but I'm wondering whether there is a more SP way to do it other than subclassing the PageMenu class.

Re: Submenus

Posted: Sun Dec 03, 2017 7:56 pm
by Ayuto
Are you looking for something like this?

Syntax: Select all

from menus import PagedMenu
from menus import PagedOption

sub_menu1 = PagedMenu()
sub_menu2 = PagedMenu()

main_menu = PagedMenu(
[
PagedOption('Submenu 1', sub_menu1),
PagedOption('Submenu 2', sub_menu2),
]
)

@main_menu.register_select_callback
def main_menu_select(menu, index, option):
return option.value

Re: Submenus

Posted: Sun Dec 03, 2017 7:59 pm
by BackRaw
Oh so I'm doing it the correct way. Thank you :D

Re: Submenus

Posted: Sun Dec 03, 2017 8:02 pm
by BackRaw
Another question:wouldn't it be better to have a register_close_callback included as well? I can override _select(), but I figure it would be better for SP to provide the mechanism.

Re: Submenus

Posted: Sun Dec 03, 2017 8:13 pm
by Ayuto
Yes, that would be a nice addition. Do you want to create a PR?

Re: Submenus

Posted: Sun Dec 03, 2017 8:16 pm
by BackRaw
I'm on it!

Re: Submenus

Posted: Sun Dec 03, 2017 8:22 pm
by BackRaw
Should it only be called when a player closes the menu or when menu._close() is called on unload and so on as well?

Re: Submenus

Posted: Sun Dec 03, 2017 8:58 pm
by Ayuto
I would only call it when the button has been pressed.

Re: Submenus

Posted: Mon Dec 04, 2017 1:09 am
by BackRaw
Ayuto wrote:I would only call it when the button has been pressed.

Done! :D

Re: Submenus

Posted: Thu Dec 07, 2017 4:50 am
by BackRaw
I have noticed that the Wiki didn't get updated with the close_callback API documentation (http://wiki.sourcepython.com/developing ... radio.html). Is that my fault or is it compiled separately from the plugin builds (build bot)?

Re: Submenus

Posted: Thu Dec 07, 2017 6:19 am
by Ayuto
No, everything is fine. Since a few months we have to update it manually.

Re: Submenus

Posted: Thu Dec 07, 2017 8:26 pm
by BackRaw
Ayuto wrote:No, everything is fine. Since a few months we have to update it manually.

Good to know thanks.