6.16.1 Textbox objects

Python 2.2

6.16.1 Textbox objects

You can instantiate a Textbox object as follows:

Return a textbox widget object. The win argument should be a curses WindowObject in which the textbox is to be contained. The edit cursor of the textbox is initially located at the upper left hand corner of the containing window, with coordinates (0, 0). The instance's stripspaces flag is initially on.

Textbox objects have the following methods:

This is the entry point you will normally use. It accepts editing keystrokes until one of the termination keystrokes is entered. If validator is supplied, it must be a function. It will be called for each keystroke entered with the keystroke as a parameter; command dispatch is done on the result. This method returns the window contents as a string; whether blanks in the window are included is affected by the stripspaces member.

Process a single command keystroke. Here are the supported special keystrokes:

Keystroke Action
Control-A Go to left edge of window.
Control-B Cursor left, wrapping to previous line if appropriate.
Control-D Delete character under cursor.
Control-E Go to right edge (stripspaces off) or end of line (stripspaces on).
Control-F Cursor right, wrapping to next line when appropriate.
Control-G Terminate, returning the window contents.
Control-H Delete character backward.
Control-J Terminate if the window is 1 line, otherwise insert newline.
Control-K If line is blank, delete it, otherwise clear to end of line.
Control-L Refresh screen.
Control-N Cursor down; move down one line.
Control-O Insert a blank line at cursor location.
Control-P Cursor up; move up one line.

Move operations do nothing if the cursor is at an edge where the movement is not possible. The following synonyms are supported where possible:

Constant Keystroke
KEY_LEFT Control-B
KEY_RIGHT Control-F
KEY_UP Control-P
KEY_DOWN Control-N
KEY_BACKSPACE Control-h

All other keystrokes are treated as a command to insert the given character and move right (with line wrapping).

This method returns the window contents as a string; whether blanks in the window are included is affected by the stripspaces member.

This data member is a flag which controls the interpretation of blanks in the window. When it is on, trailing blanks on each line are ignored; any cursor motion that would land the cursor on a trailing blank goes to the end of that line instead, and trailing blanks are stripped when the window contents are gathered.

See About this document... for information on suggesting changes.