pylib.tui module

TUI module.

Date

2020-01-13

class App(delay=5)[source]

Bases: object

TUI text-based user interface

initscr is the encapsulation window object of the stdscr stdsc is the curses.initscr

clear()[source]
color_def()[source]
color_table(window=None)[source]

Print all available colors with default background. Check if curses.has_colors() is True.

end()[source]

clean up

getch()[source]
main_loop()[source]
refresh()[source]
class StdOutWrapper[source]

Bases: object

Send print to stdout (print to the standard console).

Example

# catch all prints into StdOutWrapper
with StdOutWrapper() as mystdout:

  # begin curses (curses.initscr(), ...)

  # do your stuff here
  # print("foo")
  # you can also output mystdout.get_text() in a ncurses widget in
  # runtime

  # end curses (curses.endwin())

# go back to normal state and print all catched prints to stdout
get_text()[source]
write(txt)[source]

print uses write()

class Window[source]

Bases: object

border(title='', footer_left='', footer_right='', style='horizontal')[source]

Set border around the window with optional title and footer labels.

Parameters
  • window (curses.window) – the window to draw a border

  • title (str) – the title for the window (default = “”)

  • footer_left (str or list) – the footer label (default = “”). If footer_left is a list than every element of the list will be printed sperated by one column. This is useful to not overwright the border with a space character.

clear()[source]
derwin(height, width, y, x)[source]
getch()[source]
getmaxyx()[source]
initscr()[source]
instr(y, x, n)[source]
refresh()[source]
text(string, padding_left=0, padding_top=0, attribute=0, color_pair=0)[source]

Test to screen. If multiline than keep the x position for each new line.

Example

text(stdscr, 2, 1, "1 - Show test page")
text(stdscr, 3, 1, "h - Show help page")
text(stdscr, 4, 1, "q - Exit")

text(stdscr, 2, 1,
     "1 - Show test page\\n" +
     "h - Show help page\\n" +
     "q - Exit")

Note

Writing in the last char of the window (last row bottom and last column right) is suppressed

textbox(height, width, y, x, borders=False)[source]

Add sub window.

Parameters
  • parent_window (curses.window) – the parent window

  • height (int) – the height of the sub window. The reference point of the sub window is the top left corner.

  • width (int) – the width of the sub window. The reference point of the sub window is the top left corner.

  • y (int) – the y coordinate (position) of the sub window. Start from the top.

  • x – the x coordinate (position) of the sub window. Start from the left.

Returns

the sub window content and decoration

Return type

(curses.window, curses.window)

newwin(height, width, y, x)[source]