当前位置: 首页>>代码示例>>Python>>正文


Python Keys.Any方法代码示例

本文整理汇总了Python中prompt_toolkit.keys.Keys.Any方法的典型用法代码示例。如果您正苦于以下问题:Python Keys.Any方法的具体用法?Python Keys.Any怎么用?Python Keys.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.keys.Keys的用法示例。


在下文中一共展示了Keys.Any方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_exception

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def _handle_exception(
        self, loop: AbstractEventLoop, context: Dict[str, Any]
    ) -> None:
        """
        Handler for event loop exceptions.
        This will print the exception, using run_in_terminal.
        """
        # For Python 2: we have to get traceback at this point, because
        # we're still in the 'except:' block of the event loop where the
        # traceback is still available. Moving this code in the
        # 'print_exception' coroutine will loose the exception.
        tb = get_traceback_from_context(context)
        formatted_tb = "".join(format_tb(tb))

        async def in_term() -> None:
            async with in_terminal():
                # Print output. Similar to 'loop.default_exception_handler',
                # but don't use logger. (This works better on Python 2.)
                print("\nUnhandled exception in event loop:")
                print(formatted_tb)
                print("Exception %s" % (context.get("exception"),))

                await _do_wait_for_enter("Press ENTER to continue...")

        ensure_future(in_term()) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:27,代码来源:application.py

示例2: _do_wait_for_enter

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def _do_wait_for_enter(wait_text: AnyFormattedText) -> None:
    """
    Create a sub application to wait for the enter key press.
    This has two advantages over using 'input'/'raw_input':
    - This will share the same input/output I/O.
    - This doesn't block the event loop.
    """
    from prompt_toolkit.shortcuts import PromptSession

    key_bindings = KeyBindings()

    @key_bindings.add("enter")
    def _ok(event: E) -> None:
        event.app.exit()

    @key_bindings.add(Keys.Any)
    def _ignore(event: E) -> None:
        " Disallow typing. "
        pass

    session: PromptSession[None] = PromptSession(
        message=wait_text, key_bindings=key_bindings
    )
    await session.app.run_async() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:26,代码来源:application.py

示例3: get_bindings_starting_with_keys

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def get_bindings_starting_with_keys(self, keys: KeysTuple) -> List[Binding]:
        """
        Return a list of key bindings that handle a key sequence starting with
        `keys`. (It does only return bindings for which the sequences are
        longer than `keys`. And like `get_bindings_for_keys`, it also includes
        inactive bindings.)

        :param keys: tuple of keys.
        """

        def get() -> List[Binding]:
            result = []
            for b in self.bindings:
                if len(keys) < len(b.keys):
                    match = True
                    for i, j in zip(b.keys, keys):
                        if i != j and i != Keys.Any:
                            match = False
                            break
                    if match:
                        result.append(b)
            return result

        return self._get_bindings_starting_with_keys_cache.get(keys, get) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:26,代码来源:key_bindings.py

示例4: get_bindings_starting_with_keys

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def get_bindings_starting_with_keys(self, keys):
        """
        Return a list of key bindings that handle a key sequence starting with
        `keys`. (It does only return bindings for which the sequences are
        longer than `keys`. And like `get_bindings_for_keys`, it also includes
        inactive bindings.)

        :param keys: tuple of keys.
        """
        def get():
            result = []
            for b in self.key_bindings:
                if len(keys) < len(b.keys):
                    match = True
                    for i, j in zip(b.keys, keys):
                        if i != j and i != Keys.Any:
                            match = False
                            break
                    if match:
                        result.append(b)
            return result

        return self._get_bindings_starting_with_keys_cache.get(keys, get) 
开发者ID:bkerler,项目名称:android_universal,代码行数:25,代码来源:registry.py

