python类nocbreak()的实例源码

paint-it.py 文件源码 项目:paint-it 作者: plainspooky 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def main():
    game = Game(16)

    while True:
        game.refresh_screen()
        new_color = game.get_key()
        if new_color > 0 and new_color <= COLORS and game.status!='win':
            old_color = game.arena[0][0]
            if new_color != old_color:
                game.moves+=1
                game.paint( [0,0], old_color, new_color)
        elif new_color==-2:
            break
        elif new_color==-1:
            game.display_help()

    game.screen.keypad(False)
    curses.nocbreak()
    curses.echo()
    curses.endwin()

    print('Thanks for playing!')
    exit()
ts_top.py 文件源码 项目:transmission_scripts 作者: leighmacdonald 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def top(args):
    scr = curses.initscr()
    #scr.start_color()
    curses.noecho()
    curses.cbreak()
    hx, wm = scr.getmaxyx()
    scr.keypad(True)
    try:
        header = curses.newwin(HEADER_SIZE, wm, 0, 0)
        body = curses.newwin(BODY_SIZE, wm, HEADER_SIZE, 0)
        while True:
            draw_header(header)
            draw_body(body)
            draw_footer(scr)
            sleep(0.2)
    except KeyboardInterrupt:
        curses.nocbreak()
        scr.keypad(False)
        curses.echo()
        curses.endwin()
anonymine.py 文件源码 项目:anonymine 作者: oskar-skog 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def leave(self):
        '''Leave curses mode.'''
        curses.nocbreak()
        curses.echo()
        self.window.keypad(False)
        try:
            curses.curs_set(self.old_cursor)
        except:
            pass
        curses.endwin()
xdmodstylesetupmenu.py 文件源码 项目:supremm 作者: ubccr 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __exit__(self, exc_type, exc_value, traceback):
        """ reset terminal settings and de-init curses """
        self.stdscr.keypad(0)
        curses.nocbreak()
        curses.echo()
        curses.endwin()
console.py 文件源码 项目:Round1 作者: general-ai-challenge 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def finalize(self):
        curses.nocbreak()
        curses.echo()
        curses.endwin()
gpio_status.py 文件源码 项目:I2C-LCD-Display 作者: bradgillap 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def cleanup():
   curses.nocbreak()
   curses.echo()
   curses.endwin()
   pi.stop()
wrapper.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 36 收藏 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 文件源码 项目:getTimer 作者: maxwellgerber 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _stopWindow(stdscr):
    stdscr.erase()
    stdscr.refresh()
    stdscr.keypad(0)
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
main.py 文件源码 项目:getTimer 作者: maxwellgerber 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _cleanup():
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
    traceback.print_exc()
captiv.py 文件源码 项目:captiv8 作者: wraith-wireless 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def teardown(win):
    """
     returns console to normal state
     :param win: the window
    """
    # tear down the console
    curses.nocbreak()
    if win: win.keypad(0)
    curses.echo()
    curses.endwin()
pfserver.py 文件源码 项目:pyfeld 作者: scjurgen 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __exit__(self, exc_type, exc_val, exc_tb):
        self.window.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
browseRF.py 文件源码 项目:pyfeld 作者: scjurgen 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __exit__(self, exc_type, exc_val, exc_tb):
        self.window.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
sifter.py 文件源码 项目:sandsifter 作者: xoreaxeaxeax 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def cleanup(gui, poll, injector, ts, tests, command_line, args):
    ts.run = False
    if gui:
        gui.stop()
    if poll:
        poll.stop()
    if injector:
        injector.stop()

    '''
    # doesn't work
    if gui:
        for (i, c) in enumerate(gui.orig_colors):
            curses.init_color(i, c[0], c[1], c[2])
    '''

    curses.nocbreak();
    curses.echo()
    curses.endwin()

    dump_artifacts(tests, injector, command_line)

    if args.save:
        with open(LAST, "w") as f:
            f.write(hexlify(cstr2py(tests.r.raw_insn)))

    sys.exit(0)
gui.py 文件源码 项目:sandsifter 作者: xoreaxeaxeax 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def stop(self):
        curses.nocbreak();
        curses.echo()
        curses.endwin()
curses_ui.py 文件源码 项目:huhamhire-hosts 作者: jiangsile 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __del__(self):
        """
        Reset terminal before quit.
        """
        curses.nocbreak()
        curses.echo()
        curses.endwin()
app.py 文件源码 项目:cursed 作者: johannestaas 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run(self):
        '''
        Runs all the windows added to the application, and returns a `Result`
        object.

        '''
        result = Result()
        try:
            self.scr = curses.initscr()
            self.MAX_HEIGHT, self.MAX_WIDTH = self.scr.getmaxyx()
            curses.noecho()
            curses.cbreak()
            curses.start_color()
            curses.use_default_colors()
            self.window = self.scr.subwin(0, 0)
            self.window.keypad(1)
            self.window.nodelay(1)
            self._run_windows()
            self.threads += [gevent.spawn(self._input_loop)]
            gevent.joinall(self.threads)
            for thread in self.threads:
                if thread.exception:
                    result._extract_thread_exception(thread)
        except KeyboardInterrupt:
            result._extract_exception()
        except Exception:
            result._extract_exception()
        finally:
            if self.scr is not None:
                self.scr.keypad(0)
                curses.echo()
                curses.nocbreak()
                curses.endwin()
        return result
wrapper.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 28 收藏 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()
gui.py 文件源码 项目:pycreate2 作者: MomsFriendlyRobotCompany 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __del__(self):
        curses.nocbreak()
        curses.echo()
        curses.endwin()
        # print('done')
gintonic.py 文件源码 项目:gintonic 作者: redahe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def close_curses():
    mainwindow.keypad(0)
    curses.echo()
    curses.nocbreak()
    curses.curs_set(2)
    curses.endwin()
interpreter.py 文件源码 项目:AsciiDots-Java 作者: LousyLynx 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
stats_print.py 文件源码 项目:sawtooth-validator 作者: hyperledger-archives 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def cpstop(self):
        if self.use_curses:
            curses.nocbreak()
            self.scrn.keypad(0)
            curses.echo()
            curses.endwin()
wrapper.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 23 收藏 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()
screen.py 文件源码 项目:sciibo 作者: fdev 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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()
wrapper.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 38 收藏 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()
curses_interface.py 文件源码 项目:gdax-trader 作者: mcardillo55 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def close(self):
        if not self.enable:
            return
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin()
game.py 文件源码 项目:wpm 作者: cslarsen 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def deinit(self):
        curses.nocbreak()
        self.screen.keypad(False)
        curses.echo()
        curses.endwin()
wrapper.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 28 收藏 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()
curses_console.py 文件源码 项目:solent 作者: solent-eng 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def screen_curses_exit():
    global STDSCR
    STDSCR.keypad(0)
    curses.echo()
    curses.nocbreak()
    curses.endwin()
main.py 文件源码 项目:Music-Scraper 作者: srivatsan-ramesh 项目源码 文件源码 阅读 23 收藏 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
ui.py 文件源码 项目:youtube_watcher 作者: Sjc1000 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def shutdown(self):
        curses.echo()
        curses.nocbreak()
        self.screen.keypad(False)
        curses.endwin()
        return None


问题


面经


文章

微信
公众号

扫码关注公众号