pylib.tui module

TUI module.

Date

2020-01-10

class StdOutWrapper[source]

Bases: object

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

usage:

# catch all prints into StdOutWrapper
mystdout = StdOutWrapper()
sys.stdout = mystdout
sys.stderr = 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
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
sys.stdout.write(mystdout.get_text())
source:

https://stackoverflow.com/a/14010948

get_text()[source]
text = ''
write(txt)[source]
class TUI(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]
refresh()[source]
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]