Curses Menu - Tma2333/curses_menu GitHub Wiki
Welcome to the curses_menu wiki!
Update:0.2.1
Menu Object
menu.Menu(size_y, size_x, start_y, start_x, box=False, item_num=3, wrap=False)
Constructor, define the basic property of the menu. You need to supply the size of the menu area and starting position (the top left corner) of the menu. The menu will have a boarder if box
is True
. item_num
determine how many menu items you wish to display/configure. If wrap
is True
when you hit Down Arrow in the last (first) item, it will wrap around to the first (last) item. If it is False
, it will stay at the last item. When constructed, the number of default items will be created on top left corner of the menu. They all point to an empty method, and serve only as a place holder.
menu.add_item(num, item_name, mode = 'simple', function = None, start_y = None, start_x = None, breaking = False, menu_obj = None, edit_target = None, edit_verify = None, edit_y = None, edit_x = None)
Use add_item
to add or edit the menu item.
Required Argument:
num
: An integer that represent the number of the item you wish to edit, start with 0.
item_name
: An string that will be displayed as the name of the item.
Keyword Argument:
mode
: Define the functionality of the item. Default to simple mode. Some mode will required to have other keyword argument. It currently support the following mode:
-
simple: A simple item will call the function user supplied when user selected (by pressing 'Enter' key) it.
-
link: A link item will call the
display
method of the menu item user defined in themenu_obj
argument. It can be used to create multi-layer menu. It also make the current becoming the parent menu of the supplied menu. When you exit (by pressing q or use exit item) a child menu, it will return to the parents menu loop. Required keyword argument:menu_obj
-
edit: An edit item allow you to display and edit a supplied variable. When user select an edit item, user can give the supplied variable a new value. It could be used for taking user input or editing configuration of your program. Required keyword argument:
edit_target
-
exit: An exit item allow user to exit the current menu when selected. When user exit the most top layer of menu, it will break out of the display loop and continue to run the rest of the script. When user exit a child menu, it will break out of the display loop and call the parents
display
method.
function
: An callable you wish to be called when user select the item. Currently, it does not support function with any argument (working in progress: allow to pass argument when selected). Default to an empty function in simple mode. Force to the display
method of the supplied menu object in link mode. Force to the _edit
method in edit mode. Force to an empty function in exit mode.
start_y
: An integer represent the starting y-axis coordinate of the item display. Default to the number of the item plus 1.
start_x
: An integer represent the starting x-axis coordinate of the item display. Default to 1.
breaking
: If it is True
, the menu will exit once the item is selected. If it is False
, the menu will continue to run once the item is selected. Default to False
in simple mode. Force to True
in link mode. Force to False
in edit mode. Force to True
in exit mode.
edit_target
: A list that only contain one string. If the item is an edit item, the value of the string will be modified when selected. Required by edit mode.
edit_verify
: Currently, it is a place holder for future implementation of customize function to verify user input value.
edit_y
: An integer represent the starting y-axis coordinate of the edit target display. Default to start_y
.
edit_x
: An integer represent the starting x-axis coordinate of the edit target display. Default to start_x
plus the length of item_name
plus 1.
menu.display ()
Use the method to display the menu. It use the curses.wrapper
to safely handle curses operation.