Python curses 模块,nocbreak() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用curses.nocbreak()

项目:paint-it    作者:plainspooky    | 项目源码 | 文件源码
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()
项目:transmission_scripts    作者:leighmacdonald    | 项目源码 | 文件源码
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    作者:oskar-skog    | 项目源码 | 文件源码
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()
项目:supremm    作者:ubccr    | 项目源码 | 文件源码
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()
项目:Round1    作者:general-ai-challenge    | 项目源码 | 文件源码
def finalize(self):
        curses.nocbreak()
        curses.echo()
        curses.endwin()
项目:I2C-LCD-Display    作者:bradgillap    | 项目源码 | 文件源码
def cleanup():
   curses.nocbreak()
   curses.echo()
   curses.endwin()
   pi.stop()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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()
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _stopWindow(stdscr):
    stdscr.erase()
    stdscr.refresh()
    stdscr.keypad(0)
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
项目:getTimer    作者:maxwellgerber    | 项目源码 | 文件源码
def _cleanup():
    curses.echo()
    curses.curs_set(1)
    curses.nocbreak()
    curses.endwin()
    traceback.print_exc()
项目:captiv8    作者:wraith-wireless    | 项目源码 | 文件源码
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()
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
def __exit__(self, exc_type, exc_val, exc_tb):
        self.window.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
项目:pyfeld    作者:scjurgen    | 项目源码 | 文件源码
def __exit__(self, exc_type, exc_val, exc_tb):
        self.window.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
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)
项目:sandsifter    作者:xoreaxeaxeax    | 项目源码 | 文件源码
def stop(self):
        curses.nocbreak();
        curses.echo()
        curses.endwin()
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def __del__(self):
        """
        Reset terminal before quit.
        """
        curses.nocbreak()
        curses.echo()
        curses.endwin()
项目:cursed    作者:johannestaas    | 项目源码 | 文件源码
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
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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()
项目:pycreate2    作者:MomsFriendlyRobotCompany    | 项目源码 | 文件源码
def __del__(self):
        curses.nocbreak()
        curses.echo()
        curses.endwin()
        # print('done')
项目:gintonic    作者:redahe    | 项目源码 | 文件源码
def close_curses():
    mainwindow.keypad(0)
    curses.echo()
    curses.nocbreak()
    curses.curs_set(2)
    curses.endwin()
项目:AsciiDots-Java    作者:LousyLynx    | 项目源码 | 文件源码
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)
项目:sawtooth-validator    作者:hyperledger-archives    | 项目源码 | 文件源码
def cpstop(self):
        if self.use_curses:
            curses.nocbreak()
            self.scrn.keypad(0)
            curses.echo()
            curses.endwin()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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()
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
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()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:gdax-trader    作者:mcardillo55    | 项目源码 | 文件源码
def close(self):
        if not self.enable:
            return
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin()
项目:wpm    作者:cslarsen    | 项目源码 | 文件源码
def deinit(self):
        curses.nocbreak()
        self.screen.keypad(False)
        curses.echo()
        curses.endwin()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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()
项目:solent    作者:solent-eng    | 项目源码 | 文件源码
def screen_curses_exit():
    global STDSCR
    STDSCR.keypad(0)
    curses.echo()
    curses.nocbreak()
    curses.endwin()
项目:Music-Scraper    作者:srivatsan-ramesh    | 项目源码 | 文件源码
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
项目:youtube_watcher    作者:Sjc1000    | 项目源码 | 文件源码
def shutdown(self):
        curses.echo()
        curses.nocbreak()
        self.screen.keypad(False)
        curses.endwin()
        return None
项目:NEmusicbox    作者:PyCN    | 项目源码 | 文件源码
def start():
    nembox_menu = Menu()
    try:
        nembox_menu.start_fork(version)
    except (OSError, TypeError, ValueError):
        # clean up terminal while failed
        nembox_menu.screen.keypad(1)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
        traceback.print_exc()
项目:odin    作者:imito    | 项目源码 | 文件源码
def run(self):
    try:
      self._run()
    finally:
      try:
        import curses
        curses.echo()
        curses.nocbreak()
        curses.endwin()
      except Exception:
        pass
