Closed hckr closed 2 years ago
it surely VERY dirty solution, still works though root is SelectionMenu
@melancholiaque Why didn't you just paste the code, instead of taking a picture?
I dunno
пн, 28 окт. 2019 г., 13:13 Jakub Młokosiewicz notifications@github.com:
@melancholiaque https://github.com/melancholiaque Why didn't you just paste the code, instead of taking a picture?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pmbarrett314/curses-menu/issues/37?email_source=notifications&email_token=AISBQRBZBFZWT6TH7QPB7MTQQ3CMBA5CNFSM4FXLFFHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECMQPHQ#issuecomment-546899870, or unsubscribe https://github.com/notifications/unsubscribe-auth/AISBQRG3QJAZ2YHBKNDC3J3QQ3CMBANCNFSM4FXLFFHA .
Hmm, im not sure if im doing this right, can someone tell me what im doing wrong here ( @pmbarrett314 )
class CursesMenu_(CursesMenu):
stdscr = curses.initscr()
class SelectionMenu_(SelectionMenu):
def _wrap_start(self):
if self.parent is None:
curses.wrapper(self._main_loop)
else:
self._main_loop(self.stdscr)
CursesMenu_.currently_active_menu = None
self.stdscr.clear()
self.stdscr.refresh()
CursesMenu_.currently_active_menu = self.previous_active_menu
def selection_menu(items:list, title:str="Select an option", subtitle:str=None, exit_option:bool=True) -> int:
"""
This function displays a selection menu on screen
-> items: list -> The list of strings to display in the menu
-> title: str -> The title of the menu
-> subtitle: str -> The subtitle of the menu
-> exit_option: bool -> If True, the menu will have an exit option
----------------------------------------
=> int -> The index of the selected option
"""
selection = SelectionMenu_.get_selection(strings=items, title=title, subtitle=subtitle, exit_option=exit_option)
return response(True, "Selection", selection)
Even tried this out! Doesn't seem to work :(
CursesMenu.stdscr = curses.initscr()
def _wrap_start(self):
if self.parent is None:
curses.wrapper(self._main_loop)
else:
self._main_loop(self.stdscr)
CursesMenu.currently_active_menu = None
self.stdscr.clear()
self.stdscr.refresh()
CursesMenu.currently_active_menu = self.previous_active_menu
SelectionMenu._wrap_start = _wrap_start
def selection_menu(items:list, title:str="Select an option", subtitle:str=None, exit_option:bool=True) -> int:
"""
This function displays a selection menu on screen
-> items: list -> The list of strings to display in the menu
-> title: str -> The title of the menu
-> subtitle: str -> The subtitle of the menu
-> exit_option: bool -> If True, the menu will have an exit option
----------------------------------------
=> int -> The index of the selected option
"""
selection = SelectionMenu.get_selection(strings=items, title=title, subtitle=subtitle, exit_option=exit_option)
return response(True, "Selection", selection)
Btw, im not exactly using a submenu, im using the SelectionMenu.get_selection() to generate a small menu, and then based on the result, im directly calling another function which contains a SelectionMenu.get_selection() If that helps! Thanks a lot! @pmbarrett314
Submenu is still visible after return if parent has fewer options.
Example code: