python类wrapper()的实例源码

watcher.py 文件源码 项目:nanosat-control 作者: ceyzeriat 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def start(self):
        curses.wrapper(self.init)
wrapper.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
wrapper.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()
UICurse.py 文件源码 项目:rogueinabox 作者: rogueinabox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def start_ui(self):
        curses.wrapper(self._start_ui)
wrapper.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
main.py 文件源码 项目:Music-Scraper 作者: srivatsan-ramesh 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
keyboardInput.py 文件源码 项目:Pacbot 作者: HarvardURC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def main():
    module = InputModule(ADDRESS, PORT)
    curses.wrapper(lambda scr: module.run())
pick.py 文件源码 项目:papis 作者: alejandrogallo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def start(self):
        if len(self.options) == 0:
            return ""
        if len(self.options) == 1:
            return self.options[0]
        return curses.wrapper(self._start)
wrapper.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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()
profiler.py 文件源码 项目:son-cli 作者: sonata-nfv 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
maps_creator_term.py 文件源码 项目:ipmap-creator 作者: ASP-Labs 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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()
pipes.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def run(args):
    curses.wrapper(main,args)
stars.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def run(args):
    chars = parse_chars(args.chars)
    curses.wrapper(main,args,chars)
snake.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run(args):
    curses.wrapper(main,args)
clock.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def run(args):
    curses.wrapper(main,args)
colortest.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(args):
    curses.wrapper(colortest)
imgbounce.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(args):
    curses.wrapper(main,args)
matrix.py 文件源码 项目:tscrnsvr 作者: illinoisjackson 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def run(args):
    chars = parse_chars(args.chars)
    curses.wrapper(main,args,chars)
app.py 文件源码 项目:toot 作者: ihabunek 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self):
        curses.wrapper(self._wrapped_run)
context.py 文件源码 项目:simple-reinforcement-learning 作者: google 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def start(self):
    '''Initializes the context and starts the run loop.'''
    curses.wrapper(self._capture_window)


问题


面经


文章

微信
公众号

扫码关注公众号