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


Python Token.SetCursorPosition方法代码示例

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


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

示例1: _get_choice_tokens

# 需要导入模块: from prompt_toolkit.token import Token [as 别名]
# 或者: from prompt_toolkit.token.Token import SetCursorPosition [as 别名]
def _get_choice_tokens(self, cli):
        tokens = []
        T = Token

        def append(index, choice):
            selected = (index == self.selected_option_index)

            @if_mousedown
            def select_item(cli, mouse_event):
                # bind option with this index to mouse event
                self.selected_option_index = index
                self.answered = True
                cli.set_return_value(None)

            token = T.Selected if selected else T

            tokens.append((T.Pointer if selected else T, ' \u276f ' if selected
            else '   '))
            if selected:
                tokens.append((Token.SetCursorPosition, ''))
            if choice[1]:  # disabled
                tokens.append((T.Selected if selected else T, 
                               '- %s (%s)' % (choice[0], choice[1])))
            else:
                tokens.append((T.Selected if selected else T, str(choice[0]),
                               select_item))
            tokens.append((T, '\n'))

        # prepare the select choices
        for i, choice in enumerate(self.choices):
            append(i, choice)
        tokens.pop()  # Remove last newline.
        return tokens 
开发者ID:finklabs,项目名称:whaaaaat,代码行数:35,代码来源:list.py

示例2: _get_choice_tokens

# 需要导入模块: from prompt_toolkit.token import Token [as 别名]
# 或者: from prompt_toolkit.token.Token import SetCursorPosition [as 别名]
def _get_choice_tokens(self, cli):
        tokens = []
        T = Token

        def append(index, line):
            if isinstance(line, Separator):
                tokens.append((T.Separator, '%s\n' % line))
            else:
                line = line[0]
                selected = (line in self.selected_options)
                pointed_at = (index == self.pointer_index)

                @if_mousedown
                def select_item(cli, mouse_event):
                    # bind option with this index to mouse event
                    if line in self.selected_options:
                        self.selected_options.remove(line)
                    else:
                        self.selected_options.append(line)

                if pointed_at:
                    tokens.append((T.Pointer, ' \u276f', select_item))  # ' >'
                else:
                    tokens.append((T, '  ', select_item))
                if selected:
                    tokens.append((T, '\u25cf ', select_item))  # 'o ' - FISHEYE
                else:
                    tokens.append((T, '\u25cb ', select_item))  # 'o ' - FISHEYE

                if pointed_at:
                    tokens.append((Token.SetCursorPosition, ''))

                tokens.append((T.Selected if selected else T, line, select_item))
                tokens.append((T, '\n'))

        # prepare the select choices
        for i, choice in enumerate(self.choices):
            append(i, choice)
        tokens.pop()  # Remove last newline.
        return tokens 
开发者ID:finklabs,项目名称:whaaaaat,代码行数:42,代码来源:checkbox.py

示例3: split_lines

# 需要导入模块: from prompt_toolkit.token import Token [as 别名]
# 或者: from prompt_toolkit.token.Token import SetCursorPosition [as 别名]
def split_lines(tokenlist):
    """
    Take a single list of (Token, text) tuples and yield one such list for each
    line. Just like str.split, this will yield at least one item.

    :param tokenlist: List of (token, text) or (token, text, mouse_handler)
                      tuples.
    """
    line = []

    for item in tokenlist:
        # For (token, text) tuples.
        if len(item) == 2:
            token, string = item
            parts = string.split('\n')

            for part in parts[:-1]:
                if part:
                    line.append((token, part))
                yield line
                line = []

            line.append((token, parts[-1]))
                # Note that parts[-1] can be empty, and that's fine. It happens
                # in the case of [(Token.SetCursorPosition, '')].

        # For (token, text, mouse_handler) tuples.
        #     I know, partly copy/paste, but understandable and more efficient
        #     than many tests.
        else:
            token, string, mouse_handler = item
            parts = string.split('\n')

            for part in parts[:-1]:
                if part:
                    line.append((token, part, mouse_handler))
                yield line
                line = []

            line.append((token, parts[-1], mouse_handler))

    # Always yield the last line, even when this is an empty line. This ensures
    # that when `tokenlist` ends with a newline character, an additional empty
    # line is yielded. (Otherwise, there's no way to differentiate between the
    # cases where `tokenlist` does and doesn't end with a newline.)
    yield line 
开发者ID:chrisjim316,项目名称:Liljimbo-Chatbot,代码行数:48,代码来源:utils.py

示例4: create_content

# 需要导入模块: from prompt_toolkit.token import Token [as 别名]
# 或者: from prompt_toolkit.token.Token import SetCursorPosition [as 别名]
def create_content(self, cli, width, height):
        # Get tokens
        tokens_with_mouse_handlers = self._get_tokens_cached(cli)

        default_char = self.get_default_char(cli)

        # Wrap/align right/center parameters.
        right = self.align_right(cli)
        center = self.align_center(cli)

        def process_line(line):
            " Center or right align a single line. "
            used_width = token_list_width(line)
            padding = width - used_width
            if center:
                padding = int(padding / 2)
            return [(default_char.token, default_char.char * padding)] + line

        if right or center:
            token_lines_with_mouse_handlers = []

            for line in split_lines(tokens_with_mouse_handlers):
                token_lines_with_mouse_handlers.append(process_line(line))
        else:
            token_lines_with_mouse_handlers = list(split_lines(tokens_with_mouse_handlers))

        # Strip mouse handlers from tokens.
        token_lines = [
            [tuple(item[:2]) for item in line]
            for line in token_lines_with_mouse_handlers
        ]

        # Keep track of the tokens with mouse handler, for later use in
        # `mouse_handler`.
        self._tokens = tokens_with_mouse_handlers

        # If there is a `Token.SetCursorPosition` in the token list, set the
        # cursor position here.
        def get_cursor_position():
            SetCursorPosition = Token.SetCursorPosition

            for y, line in enumerate(token_lines):
                x = 0
                for token, text in line:
                    if token == SetCursorPosition:
                        return Point(x=x, y=y)
                    x += len(text)
            return None

        # Create content, or take it from the cache.
        key = (default_char.char, default_char.token,
                tuple(tokens_with_mouse_handlers), width, right, center)

        def get_content():
            return UIContent(get_line=lambda i: token_lines[i],
                             line_count=len(token_lines),
                             default_char=default_char,
                             cursor_position=get_cursor_position())

        return self._content_cache.get(key, get_content) 
开发者ID:chrisjim316,项目名称:Liljimbo-Chatbot,代码行数:62,代码来源:controls.py


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