CursesMenu is a GTK inspired widget engine using curses for use with command line interfaces. Also inspired by the Ubuntu Live Server installation menus.
pip3 install cursesmenu
python3 setup.py install
- Import the package into your script using:
from CursesMenu import *
- Create a new
CursesMenu
object:
myMenu = CursesMenu()
- Create widgets to add to the menu:
#Creates a text widget that gets a string of text as input from the user
textInput = CursesWidget("text", title="My Text Widget", onClose="listWidget")
#Creates a list widget that gets an index and value of a list item from the user
listInput = CursesWidget("list", title="My List Widget", items=["Item 1", "Item 2", "Item 3"])
- Add widgets to the menu:
myMenu.addWidget(textInput, id="root")
myMenu.addWidget(listInput, id="listWidget")
- Draw the menu using Curses:
myMenu.draw()
- Menu object to handle widgets and drawing with curses.
CursesMenu.addWidget(widget, margin=0, id=None)
- Adds a widget to the menu.
- widget: An instance of
CursesWidget
to add to the menu. - margin: Empty space around the widget. Defaults to
0
. - id: Identification for use with the
onClose
property ofCursesWidget
and also forCursesMenu.draw()
.
CursesMenu.quit(
)- Exits curses in the menu. Intended for use within
CursesMenu
class.
- Exits curses in the menu. Intended for use within
CursesMenu.widgetHandler(widget)
- Drawing process for the menu. Intended for use within
CursesMenu
class. - widget: Widget for the handler to draw.
- Drawing process for the menu. Intended for use within
CursesMenu.draw(startWidget="root", inputWin=None)
- Initiates curses and hands off execution to
CursesMenu.widgetHandler()
. - startWidget: ID of the widget to start drawing. Defaults to
"root"
. - inputWin: Curses window object to use for drawing to. Indtended for use with
curses.wrapper()
, but can be used outside ofcurses.wrapper()
. Defaults toNone
.
- Initiates curses and hands off execution to
CursesMenu.widgets
- Python dictionary of widgets with their respective ID's.
- Widget object to handle associated data with a widget.
- type: Type of widget to create. Accepts
"text"
and"list"
. - title: String to display above widget. Defaults to an empty string.
- onClose: String with the ID of a widget added to the same menu to go to after drawing the current widget. Defaults to
None
. - items: For use with
"list"
widget. A Python list of items to be displayed. Converted to strings when displayed. Defaults to an empty list. - hide: Boolean value for whether to hide input. Replaces text input for asterisks if set to
True
. Defaults toFalse
.
CursesWidget.type
- Parameter of original object.
CursesWidget.title
- Parameter of original object.
CursesWidget.id
- Parameter of original object.
CursesWidget.onClose
- Parameter of original object.
CursesWidget.hide
- Parameter of original object.
CursesWidget.data
items
parameter of original object.
CursesWidget.value
- Dependent on
CursesWidget.type
. IfCursesWidget.type == "text"
,CursesWidget.value = {"text": ""}
. IfCursesWidget.type == "list"
,CursesWidget.value = {"text": "", "index": 0}
. Updated duringCursesMenu.widgetHandler()
.
- Dependent on