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


Python containers.Window方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def __init__(self, pymux, client_state):
        self.pymux = pymux
        self.client_state = client_state

        # Popup dialog for displaying keys, etc...
        search_textarea = SearchToolbar()
        self._popup_textarea = TextArea(scrollbar=True, read_only=True, search_field=search_textarea)
        self.popup_dialog = Dialog(
            title='Keys',
            body=HSplit([
                Window(FormattedTextControl(text=''), height=1),  # 1 line margin.
                self._popup_textarea,
                search_textarea,
                Window(
                    FormattedTextControl(
                        text=HTML('Press [<b>q</b>] to quit or [<b>/</b>] for searching.')),
                    align=WindowAlign.CENTER,
                    height=1)
                ])
            )

        self.layout = self._create_layout()

        # Keep track of render information.
        self.pane_write_positions = {} 
開發者ID:prompt-toolkit,項目名稱:pymux,代碼行數:27,代碼來源:layout.py

示例2: _build_layout

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [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

示例3: __init__

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [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

示例4: scroll_down

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def scroll_down(event, window: Optional[Window] = None, buffer: Optional[Buffer] = None):
    w = window or event.app.layout.current_window
    b = buffer or event.app.current_buffer

    if w and w.render_info:
        info = w.render_info
        ui_content = info.ui_content

        # Height to scroll.
        scroll_height = info.window_height // 2

        # Calculate how many lines is equivalent to that vertical space.
        y = b.document.cursor_position_row + 1
        height = 0
        while y < ui_content.line_count:
            line_height = info.get_height_for_line(y)

            if height + line_height < scroll_height:
                height += line_height
                y += 1
            else:
                break

        b.cursor_position = b.document.translate_row_col_to_index(y, 0) 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:26,代碼來源:scroll_handlers.py

示例5: scroll_up

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def scroll_up(event, window: Optional[Window] = None, buffer: Optional[Buffer] = None):
    w = window or event.app.layout.current_window
    b = buffer or event.app.current_buffer

    if w and w.render_info:
        info = w.render_info

        # Height to scroll.
        scroll_height = info.window_height // 2

        # Calculate how many lines is equivalent to that vertical space.
        y = max(0, b.document.cursor_position_row - 1)
        height = 0
        while y > 0:
            line_height = info.get_height_for_line(y)

            if height + line_height < scroll_height:
                height += line_height
                y -= 1
            else:
                break

        b.cursor_position = b.document.translate_row_col_to_index(y, 0) 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:25,代碼來源:scroll_handlers.py

示例6: __init__

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def __init__(self, app: Application[_AppResult]) -> None:
        self.app = app
        self._cache: SimpleCache[
            Tuple[Window, FrozenSet[UIControl]], KeyBindingsBase
        ] = SimpleCache() 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:7,代碼來源:application.py

示例7: __init__

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def __init__(
        self,
        prompt: AnyFormattedText = "Shell command: ",
        enable_global_bindings: FilterOrBool = True,
    ) -> None:

        self.prompt = prompt
        self.enable_global_bindings = to_filter(enable_global_bindings)

        self.system_buffer = Buffer(name=SYSTEM_BUFFER)

        self._bindings = self._build_key_bindings()

        self.buffer_control = BufferControl(
            buffer=self.system_buffer,
            lexer=SimpleLexer(style="class:system-toolbar.text"),
            input_processors=[
                BeforeInput(lambda: self.prompt, style="class:system-toolbar")
            ],
            key_bindings=self._bindings,
        )

        self.window = Window(
            self.buffer_control, height=1, style="class:system-toolbar"
        )

        self.container = ConditionalContainer(
            content=self.window, filter=has_focus(self.system_buffer)
        ) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:31,代碼來源:toolbars.py

示例8: test_layout_class

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def test_layout_class():
    c1 = BufferControl()
    c2 = BufferControl()
    c3 = BufferControl()
    win1 = Window(content=c1)
    win2 = Window(content=c2)
    win3 = Window(content=c3)

    layout = Layout(container=VSplit([HSplit([win1, win2]), win3]))

    # Listing of windows/controls.
    assert list(layout.find_all_windows()) == [win1, win2, win3]
    assert list(layout.find_all_controls()) == [c1, c2, c3]

    # Focusing something.
    layout.focus(c1)
    assert layout.has_focus(c1)
    assert layout.has_focus(win1)
    assert layout.current_control == c1
    assert layout.previous_control == c1

    layout.focus(c2)
    assert layout.has_focus(c2)
    assert layout.has_focus(win2)
    assert layout.current_control == c2
    assert layout.previous_control == c1

    layout.focus(win3)
    assert layout.has_focus(c3)
    assert layout.has_focus(win3)
    assert layout.current_control == c3
    assert layout.previous_control == c2

    # Pop focus. This should focus the previous control again.
    layout.focus_last()
    assert layout.has_focus(c2)
    assert layout.has_focus(win2)
    assert layout.current_control == c2
    assert layout.previous_control == c1 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:41,代碼來源:test_layout.py

示例9: update

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def update(self):
        """
        Update layout to match the layout as described in the
        WindowArrangement.
        """
        # Start with an empty frames list everytime, to avoid memory leaks.
        existing_frames = self._frames
        self._frames = {}

        def create_layout_from_node(node):
            if isinstance(node, window_arrangement.Window):
                # Create frame for Window, or reuse it, if we had one already.
                key = (node, node.editor_buffer)
                frame = existing_frames.get(key)
                if frame is None:
                    frame, pt_window = self._create_window_frame(node.editor_buffer)

                    # Link layout Window to arrangement.
                    node.pt_window = pt_window

                self._frames[key] = frame
                return frame

            elif isinstance(node, window_arrangement.VSplit):
                return VSplit(
                    [create_layout_from_node(n) for n in node],
                    padding=1,
                    padding_char=self.get_vertical_border_char(),
                    padding_style='class:frameborder')

            if isinstance(node, window_arrangement.HSplit):
                return HSplit([create_layout_from_node(n) for n in node])

        layout = create_layout_from_node(self.window_arrangement.active_tab.root)
        self._fc.content = layout 
開發者ID:prompt-toolkit,項目名稱:pyvim,代碼行數:37,代碼來源:layout.py

示例10: _create_window_frame

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [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

示例11: _create_key_bindings

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def _create_key_bindings(
        self, current_window: Window, other_controls: List[UIControl]
    ) -> KeyBindingsBase:
        """
        Create a `KeyBindings` object that merges the `KeyBindings` from the
        `UIControl` with all the parent controls and the global key bindings.
        """
        key_bindings = []
        collected_containers = set()

        # Collect key bindings from currently focused control and all parent
        # controls. Don't include key bindings of container parent controls.
        container: Container = current_window
        while True:
            collected_containers.add(container)
            kb = container.get_key_bindings()
            if kb is not None:
                key_bindings.append(kb)

            if container.is_modal():
                break

            parent = self.app.layout.get_parent(container)
            if parent is None:
                break
            else:
                container = parent

        # Include global bindings (starting at the top-model container).
        for c in walk(container):
            if c not in collected_containers:
                kb = c.get_key_bindings()
                if kb is not None:
                    key_bindings.append(GlobalOnlyKeyBindings(kb))

        # Add App key bindings
        if self.app.key_bindings:
            key_bindings.append(self.app.key_bindings)

        # Add mouse bindings.
        key_bindings.append(
            ConditionalKeyBindings(
                self.app._page_navigation_bindings,
                self.app.enable_page_navigation_bindings,
            )
        )
        key_bindings.append(self.app._default_bindings)

        # Reverse this list. The current control's key bindings should come
        # last. They need priority.
        key_bindings = key_bindings[::-1]

        return merge_key_bindings(key_bindings) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:55,代碼來源:application.py

示例12: has_focus

# 需要導入模塊: from prompt_toolkit.layout import containers [as 別名]
# 或者: from prompt_toolkit.layout.containers import Window [as 別名]
def has_focus(value: "FocusableElement") -> Condition:
    """
    Enable when this buffer has the focus.
    """
    from prompt_toolkit.buffer import Buffer
    from prompt_toolkit.layout.controls import UIControl
    from prompt_toolkit.layout.containers import to_container, Window, Container
    from prompt_toolkit.layout import walk

    if isinstance(value, str):

        def test() -> bool:
            return get_app().current_buffer.name == value

    elif isinstance(value, Buffer):

        def test() -> bool:
            return get_app().current_buffer == value

    elif isinstance(value, UIControl):

        def test() -> bool:
            return get_app().layout.current_control == value

    else:
        value = to_container(value)

        if isinstance(value, Window):

            def test() -> bool:
                return get_app().layout.current_window == value

        else:

            def test() -> bool:
                # Consider focused when any window inside this container is
                # focused.
                current_window = get_app().layout.current_window

                for c in walk(cast(Container, value)):
                    if isinstance(c, Window) and c == current_window:
                        return True
                return False

    @Condition
    def has_focus_filter() -> bool:
        return test()

    return has_focus_filter 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:51,代碼來源:app.py


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