def search_mode(self, search_mode):
self._search_mode = search_mode
#if search_mode is True:
# curses.setsyx(0, 0)
# self.scr.clrtoeol()
# s = 'Search for: '
# self.line(s, 0, len(s), color='blue')
# curses.echo()
# curses.curs_set(1)
return self
python类echo()的实例源码
def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().
"""
try:
# Initialize curses
stdscr = curses.initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
curses.noecho()
curses.cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like curses.KEY_LEFT will be returned
stdscr.keypad(1)
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
try:
curses.start_color()
except:
pass
return func(stdscr, *args, **kwds)
finally:
# Set everything back to normal
if 'stdscr' in locals():
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def __del__(self):
curses.nocbreak()
curses.echo()
curses.endwin()
# print('done')
def close_curses():
mainwindow.keypad(0)
curses.echo()
curses.nocbreak()
curses.curs_set(2)
curses.endwin()
def curses_input(self, stdscr, r, c, prompt_string):
curses.echo()
stdscr.addstr(r, c, str(prompt_string), curses.A_REVERSE)
stdscr.addstr(r + 1, c, " " * (curses.COLS - 1))
stdscr.refresh()
input_val = ""
while len(input_val) <= 0:
input_val = stdscr.getstr(r + 1, c, 20)
return input_val
def on_finish(self):
global interpreter
if self.debug and not self.compat_debug:
curses.nocbreak()
self.stdscr.keypad(False)
curses.echo()
curses.endwin()
# sys.exit(0)
def cpstop(self):
if self.use_curses:
curses.nocbreak()
self.scrn.keypad(0)
curses.echo()
curses.endwin()
def get_account(self):
self.screen.timeout(-1) # disable the screen timeout
curses.echo()
account = self.screen.getstr(8, self.startcol + 6, 60)
self.screen.timeout(100) # restore the screen timeout
return account.decode('utf-8')
def get_param(self, prompt_string):
# keep playing info in line 1
curses.echo()
self.screen.move(4, 1)
self.screen.clrtobot()
self.addstr(5, self.startcol, prompt_string,
curses.color_pair(1))
self.screen.refresh()
info = self.screen.getstr(10, self.startcol, 60)
if info == '':
return '/return'
elif info.strip() is '':
return self.get_param(prompt_string)
else:
return info
def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().
"""
try:
# Initialize curses
stdscr = curses.initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
curses.noecho()
curses.cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like curses.KEY_LEFT will be returned
stdscr.keypad(1)
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
try:
curses.start_color()
except:
pass
return func(stdscr, *args, **kwds)
finally:
# Set everything back to normal
if 'stdscr' in locals():
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def create_screen(fn):
"""
Initializes curses and passes a Screen to the main loop function `fn`.
Based on curses.wrapper.
"""
try:
# Make escape key more responsive
os.environ['ESCDELAY'] = '25'
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
stdscr.nodelay(1)
curses.curs_set(0)
curses.mousemask(curses.BUTTON1_CLICKED)
if curses.has_colors():
curses.start_color()
curses.use_default_colors()
screen = Screen(stdscr)
fn(screen)
finally:
# Set everything back to normal
if 'stdscr' in locals():
curses.use_default_colors()
curses.curs_set(1)
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().
"""
try:
# Initialize curses
stdscr = curses.initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
curses.noecho()
curses.cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like curses.KEY_LEFT will be returned
stdscr.keypad(1)
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
try:
curses.start_color()
except:
pass
return func(stdscr, *args, **kwds)
finally:
# Set everything back to normal
if 'stdscr' in locals():
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def __exit__(self, exc_type, exc_val, exc_tb):
# for thread in self.threads:
# thread.join()
curses.noraw()
self.screen.keypad(False)
curses.echo()
curses.endwin()
def close(self):
if not self.enable:
return
curses.nocbreak()
self.stdscr.keypad(0)
curses.echo()
curses.endwin()
def deinit(self):
curses.nocbreak()
self.screen.keypad(False)
curses.echo()
curses.endwin()
def wrapper(func, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
as its first argument, followed by any other arguments passed to
wrapper().
"""
try:
# Initialize curses
stdscr = curses.initscr()
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
curses.noecho()
curses.cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like curses.KEY_LEFT will be returned
stdscr.keypad(1)
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
try:
curses.start_color()
except:
pass
return func(stdscr, *args, **kwds)
finally:
# Set everything back to normal
if 'stdscr' in locals():
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def screen_curses_exit():
global STDSCR
STDSCR.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
def start_gui(process):
"""
A function that takes care of starting the GUI and stops the Scrapy crawler process when exited from program.
:param CrawlerProcess process: The scrapy crawler process that is used to scrape the web. The instance is used for stopping the process.
"""
def create_ui(screen):
"""
A function passes to curses wrapper for safe execution of terminal GUI.
:param screen: The screen parameter to run the GUI. Sent from the curses wrapper.
"""
GUI.screen = screen # All the statis variables of the GUI class is initialized
GUI.strings = [] # the list of songs is empty initially
GUI.init_display() # init the variables required for GUI
GUI.update_on_key() # Starts a loop that waits for key input and acts accordingly
curses.nocbreak()
curses.echo()
curses.endwin()
GUI.gui_stopped = True
curses.wrapper(create_ui)
process.stop() # Stopping the scrapy crawler process
def my_raw_input(r, c, prompt_string):
"""
Gets input on the screen
:param r: y coordinate
:param c: x coordinate
:param prompt_string: The prompt string
:return: The input string
"""
curses.echo()
GUI.box.addstr(r, c, prompt_string, GUI.high_light_text)
GUI.box.refresh()
input_str = GUI.box.getstr(r + 2, c, curses.COLS)
return input_str.decode('UTF-8')
def shutdown(self):
curses.echo()
curses.nocbreak()
self.screen.keypad(False)
curses.endwin()
return None