def start(self):
curses.wrapper(self.init)
python类wrapper()的实例源码
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 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 start_ui(self):
curses.wrapper(self._start_ui)
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 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 main():
module = InputModule(ADDRESS, PORT)
curses.wrapper(lambda scr: module.run())
def start(self):
if len(self.options) == 0:
return ""
if len(self.options) == 1:
return self.options[0]
return curses.wrapper(self._start)
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 start_experiment(self):
if self.graph_only:
return
# start pre-configuration commands
for vnf_name, cmd_list in self.pre_config_commands.items():
for cmd in cmd_list:
self.emu.exec(vnf_name=vnf_name, cmd=cmd)
# start overload detection
#if len(self.overload_vnf_list) > 0 :
self.overload_monitor.start(self.emu)
# start the profling loop
self.profiling_thread.start()
if self.no_display == False:
# nicely print values
rows, columns = os.popen('stty size', 'r').read().split()
# Set the Terminal window size larger than its default
# to make sure the profiling results are fitting
if int(rows) < 40 or int(columns) < 130:
sys.stdout.write("\x1b[8;{rows};{cols}t".format(rows=40, cols=130))
# print something to reset terminal
print("")
n = os.system("clear")
# Add a delay to allow settings to settle...
time.sleep(1)
curses.wrapper(self.display_loop)
else:
# wait for profiling thread to end
self.profiling_thread.join()
# stop overload detection
self.overload_monitor.stop(self.emu)
# write results to file
self.write_results_to_file(self.results_file)
#finalize the calculation of the performance profile
self.profile_calc.finalize_graph(show_final=self.no_display)
def __init__(
self,
options,
title='Select',
arrow="-->",
footer="Space = toggle, Enter = accept, q = cancel",
more="...",
border="||--++++",
c_selected="[v]",
c_empty="[ ]"
):
self.title = title
self.arrow = arrow
self.footer = footer
self.more = more
self.border = border
self.c_selected = c_selected
self.c_empty = c_empty
self.all_options = []
for option in options:
self.all_options.append({
"label": option,
"selected": False
})
self.length = len(self.all_options)
self.curses_start()
curses.wrapper(self.curses_loop)
self.curses_stop()
def run(args):
curses.wrapper(main,args)
def run(args):
chars = parse_chars(args.chars)
curses.wrapper(main,args,chars)
def run(args):
curses.wrapper(main,args)
def run(args):
curses.wrapper(main,args)
def run(args):
curses.wrapper(colortest)
def run(args):
curses.wrapper(main,args)
def run(args):
chars = parse_chars(args.chars)
curses.wrapper(main,args,chars)
def run(self):
curses.wrapper(self._wrapped_run)
def start(self):
'''Initializes the context and starts the run loop.'''
curses.wrapper(self._capture_window)