14.7.2 Window Objects

Python 2.5

14.7.2 Window Objects

Window objects, as returned by initscr() and newwin() above, have the following methods:

Note: A character means a C character (an ASCII code), rather then a Python character (a string of length 1). (This note is true whenever the documentation mentions a character.) The builtin ord() is handy for conveying strings to codes.

Paint character ch at (y, x) with attributes attr, overwriting any character previously painter at that location. By default, the character position and attributes are the current settings for the window object.

Paint at most n characters of the string str at (y, x) with attributes attr, overwriting anything previously on the display.

Paint the string str at (y, x) with attributes attr, overwriting anything previously on the display.

Remove attribute attr from the ``background'' set applied to all writes to the current window.

Add attribute attr from the ``background'' set applied to all writes to the current window.

Set the ``background'' set of attributes to attr. This set is initially 0 (no attributes).

Sets the background property of the window to the character ch, with attributes attr. The change is then applied to every character position in that window:
  • The attribute of every character in the window is changed to the new background attribute.
  • Wherever the former background character appears, it is changed to the new background character.

Sets the window's background. A window's background consists of a character and any combination of attributes. The attribute part of the background is combined (OR'ed) with all non-blank characters that are written into the window. Both the character and attribute parts of the background are combined with the blank characters. The background becomes a property of the character and moves with the character through any scrolling and insert/delete line/character operations.

Draw a border around the edges of the window. Each parameter specifies the character to use for a specific part of the border; see the table below for more details. The characters can be specified as integers or as one-character strings.

Note: A 0 value for any parameter will cause the default character to be used for that parameter. Keyword parameters can not be used. The defaults are listed in this table:

Parameter Description Default value
ls Left side ACS_VLINE
rs Right side ACS_VLINE
ts Top ACS_HLINE
bs Bottom ACS_HLINE
tl Upper-left corner ACS_ULCORNER
tr Upper-right corner ACS_URCORNER
bl Bottom-left corner ACS_LLCORNER
br Bottom-right corner ACS_LRCORNER

Similar to border(), but both ls and rs are vertch and both ts and bs are horch. The default corner characters are always used by this function.

Like erase(), but also causes the whole window to be repainted upon next call to refresh().

If yes is 1, the next call to refresh() will clear the window completely.

Erase from cursor to the end of the window: all lines below the cursor are deleted, and then the equivalent of clrtoeol() is performed.

Erase from cursor to the end of the line.

Updates the current cursor position of all the ancestors of the window to reflect the current cursor position of the window.

Delete any character at (y, x).

Delete the line under the cursor. All following lines are moved up by 1 line.

An abbreviation for ``derive window'', derwin() is the same as calling subwin(), except that begin_y and begin_x are relative to the origin of the window, rather than relative to the entire screen. Returns a window object for the derived window.

Add character ch with attribute attr, and immediately call refresh() on the window.

Tests whether the given pair of screen-relative character-cell coordinates are enclosed by the given window, returning true or false. It is useful for determining what subset of the screen windows enclose the location of a mouse event.

Clear the window.

Return a tuple (y, x) of co-ordinates of upper-left corner.

Get a character. Note that the integer returned does not have to be in ASCII range: function keys, keypad keys and so on return numbers higher than 256. In no-delay mode, -1 is returned if there is no input.

Get a character, returning a string instead of an integer, as getch() does. Function keys, keypad keys and so on return a multibyte string containing the key name. In no-delay mode, an exception is raised if there is no input.

Return a tuple (y, x) of the height and width of the window.

Returns the beginning coordinates of this window relative to its parent window into two integer variables y and x. Returns -1,-1 if this window has no parent.

Read a string from the user, with primitive line editing capacity.

Return a tuple (y, x) of current cursor position relative to the window's upper-left corner.

Display a horizontal line starting at (y, x) with length n consisting of the character ch.

If flag is false, curses no longer considers using the hardware insert/delete character feature of the terminal; if flag is true, use of character insertion and deletion is enabled. When curses is first initialized, use of character insert/delete is enabled by default.

If called with yes equal to 1, curses will try and use hardware line editing facilities. Otherwise, line insertion/deletion are disabled.

If flag is true, any change in the window image automatically causes the window to be refreshed; you no longer have to call refresh() yourself. However, it may degrade performance considerably, due to repeated calls to wrefresh. This option is disabled by default.

Return the character at the given position in the window. The bottom 8 bits are the character proper, and upper bits are the attributes.

Paint character ch at (y, x) with attributes attr, moving the line from position x right by one character.

Inserts nlines lines into the specified window above the current line. The nlines bottom lines are lost. For negative nlines, delete nlines lines starting with the one under the cursor, and move the remaining lines up. The bottom nlines lines are cleared. The current cursor position remains the same.

Insert a blank line under the cursor. All following lines are moved down by 1 line.

Insert a character string (as many characters as will fit on the line) before the character under the cursor, up to n characters. If n is zero or negative, the entire string is inserted. All characters to the right of the cursor are shifted right, with the rightmost characters on the line being lost. The cursor position does not change (after moving to y, x, if specified).

Insert a character string (as many characters as will fit on the line) before the character under the cursor. All characters to the right of the cursor are shifted right, with the rightmost characters on the line being lost. The cursor position does not change (after moving to y, x, if specified).

Returns a string of characters, extracted from the window starting at the current cursor position, or at y, x if specified. Attributes are stripped from the characters. If n is specified, instr() returns return a string at most n characters long (exclusive of the trailing NUL).

Returns true if the specified line was modified since the last call to refresh(); otherwise returns false. Raises a curses.error exception if line is not valid for the given window.

Returns true if the specified window was modified since the last call to refresh(); otherwise returns false.

If yes is 1, escape sequences generated by some keys (keypad, function keys) will be interpreted by curses. If yes is 0, escape sequences will be left as is in the input stream.

If yes is 1, cursor is left where it is on update, instead of being at ``cursor position.'' This reduces cursor movement where possible. If possible the cursor will be made invisible.

If yes is 0, cursor will always be at ``cursor position'' after an update.

Move cursor to (new_y, new_x).

Moves the window inside its parent window. The screen-relative parameters of the window are not changed. This routine is used to display different parts of the parent window at the same physical position on the screen.

Move the window so its upper-left corner is at (new_y, new_x).

If yes is 1, getch() will be non-blocking.

If yes is 1, escape sequences will not be timed out.

If yes is 0, after a few milliseconds, an escape sequence will not be interpreted, and will be left in the input stream as is.

Mark for refresh but wait. This function updates the data structure representing the desired state of the window, but does not force an update of the physical screen. To accomplish that, call doupdate().

Overlay the window on top of destwin. The windows need not be the same size, only the overlapping region is copied. This copy is non-destructive, which means that the current background character does not overwrite the old contents of destwin.

To get fine-grained control over the copied region, the second form of overlay() can be used. sminrow and smincol are the upper-left coordinates of the source window, and the other variables mark a rectangle in the destination window.

Overwrite the window on top of destwin. The windows need not be the same size, in which case only the overlapping region is copied. This copy is destructive, which means that the current background character overwrites the old contents of destwin.

To get fine-grained control over the copied region, the second form of overwrite() can be used. sminrow and smincol are the upper-left coordinates of the source window, the other variables mark a rectangle in the destination window.

Writes all data associated with the window into the provided file object. This information can be later retrieved using the getwin() function.

Indicates that the num screen lines, starting at line beg, are corrupted and should be completely redrawn on the next refresh() call.

Touches the entire window, causing it to be completely redrawn on the next refresh() call.

Update the display immediately (sync actual screen with previous drawing/deleting methods).

The 6 optional arguments can only be specified when the window is a pad created with newpad(). The additional parameters are needed to indicate what part of the pad and screen are involved. pminrow and pmincol specify the upper left-hand corner of the rectangle to be displayed in the pad. sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to be displayed on the screen. The lower right-hand corner of the rectangle to be displayed in the pad is calculated from the screen coordinates, since the rectangles must be the same size. Both rectangles must be entirely contained within their respective structures. Negative values of pminrow, pmincol, sminrow, or smincol are treated as if they were zero.

Scroll the screen or scrolling region upward by lines lines.

Controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line. If flag is false, the cursor is left on the bottom line. If flag is true, the window is scrolled up one line. Note that in order to get the physical scrolling effect on the terminal, it is also necessary to call idlok().

Set the scrolling region from line top to line bottom. All scrolling actions will take place in this region.

Turn off the standout attribute. On some terminals this has the side effect of turning off all attributes.

Turn on attribute A_STANDOUT.

Return a sub-window, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines.

Return a sub-window, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines.

By default, the sub-window will extend from the specified position to the lower right corner of the window.

Touches each location in the window that has been touched in any of its ancestor windows. This routine is called by refresh(), so it should almost never be necessary to call it manually.

If called with flag set to true, then syncup() is called automatically whenever there is a change in the window.

Touches all locations in ancestors of the window that have been changed in the window.

Sets blocking or non-blocking read behavior for the window. If delay is negative, blocking read is used (which will wait indefinitely for input). If delay is zero, then non-blocking read is used, and -1 will be returned by getch() if no input is waiting. If delay is positive, then getch() will block for delay milliseconds, and return -1 if there is still no input at the end of that time.

Pretend count lines have been changed, starting with line start.

Pretend the whole window has been changed, for purposes of drawing optimizations.

Marks all lines in the window as unchanged since the last call to refresh().

Display a vertical line starting at (y, x) with length n consisting of the character ch.

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