當前位置: 首頁>>代碼示例>>Python>>正文


Python curses.wrapper方法代碼示例

本文整理匯總了Python中curses.wrapper方法的典型用法代碼示例。如果您正苦於以下問題:Python curses.wrapper方法的具體用法?Python curses.wrapper怎麽用?Python curses.wrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在curses的用法示例。


在下文中一共展示了curses.wrapper方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: initscr

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
# COLOR_PAIRS variables which are only available after start_color() is
# called. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:__init__.py

示例2: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main():
        """
        If a project has a Curses driver, the section "main" in the section
        "run" must be "bibliopixel.drivers.curses.Curses.main".

        """
        if not _curses:
            # https://stackoverflow.com/a/1325587/43839
            if os.name == 'nt':
                raise ValueError('curses is not supported under Windows')
            raise ValueError('Your platform does not support curses.')
        try:
            driver = next(iter(Curses.DRIVERS))
        except:
            raise ValueError('No Curses driver in project')

        _curses.wrapper(driver.run_in_curses) 
開發者ID:ManiacalLabs,項目名稱:BiblioPixel,代碼行數:19,代碼來源:curses.py

示例3: wrapper_basic

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def wrapper_basic(call_function):
    #set the locale properly
    locale.setlocale(locale.LC_ALL, '')
    return curses.wrapper(call_function)

#def wrapper(call_function):
#   locale.setlocale(locale.LC_ALL, '')
#   screen = curses.initscr()
#   curses.noecho()
#   curses.cbreak()
#   
#   return_code = call_function(screen)
#   
#   curses.nocbreak()
#   curses.echo()
#   curses.endwin() 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:18,代碼來源:npyssafewrapper.py

示例4: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main():
    args = parse_args()
    log.info('Requesting remote shell from {}', args.hostname)
    with PenguinDomeServerPeer(
            'server', local_port=get_setting('local_port'),
            logger=log, client_hostname=args.hostname) as remote, \
            TerminalPeer() as terminal:
        host = args.hostname
        script = '#!/bin/bash\npython client/endpoints/shell.py {}\n'.format(
            remote.pipe_id)
        patch_hosts('client/commands/shell-{}'.format(remote.pipe_id),
                    patch_content=script.encode('utf8'),
                    hosts=host)
        broker = InteractionBroker(terminal, remote, poll_interval=0.2)
        print('Waiting for client to connect (once connected, use "~." to '
              'disconnect)...')
        remote.poll()
        curses.wrapper(interact, broker) 
開發者ID:quantopian,項目名稱:PenguinDome,代碼行數:20,代碼來源:client_shell.py

示例5: run_ci

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def run_ci():
    locale.setlocale(locale.LC_ALL, '')
    try:
        # Reduce the delay waiting for escape sequences.
        os.environ.setdefault('ESCDELAY', '1')
        curses.wrapper(wrapped_ci)
    finally:
        app.log.flush()
        app.log.writeToFile('~/.ci_edit/recentLog')
        # Disable Bracketed Paste Mode.
        sys.stdout.write('\033[?2004l')
        # Disable mouse tracking in xterm.
        sys.stdout.write('\033[?1002;l')
        sys.stdout.flush()
    if userConsoleMessage:
        fullPath = app.buffer_file.expandFullPath(
            '~/.ci_edit/userConsoleMessage')
        with io.open(fullPath, 'w+') as f:
            f.write(userConsoleMessage)
        sys.stdout.write(userConsoleMessage + '\n')
        sys.stdout.flush() 
開發者ID:google,項目名稱:ci_edit,代碼行數:23,代碼來源:ci_program.py

示例6: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main(argv):
    if len(argv) > 1:
        if argv[1] == 'slave':
            display = Display()
            curses.wrapper(display.show)
            return 1

    command = [
        sys.executable,
        os.path.realpath(__file__),
        'slave',
    ]
    while True:
        return_code = subprocess.call(command)
        if return_code != 1:
            break

    return 0 
開發者ID:ayeowch,項目名稱:bitnodes-hardware,代碼行數:20,代碼來源:lcd.py

示例7: start

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def start():
	curses.wrapper(main) 
開發者ID:Jugran,項目名稱:lyrics-in-terminal,代碼行數:4,代碼來源:lyrics_in_terminal.py

示例8: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main():
    username = ''
    password = ''
    baidu_api = BaiduFmAPI(username, password)
    baidu_cli = BaiduFmCli(baidu_api)
    curses.wrapper(baidu_cli.setup) 
開發者ID:tdoly,項目名稱:baidufm-py,代碼行數:8,代碼來源:baidufm.py

示例9: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main():
  with Controller.from_port(port = 9051) as controller:
    controller.authenticate()

    try:
      # This makes curses initialize and call draw_bandwidth_graph() with a
      # reference to the screen, followed by additional arguments (in this
      # case just the controller).

      curses.wrapper(draw_bandwidth_graph, controller)
    except KeyboardInterrupt:
      pass  # the user hit ctrl+c 
