當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。