pmbarrett314 / curses-menu

A simple console menu system in python using the curses library
MIT License
475 stars 53 forks source link

Submenu with more elements than parent still visible after return #37

Closed hckr closed 2 years ago

hckr commented 6 years ago

Submenu is still visible after return if parent has fewer options.

cursesmenu

Example code:

from cursesmenu import *
from cursesmenu.items import *
menu = CursesMenu("Title", "Subtitle")
selection_menu = SelectionMenu([ "item{}".format(i) for i in range(20) ])
submenu_item = SubmenuItem("Submenu item", selection_menu, menu)
menu.append_item(submenu_item)
menu.show()
melancholiaque commented 5 years ago

image it surely VERY dirty solution, still works though root is SelectionMenu

hckr commented 5 years ago

@melancholiaque Why didn't you just paste the code, instead of taking a picture?

melancholiaque commented 5 years ago

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 .

skandabhairava commented 2 years ago

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)
skandabhairava commented 2 years ago

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)
skandabhairava commented 2 years ago

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