def get_window_contents():
"""Dump the contents of the current curses window."""
tbox = curses.textpad.Textbox(window)
tbox.stripspaces = False;
w_str = tbox.gather()
return w_str
python类textpad()的实例源码
def __init__( self, x, y, width, height ):
NCursesUI.Window.__init__( self, x, y, width, height )
# put that to the top again from curses.textpad import Textbox
# self.textbox = Textbox( self.win )
# t = threading.Thread()
# t.run = self.textbox.edit
# t.start()
#-------------------------------------------------------------------------#
def __init__(self):
self.swin = curses.newwin(4, 59, 0, 0)
self.inp = curses.newwin(1, 55, 2, 2)
self.text = textpad.Textbox(self.inp, insert_mode=False)
self.history_point = 0
self.search_history = collections.deque(maxlen=100)
def input_n(cursor, scr_bottom, max_stock_range, stock_list, scr_dim):
stock_input = None
curses.start_color()
curses.init_pair(5,curses.COLOR_WHITE,curses.COLOR_BLUE)
stock_win = curses.newwin(1, 10, scr_dim[0]-1, 0)
stock_win.bkgd(curses.color_pair(5))
stock_box = textpad.Textbox(stock_win)
stock_win.refresh()
scr_bottom.addstr(0, curses.COLS-20, " [Enter]Save/Exit")
scr_bottom.refresh()
stock_input = stock_box.edit()
stock_input = stock_input.upper()
if str(stock_input) != "" and str(stock_input) not in stock_list:
stocks.add_stock_code(str(stock_input))
total_stocks = len(stock_list) + 1
if total_stocks > scr_dim[0] - 6:
cursor[1] = total_stocks
cursor[2] = max_stock_range
else:
cursor[1] = max_stock_range + 1
cursor[2] = cursor[1]
elif str(stock_input) or ((str(stock_input)[0:(len(str(stock_input)) - 2)] and str(stock_input)[len(str(stock_input))])) in stock_list:
total_stocks = len(stock_list)
stock_pos = stock_list.index(str(stock_input)) + 1
cursor[1] = stock_pos
if total_stocks > max_stock_range:
cursor[2] = 1
else:
cursor[2] = cursor[1]
return cursor
def __init__(self, stdscr, ui):
CursesHelper.init_curses(stdscr)
self.input_win = self._create_input_window()
self.output_win = self._create_output_window()
self.header_win = self._create_header_window()
self.textpad = None
self.textpad_validator = _Validator(self)
self.ui = ui
self.init_windows()
def init_windows(self):
self.input_win.init()
self.output_win.init()
self.header_win.init()
self.textpad = _Textbox(self.input_win, self.ui)
self.textpad.stripspaces = True
def read_input(self):
return self.textpad.edit(self.textpad_validator.validate).strip()