-
Notifications
You must be signed in to change notification settings - Fork 0
npyscreen
Widget library and application framework built on top of ncurses. Documentation]
Three main types of object compose npyscreen applications:
- Application objects manage forms and other classes
-
Form objects form the canvas upon which widgets are arrayed
-
Formgeneral-purpose FormMutt
-
-
Widget objects are individual controls
-
TitleTexttext entry -
TitleSelectOneequivalent to radio buttons -
TitleDateComboallows picking of date on a small calendar
-
Main entry point
import npyscreen
def myFunction(*args):
pass
if __name__ == '__main__':
npyscreen.wrapper_basic(myFunction)
print "Blink and you missed it!"Equivalent to the Tk() object, which is typically instantiated as win in GUI frameworks.
F = npyscreen.Form(name='My Test Application')Several important methods are key:
-
create()The standard constructor calls this method, which does nothing by default and is meant to be overriden in subclasses. Widgets are defined here.
FormMutt imitates a UI layout popularized by applications like mutt, irssi, and vim, with a title bar at the top, a command line at the bottom, and a status line directly above the command line.
ACTION_CONTROLLER can be defined in the FormMutt subclass as the name of a subclass of ActionControllerSimple.
Commands for the application can be defined as callbacks in the create() method.
self.add_action(ident,call_back, True)Callbacks are called with the following arguments:
call_back(command_line, control_widget_proxy, live=True)class ActionControllerSearch(npyscreen.ActionControllerSimple):
def create(self):
self.add_action('^/.*', self.set_search, True)
def set_search(self, command_line, widget_proxy, live):
self.parent.value.set_filter(command_line[1:])
self.parent.wMain.values = self.parent.value.get()
self.parent.wMain.display()
class FmSearchActive(npyscreen.FormMuttActiveTraditional):
ACTION_CONTROLLER = ActionControllerSearchPreferred superclass for OO implementation.
class MyApplication(npyscreen.NPSAppManaged):
passCalling run() method of application object as main entry point.
run() activates the default form, which should be given an id of MAIN
if __name__ == '__main__':
TestApp = MyApplication().run()
print "All objects, baby."Using a try/except block to allow for well-mannered exit in case of KeyboardInterrupt (Ctrl+C)GitHub
try:
App().run()
except KeyboardInterrupt:
sys.exit(0)There are three methods for registering a Form object with a NPSAppManaged instance;
-
addForm()creates a new form and returns aweakref.proxyto it -
addFormClass()register a class ofFormrather than an instance registerForm()
It continually displays the Form named by its NEXT_ACTIVE_FORM attribute.
Use the afterEditing method to allow exiting.
class myEmployeeForm(npyscreen.Form):
def afterEditing(self):
self.parentApp.setNextForm(None)- argparse ?
- array ?
- asyncio ?
- bisect ?
- csv ?
- ctypes ?
- curses ?
- datetime ?
- functools ?
- getpass ?
- glob ?
- heapq ?
- http ?
- json ?
- logging ?
- optparse ?
- os ?
- pathlib ?
- platform ?
- pythonnet ?
- random ?
- socket ?
- subprocess ?
- sqlite3 ?
- sys ?
- termcolor ?
- threading ?
- trace ?
- typing ?
- unittest ?
- urllib ?
- venv ?
- weakref ?
- winrm ?