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


Python filters.Condition方法代码示例

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


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

示例1: _create_buffer

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def _create_buffer(self) -> Buffer:
        """
        Create the `Buffer` for the Python input.
        """
        python_buffer = Buffer(
            name=DEFAULT_BUFFER,
            complete_while_typing=Condition(lambda: self.complete_while_typing),
            enable_history_search=Condition(lambda: self.enable_history_search),
            tempfile_suffix=".py",
            history=self.history,
            completer=ThreadedCompleter(self._completer),
            validator=ConditionalValidator(
                self._validator, Condition(lambda: self.enable_input_validation)
            ),
            auto_suggest=ConditionalAutoSuggest(
                ThreadedAutoSuggest(AutoSuggestFromHistory()),
                Condition(lambda: self.enable_auto_suggest),
            ),
            accept_handler=self._accept_handler,
            on_text_changed=self._on_input_timeout,
        )

        return python_buffer 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:25,代码来源:python_input.py

示例2: __init__

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def __init__(self, client_state):
        def get_message():
            # If there is a message to be shown for this client, show that.
            if client_state.message:
                return client_state.message
            else:
                return ''

        def get_tokens():
            message = get_message()
            if message:
                return FormattedText([
                    ('class:message', message),
                    ('[SetCursorPosition]', ''),
                    ('class:message', ' '),
                ])
            else:
                return ''

        @Condition
        def is_visible():
            return bool(get_message())

        super(MessageToolbar, self).__init__(get_tokens) 
开发者ID:prompt-toolkit,项目名称:pymux,代码行数:26,代码来源:layout.py

示例3: _build_layout

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def _build_layout(self):
        " Rebuild a new Container object and return that. "
        logger.info('Rebuilding layout.')

        if not self.pymux.arrangement.windows:
            # No Pymux windows in the arrangement.
            return Window()

        active_window = self.pymux.arrangement.get_active_window()

        # When zoomed, only show the current pane, otherwise show all of them.
        if active_window.zoom:
            return to_container(_create_container_for_process(
                self.pymux, active_window, active_window.active_pane, zoom=True))
        else:
            window = self.pymux.arrangement.get_active_window()
            return HSplit([
                # Some spacing for the top status bar.
                ConditionalContainer(
                    content=Window(height=1),
                    filter=Condition(lambda: self.pymux.enable_pane_status)),
                # The actual content.
                _create_split(self.pymux, window, window.root)
            ]) 
开发者ID:prompt-toolkit,项目名称:pymux,代码行数:26,代码来源:layout.py

示例4: __init__

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def __init__(self, editor):
        once_hidden = [False]  # Nonlocal

        def condition():
            # Get editor buffers
            buffers = editor.window_arrangement.editor_buffers

            # Only show when there is only one empty buffer, but once the
            # welcome message has been hidden, don't show it again.
            result = (len(buffers) == 1 and buffers[0].buffer.text == '' and
                      buffers[0].location is None and not once_hidden[0])
            if not result:
                once_hidden[0] = True
            return result

        super(WelcomeMessageWindow, self).__init__(
            Window(
                FormattedTextControl(lambda: WELCOME_MESSAGE_TOKENS),
                align=WindowAlign.CENTER,
                style="class:welcome"),
            filter=Condition(condition)) 
开发者ID:prompt-toolkit,项目名称:pyvim,代码行数:23,代码来源:layout.py

示例5: load_abort_and_exit_bindings

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def load_abort_and_exit_bindings():
    """
    Basic bindings for abort (Ctrl-C) and exit (Ctrl-D).
    """
    registry = Registry()
    handle = registry.add_binding

    @handle(Keys.ControlC)
    def _(event):
        " Abort when Control-C has been pressed. "
        event.cli.abort()

    @Condition
    def ctrl_d_condition(cli):
        """ Ctrl-D binding is only active when the default buffer is selected
        and empty. """
        return (cli.current_buffer_name == DEFAULT_BUFFER and
                not cli.current_buffer.text)

    handle(Keys.ControlD, filter=ctrl_d_condition)(get_by_name('end-of-file'))

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:24,代码来源:basic.py

示例6: load_basic_system_bindings

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def load_basic_system_bindings():
    """
    Basic system bindings (For both Emacs and Vi mode.)
    """
    registry = Registry()

    suspend_supported = Condition(
        lambda cli: suspend_to_background_supported())

    @registry.add_binding(Keys.ControlZ, filter=suspend_supported)
    def _(event):
        """
        Suspend process to background.
        """
        event.cli.suspend_to_background()

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:19,代码来源:basic.py

示例7: load_auto_suggestion_bindings

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def load_auto_suggestion_bindings():
    """
    Key bindings for accepting auto suggestion text.
    """
    registry = Registry()
    handle = registry.add_binding

    suggestion_available = Condition(
        lambda cli:
            cli.current_buffer.suggestion is not None and
            cli.current_buffer.document.is_cursor_at_the_end)

    @handle(Keys.ControlF, filter=suggestion_available)
    @handle(Keys.ControlE, filter=suggestion_available)
    @handle(Keys.Right, filter=suggestion_available)
    def _(event):
        " Accept suggestion. "
        b = event.current_buffer
        suggestion = b.suggestion

        if suggestion:
            b.insert_text(suggestion.text)

    return registry 
开发者ID:bkerler,项目名称:android_universal,代码行数:26,代码来源:basic.py