示例5: load_confirm_exit_bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def load_confirm_exit_bindings(python_input):
    """
    Handle yes/no key presses when the exit confirmation is shown.
    """
    bindings = KeyBindings()

    handle = bindings.add
    confirmation_visible = Condition(lambda: python_input.show_exit_confirmation)

    @handle("y", filter=confirmation_visible)
    @handle("Y", filter=confirmation_visible)
    @handle("enter", filter=confirmation_visible)
    @handle("c-d", filter=confirmation_visible)
    def _(event):
        """
        Really quit.
        """
        event.app.exit(exception=EOFError, style="class:exiting")

    @handle(Keys.Any, filter=confirmation_visible)
    def _(event):
        """
        Cancel exit.
        """
        python_input.show_exit_confirmation = False

    return bindings 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:29,代码来源:key_bindings.py

示例6: _create_more_session

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def _create_more_session(message: str = "--MORE--") -> "PromptSession":
    """
    Create a `PromptSession` object for displaying the "--MORE--".
    """
    from prompt_toolkit.shortcuts import PromptSession

    bindings = KeyBindings()

    @bindings.add(" ")
    @bindings.add("y")
    @bindings.add("Y")
    @bindings.add(Keys.ControlJ)
    @bindings.add(Keys.ControlM)
    @bindings.add(Keys.ControlI)  # Tab.
    def _yes(event: E) -> None:
        event.app.exit(result=True)

    @bindings.add("n")
    @bindings.add("N")
    @bindings.add("q")
    @bindings.add("Q")
    @bindings.add(Keys.ControlC)
    def _no(event: E) -> None:
        event.app.exit(result=False)

    @bindings.add(Keys.Any)
    def _ignore(event: E) -> None:
        " Disable inserting of text. "

    return PromptSession(message, key_bindings=bindings, erase_when_done=True) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:32,代码来源:completion.py

示例7: get_bindings_for_keys

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def get_bindings_for_keys(self, keys: KeysTuple) -> List[Binding]:
        """
        Return a list of key bindings that can handle this key.
        (This return also inactive bindings, so the `filter` still has to be
        called, for checking it.)

        :param keys: tuple of keys.
        """

        def get() -> List[Binding]:
            result: List[Tuple[int, Binding]] = []

            for b in self.bindings:
                if len(keys) == len(b.keys):
                    match = True
                    any_count = 0

                    for i, j in zip(b.keys, keys):
                        if i != j and i != Keys.Any:
                            match = False
                            break

                        if i == Keys.Any:
                            any_count += 1

                    if match:
                        result.append((any_count, b))

            # Place bindings that have more 'Any' occurrences in them at the end.
            result = sorted(result, key=lambda item: -item[0])

            return [item[1] for item in result]

        return self._get_bindings_for_keys_cache.get(keys, get) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:36,代码来源:key_bindings.py

示例8: bindings

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def bindings(handlers):
    bindings = KeyBindings()
    bindings.add(Keys.ControlX, Keys.ControlC)(handlers.controlx_controlc)
    bindings.add(Keys.ControlX)(handlers.control_x)
    bindings.add(Keys.ControlD)(handlers.control_d)
    bindings.add(Keys.ControlSquareClose, Keys.Any)(handlers.control_square_close_any)

    return bindings 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:10,代码来源:test_key_binding.py

示例9: get_bindings_for_keys

# 需要导入模块: from prompt_toolkit.keys import Keys [as 别名]
# 或者: from prompt_toolkit.keys.Keys import Any [as 别名]
def get_bindings_for_keys(self, keys):
        """
        Return a list of key bindings that can handle this key.
        (This return also inactive bindings, so the `filter` still has to be
        called, for checking it.)

        :param keys: tuple of keys.
        """
        def get():
            result = []
            for b in self.key_bindings:
                if len(keys) == len(b.keys):
                    match = True
                    any_count = 0

                    for i, j in zip(b.keys, keys):
                        if i != j and i != Keys.Any:
                            match = False
                            break

                        if i == Keys.Any:
                            any_count += 1

                    if match:
                        result.append((any_count, b))

            # Place bindings that have more 'Any' occurences in them at the end.
            result = sorted(result, key=lambda item: -item[0])

            return [item[1] for item in result]

        return self._get_bindings_for_keys_cache.get(keys, get) 
开发者ID:bkerler,项目名称:android_universal,代码行数:34,代码来源:registry.py


注:本文中的prompt_toolkit.keys.Keys.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。