開發者ID:torproject,項目名稱:stem,代碼行數:14,代碼來源:event_listening.py

示例10: wrapper

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def wrapper(cls, func, height=None, catch_interrupt=False, arguments=None,
                unicode_aware=None):
        """
        Construct a new Screen for any platform.  This will initialize the
        Screen, call the specified function and then tidy up the system as
        required when the function exits.

        :param func: The function to call once the Screen has been created.
        :param height: The buffer height for this Screen (only for test purposes).
        :param catch_interrupt: Whether to catch and prevent keyboard
            interrupts.  Defaults to False to maintain backwards compatibility.
        :param arguments: Optional arguments list to pass to func (after the
            Screen object).
        :param unicode_aware: Whether the application can use unicode or not.
            If None, try to detect from the environment if UTF-8 is enabled.
        """
        screen = Screen.open(height,
                             catch_interrupt=catch_interrupt,
                             unicode_aware=unicode_aware)
        restore = True
        try:
            try:
                if arguments:
                    return func(screen, *arguments)
                else:
                    return func(screen)
            except ResizeScreenError:
                restore = False
                raise
        finally:
            screen.close(restore) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:33,代碼來源:screen.py

示例11: play

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def play(self, game):
    """Play a pycolab game.

    Calling this method initialises curses and starts an interaction loop. The
    loop continues until the game terminates or an error occurs.

    This method will exit cleanly if an exception is raised within the game;
    that is, you shouldn't have to reset your terminal.

    Args:
      game: a pycolab game. Ths game must not have had its `its_showtime` method
          called yet.

    Raises:
      RuntimeError: if this method is called while a game is already underway.
    """
    if self._game is not None:
      raise RuntimeError('CursesUi is not at all thread safe')
    self._game = game
    self._start_time = datetime.datetime.now()
    # Inform the croppers which game we're playing.
    for cropper in self._croppers:
      cropper.set_engine(self._game)

    # After turning on curses, set it up and play the game.
    curses.wrapper(self._init_curses_and_play)

    # The game has concluded. Print the final statistics.
    duration = datetime.datetime.now() - self._start_time
    print('Game over! Final score is {}, earned over {}.'.format(
        self._total_return, _format_timedelta(duration)))

    # Clean up in preparation for the next game.
    self._game = None
    self._start_time = None
    self._total_return = None 
開發者ID:deepmind,項目名稱:pycolab,代碼行數:38,代碼來源:human_ui.py

示例12: _update_game_console

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def _update_game_console(self, new_log_messages, console, paint_console):
    """Update game console text buffer; draw console to the screen if enabled.

    Args:
      new_log_messages: a list of strings containing new log messages to place
          in the game console's message buffer.
      console: curses window for the game console.
      paint_console: if True, the console will be displayed at the next screen
          refresh; if not, it won't.
    """
    # First we have to format the new messages to fit within our game console.
    rows, cols = console.getmaxyx()

    # Split all log messages on newline characters.
    split_log_messages = []
    for message in new_log_messages:
      split_log_messages.extend(message.splitlines())

    # It's a little weird to wrap console log messages with a text wrapper
    # designed for English text, but that beats writing tab expansion myself.
    wrapper = textwrap.TextWrapper(
        width=cols, drop_whitespace=False, break_on_hyphens=False)
    for message in split_log_messages:
      self._log_messages.extend(wrapper.wrap(message))

    # There's only room on the screen for the last rows-1 console messages.
    del self._log_messages[:(1-rows)]

    # Draw the console if the console is visible.
    if paint_console:
      console.border(' ', ' ', curses.ACS_HLINE, ' ',
                     curses.ACS_ULCORNER, curses.ACS_URCORNER, ' ', ' ')
      console.addstr(0, 4, '{ Console }', curses.A_BOLD)
      console.addstr(1, 0, '\n'.join(self._log_messages))
      console.noutrefresh() 
開發者ID:deepmind,項目名稱:pycolab,代碼行數:37,代碼來源:human_ui.py

示例13: wrapper

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:41,代碼來源:wrapper.py

示例14: main

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def main():
    if os.path.isfile(BASEDIR):
        sys.exit('Please remove your old configuration file at {}'.format(BASEDIR))
    os.makedirs(BASEDIR, exist_ok=True)

    global CONFIG
    CONFIG = read_configuration(CONFFILE)
    locale.setlocale(locale.LC_MONETARY, CONFIG['locale'].get('monetary', ''))

    requests_cache.install_cache(cache_name='api_cache', backend='memory',
        expire_after=int(CONFIG['api'].get('cache', 10)))

    curses.wrapper(mainc) 
開發者ID:huwwp,項目名稱:cryptop,代碼行數:15,代碼來源:cryptop.py

示例15: run

# 需要導入模塊: import curses [as 別名]
# 或者: from curses import wrapper [as 別名]
def run(remote):
    """Run interactive remote control application."""
    curses.wrapper(_control, remote) 
開發者ID:Ape,項目名稱:samsungctl,代碼行數:5,代碼來源:interactive.py


注:本文中的curses.wrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。