示例8: _create_application

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def _create_application(
        self, input: Optional[Input], output: Optional[Output]
    ) -> Application:
        """
        Create an `Application` instance.
        """
        return Application(
            layout=self.ptpython_layout.layout,
            key_bindings=merge_key_bindings(
                [
                    load_python_bindings(self),
                    load_auto_suggest_bindings(),
                    load_sidebar_bindings(self),
                    load_confirm_exit_bindings(self),
                    ConditionalKeyBindings(
                        load_open_in_editor_bindings(),
                        Condition(lambda: self.enable_open_in_editor),
                    ),
                    # Extra key bindings should not be active when the sidebar is visible.
                    ConditionalKeyBindings(
                        self.extra_key_bindings,
                        Condition(lambda: not self.show_sidebar),
                    ),
                ]
            ),
            color_depth=lambda: self.color_depth,
            paste_mode=Condition(lambda: self.paste_mode),
            mouse_support=Condition(lambda: self.enable_mouse_support),
            style=DynamicStyle(lambda: self._current_style),
            style_transformation=self.style_transformation,
            include_default_pygments_style=False,
            reverse_vi_search_direction=True,
            input=input,
            output=output,
        ) 
开发者ID:prompt-toolkit,项目名称:ptpython,代码行数:37,代码来源:python_input.py

示例9: main

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def main():
    hidden = [True]  # Nonlocal
    bindings = KeyBindings()

    @bindings.add("c-t")
    def _(event):
        " When ControlT has been pressed, toggle visibility. "
        hidden[0] = not hidden[0]

    print("Type Control-T to toggle password visible.")
    password = prompt(
        "Password: ", is_password=Condition(lambda: hidden[0]), key_bindings=bindings
    )
    print("You said: %s" % password) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:16,代码来源:get-password-with-toggle-display-shortcut.py

示例10: main

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def main():
    swapped = [False]  # Nonlocal
    bindings = KeyBindings()

    @bindings.add("c-t")
    def _(event):
        " When ControlT has been pressed, toggle light/dark colors. "
        swapped[0] = not swapped[0]

    def bottom_toolbar():
        if swapped[0]:
            on = "on=true"
        else:
            on = "on=false"

        return (
            HTML(
                'Press <style bg="#222222" fg="#ff8888">[control-t]</style> '
                "to swap between dark/light colors. "
                '<style bg="ansiblack" fg="ansiwhite">[%s]</style>'
            )
            % on
        )

    text = prompt(
        HTML('<style fg="#aaaaaa">Give some animals</style>: '),
        completer=html_completer,
        complete_while_typing=True,
        bottom_toolbar=bottom_toolbar,
        key_bindings=bindings,
        lexer=PygmentsLexer(HtmlLexer),
        swap_light_and_dark_colors=Condition(lambda: swapped[0]),
    )
    print("You said: %s" % text) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:36,代码来源:swap-light-and-dark-colors.py

示例11: test_invert

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def test_invert():
    assert not (~Always())()
    assert ~Never()()

    c = ~Condition(lambda: False)
    assert c() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:8,代码来源:test_filter.py

示例12: test_or

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def test_or():
    for a in (True, False):
        for b in (True, False):
            c1 = Condition(lambda: a)
            c2 = Condition(lambda: b)
            c3 = c1 | c2

            assert isinstance(c3, Filter)
            assert c3() == a or b 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:11,代码来源:test_filter.py

示例13: test_and

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def test_and():
    for a in (True, False):
        for b in (True, False):
            c1 = Condition(lambda: a)
            c2 = Condition(lambda: b)
            c3 = c1 & c2

            assert isinstance(c3, Filter)
            assert c3() == (a and b) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:11,代码来源:test_filter.py

示例14: _bufferlist_overlay_visible

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def _bufferlist_overlay_visible(editor):
    """
    True when the buffer list overlay should be displayed.
    (This is when someone starts typing ':b' or ':buffer' in the command line.)
    """
    @Condition
    def overlay_is_visible():
        app = get_app()

        text = editor.command_buffer.text.lstrip()
        return app.layout.has_focus(editor.command_buffer) and (
                any(text.startswith(p) for p in ['b ', 'b! ', 'buffer', 'buffer!']))
    return overlay_is_visible 
开发者ID:prompt-toolkit,项目名称:pyvim,代码行数:15,代码来源:layout.py

示例15: _create_window_frame

# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import Condition [as 别名]
def _create_window_frame(self, editor_buffer):
        """
        Create a Window for the buffer, with underneat a status bar.
        """
        @Condition
        def wrap_lines():
            return self.editor.wrap_lines

        window = Window(
            self._create_buffer_control(editor_buffer),
            allow_scroll_beyond_bottom=True,
            scroll_offsets=ScrollOffsets(
                left=0, right=0,
                top=(lambda: self.editor.scroll_offset),
                bottom=(lambda: self.editor.scroll_offset)),
            wrap_lines=wrap_lines,
            left_margins=[ConditionalMargin(
                    margin=NumberedMargin(
                        display_tildes=True,
                        relative=Condition(lambda: self.editor.relative_number)),
                    filter=Condition(lambda: self.editor.show_line_numbers))],
            cursorline=Condition(lambda: self.editor.cursorline),
            cursorcolumn=Condition(lambda: self.editor.cursorcolumn),
            colorcolumns=(
                lambda: [ColorColumn(pos) for pos in self.editor.colorcolumn]),
            ignore_content_width=True,
            ignore_content_height=True,
            get_line_prefix=partial(self._get_line_prefix, editor_buffer.buffer))

        return HSplit([
            window,
            VSplit([
                WindowStatusBar(self.editor, editor_buffer),
                WindowStatusBarRuler(self.editor, window, editor_buffer.buffer),
            ], width=Dimension()),  # Ignore actual status bar width.
        ]), window 
开发者ID:prompt-toolkit,项目名称:pyvim,代码行数:38,代码来源:layout.py


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