Submenus

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Submenus

Postby BackRaw » Sun Dec 03, 2017 7:44 pm

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.
Last edited by BackRaw on Sun Dec 03, 2017 7:58 pm, edited 1 time in total.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Submenus

Postby Ayuto » Sun Dec 03, 2017 7:56 pm

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
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Sun Dec 03, 2017 7:59 pm

Oh so I'm doing it the correct way. Thank you :D
Last edited by BackRaw on Sun Dec 03, 2017 8:03 pm, edited 1 time in total.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Sun Dec 03, 2017 8:02 pm

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.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Submenus

Postby Ayuto » Sun Dec 03, 2017 8:13 pm

Yes, that would be a nice addition. Do you want to create a PR?
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Sun Dec 03, 2017 8:16 pm

I'm on it!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Sun Dec 03, 2017 8:22 pm

Should it only be called when a player closes the menu or when menu._close() is called on unload and so on as well?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Submenus

Postby Ayuto » Sun Dec 03, 2017 8:58 pm

I would only call it when the button has been pressed.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Mon Dec 04, 2017 1:09 am

Ayuto wrote:I would only call it when the button has been pressed.

Done! :D
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Thu Dec 07, 2017 4:50 am

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)?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Submenus

Postby Ayuto » Thu Dec 07, 2017 6:19 am

No, everything is fine. Since a few months we have to update it manually.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Submenus

Postby BackRaw » Thu Dec 07, 2017 8:26 pm

Ayuto wrote:No, everything is fine. Since a few months we have to update it manually.

Good to know thanks.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 16 guests