项目:app    作者:pythonfucku    | 项目源码 | 文件源码
def __del__(self):
        curses.nocbreak(); curses.echo()
        curses.endwin()
项目:app    作者:pythonfucku    | 项目源码 | 文件源码
def show(self):
        t = threading.Thread(target=self.get_data,args=())
        t.setDaemon(True)
        t.start()
        try:
            mainwindow = curses.initscr()
            curses.cbreak(); mainwindow.keypad(1); curses.noecho()
            mainwindow.border(0)
            mainwindow.refresh()
            curses.start_color() 
            curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
            (h,w)= mainwindow.getmaxyx()

            l1= mainwindow.subwin(8,w/2,0,0)
            l1.border(0)

            t1 = threading.Thread(target=self._showdata,args=(l1,))
            t1.setDaemon(True)
            t1.start()

            t1.join()
            t.join()

            mainwindow.addstr(h/2,w/2-15,"RUN OVER,PLEASE ENTER!",curses.color_pair(1))
            mainwindow.getch()

        finally:
            curses.nocbreak(); mainwindow.keypad(0); curses.echo()
            curses.endwin()
项目:ClockBlocker    作者:pinheadmz    | 项目源码 | 文件源码
def cleanup():  
    # reset all this crap to normal terminal settings
    curses.nocbreak()
    curses.echo()
    curses.endwin()
    print "bye!"
项目:ClockBlocker    作者:pinheadmz    | 项目源码 | 文件源码
def cleanup():
    time.sleep(5)

    # undo curses settings
    curses.nocbreak()
    curses.echo()
    curses.endwin()

    matrix.Clear()
    print "bye!"
项目:Otop    作者:fcbarclo    | 项目源码 | 文件源码
def WinCrestoreScr(self):
        if self.VScrStatus == 1:
                    self.VWscreen.keypad(0)

        curses.nocbreak()
        curses.echo()
            curses.endwin()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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()
项目:pubmarine    作者:abadger    | 项目源码 | 文件源码
def __exit__(self, *args):
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin()

        return False
项目:py_wsjtx    作者:teabreakninja    | 项目源码 | 文件源码
def exit_now(self):
        # self.thread_flag = False
        self.stdscr.refresh()

        # end
        curses.nocbreak()
        curses.echo()
        curses.endwin()
项目:connect4    作者:guglielmilo    | 项目源码 | 文件源码
def close():
    curses.nocbreak(); stdscr.keypad(0); curses.echo()
    curses.endwin()
项目:DarkWallet    作者:DissentDifference    | 项目源码 | 文件源码
def finish(screen):
    curses.nocbreak()
    screen.keypad(False)
    curses.echo()
    curses.endwin()
项目:ipmap-creator    作者:ASP-Labs    | 项目源码 | 文件源码
def curses_stop(self):
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin()
项目:Sample-Code    作者:meigrafd    | 项目源码 | 文件源码
def _exit():
    stdscr.keypad(0)
    curses.nocbreak()
    curses.echo()
    curses.endwin()
    GPIO.cleanup()
项目:tscrnsvr    作者:illinoisjackson    | 项目源码 | 文件源码
def destroy(self):
        curses.nocbreak()
        self.win.keypad(0)
        curses.echo()
        curses.endwin()
        curses.curs_set(1)
项目:CommAI-env    作者:facebookresearch    | 项目源码 | 文件源码
def finalize(self):
        curses.nocbreak()
        curses.echo()
        curses.endwin()
项目:unmessage    作者:AnemoneLabs    | 项目源码 | 文件源码
def end_curses(cls):
        curses.nocbreak()
        cls.stdscr.keypad(0)
        curses.echo()
        curses.endwin()
项目:s2e-env    作者:S2E    | 项目源码 | 文件源码
def _cleanup(self):
        curses.nocbreak()
        _s_screen.keypad(0)
        curses.echo()
        curses.endwin()
项目:LinuxBashShellScriptForOps    作者:DingGuodong    | 项目源码 | 文件源码
def tear_down():
    win.keypad(0)
    curses.nocbreak()
    curses.echo()
    curses.endwin()
项目:LinuxBashShellScriptForOps    作者:DingGuodong    | 项目源码 | 文件源码
def tear_down():
    win.keypad(0)
    curses.nocbreak()
    curses.echo()
    curses.endwin()