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


Python application.Application方法代碼示例

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


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

示例1: listen_on_socket

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def listen_on_socket(self, socket_name=None):
        """
        Listen for clients on a Unix socket.
        Returns the socket name.
        """
        def connection_cb(pipe_connection):
            # We have to create a new `context`, because this will be the scope for
            # a new prompt_toolkit.Application to become active.
            with context():
                connection = ServerConnection(self, pipe_connection)

            self.connections.append(connection)

        self.socket_name = bind_and_listen_on_socket(socket_name, connection_cb)

        # Set session_name according to socket name.
#        if '.' in self.socket_name:
#            self.session_name = self.socket_name.rpartition('.')[-1]

        logger.info('Listening on %r.' % self.socket_name)
        return self.socket_name 
開發者ID:prompt-toolkit,項目名稱:pymux,代碼行數:23,代碼來源:main.py

示例2: print_container

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def print_container(container: "Container", file: Optional[TextIO] = None) -> None:
    """
    Print any layout to the output in a non-interactive way.

    Example usage::

        from prompt_toolkit.widgets import Frame, TextArea
        print_container(
            Frame(TextArea(text='Hello world!')))
    """
    if file:
        output = create_output(stdout=file)
    else:
        output = get_app_session().output

    def exit_immediately() -> None:
        # Use `call_from_executor` to exit "soon", so that we still render one
        # initial time, before exiting the application.
        get_event_loop().call_soon(lambda: app.exit())

    app: Application[None] = Application(
        layout=Layout(container=container), output=output, input=DummyInput()
    )
    app.run(pre_run=exit_immediately) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:26,代碼來源:utils.py

示例3: message_dialog

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def message_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    ok_text: str = "Ok",
    style: Optional[BaseStyle] = None,
) -> Application[None]:
    """
    Display a simple message box and wait until the user presses enter.
    """
    dialog = Dialog(
        title=title,
        body=Label(text=text, dont_extend_height=True),
        buttons=[Button(text=ok_text, handler=_return_none),],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:19,代碼來源:dialogs.py

示例4: _create_application

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

示例5: _

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def _(event):
    " Quit application. "
    event.app.exit()


# 3. The `Application` 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:8,代碼來源:alignment.py

示例6: _

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def _(event):
    " Disable/enable wrapping. "
    global wrap_lines
    wrap_lines = not wrap_lines


# The `Application` 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:9,代碼來源:line-prefixes.py

示例7: _

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def _(event):
    event.app.layout.focus_previous()


# 3. The `Application` 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:7,代碼來源:focus.py

示例8: app

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def app(self) -> "Application[Any]":
        """
        The current `Application` object.
        """
        return self._app 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:7,代碼來源:key_processor.py

示例9: cli

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def cli(self) -> "Application":
        " For backward-compatibility. "
        return self.app 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:5,代碼來源:key_processor.py

示例10: yes_no_dialog

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def yes_no_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    yes_text: str = "Yes",
    no_text: str = "No",
    style: Optional[BaseStyle] = None,
) -> Application[bool]:
    """
    Display a Yes/No dialog.
    Return a boolean.
    """

    def yes_handler() -> None:
        get_app().exit(result=True)

    def no_handler() -> None:
        get_app().exit(result=False)

    dialog = Dialog(
        title=title,
        body=Label(text=text, dont_extend_height=True),
        buttons=[
            Button(text=yes_text, handler=yes_handler),
            Button(text=no_text, handler=no_handler),
        ],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:31,代碼來源:dialogs.py

示例11: input_dialog

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def input_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    ok_text: str = "OK",
    cancel_text: str = "Cancel",
    completer: Optional[Completer] = None,
    password: FilterOrBool = False,
    style: Optional[BaseStyle] = None,
) -> Application[str]:
    """
    Display a text input box.
    Return the given text, or None when cancelled.
    """

    def accept(buf: Buffer) -> bool:
        get_app().layout.focus(ok_button)
        return True  # Keep text.

    def ok_handler() -> None:
        get_app().exit(result=textfield.text)

    ok_button = Button(text=ok_text, handler=ok_handler)
    cancel_button = Button(text=cancel_text, handler=_return_none)

    textfield = TextArea(
        multiline=False, password=password, completer=completer, accept_handler=accept
    )

    dialog = Dialog(
        title=title,
        body=HSplit(
            [Label(text=text, dont_extend_height=True), textfield,],
            padding=D(preferred=1, max=1),
        ),
        buttons=[ok_button, cancel_button],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:41,代碼來源:dialogs.py

示例12: radiolist_dialog

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def radiolist_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    ok_text: str = "Ok",
    cancel_text: str = "Cancel",
    values: Optional[List[Tuple[_T, AnyFormattedText]]] = None,
    style: Optional[BaseStyle] = None,
) -> Application[_T]:
    """
    Display a simple list of element the user can choose amongst.

    Only one element can be selected at a time using Arrow keys and Enter.
    The focus can be moved between the list and the Ok/Cancel button with tab.
    """
    if values is None:
        values = []

    def ok_handler() -> None:
        get_app().exit(result=radio_list.current_value)

    radio_list = RadioList(values)

    dialog = Dialog(
        title=title,
        body=HSplit(
            [Label(text=text, dont_extend_height=True), radio_list,], padding=1
        ),
        buttons=[
            Button(text=ok_text, handler=ok_handler),
            Button(text=cancel_text, handler=_return_none),
        ],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:37,代碼來源:dialogs.py

示例13: checkboxlist_dialog

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def checkboxlist_dialog(
    title: AnyFormattedText = "",
    text: AnyFormattedText = "",
    ok_text: str = "Ok",
    cancel_text: str = "Cancel",
    values: Optional[List[Tuple[_T, AnyFormattedText]]] = None,
    style: Optional[BaseStyle] = None,
) -> Application[List[_T]]:
    """
    Display a simple list of element the user can choose multiple values amongst.

    Several elements can be selected at a time using Arrow keys and Enter.
    The focus can be moved between the list and the Ok/Cancel button with tab.
    """
    if values is None:
        values = []

    def ok_handler() -> None:
        get_app().exit(result=cb_list.current_values)

    cb_list = CheckboxList(values)

    dialog = Dialog(
        title=title,
        body=HSplit([Label(text=text, dont_extend_height=True), cb_list,], padding=1),
        buttons=[
            Button(text=ok_text, handler=ok_handler),
            Button(text=cancel_text, handler=_return_none),
        ],
        with_background=True,
    )

    return _create_app(dialog, style) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:35,代碼來源:dialogs.py

示例14: set_dummy_app

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def set_dummy_app():
    """
    Return a context manager that makes sure that this dummy application is
    active. This is important, because we need an `Application` with
    `is_done=False` flag, otherwise no keys will be processed.
    """
    app = Application(
        layout=Layout(Window()), output=DummyOutput(), input=create_pipe_input()
    )
    return set_app(app) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:12,代碼來源:test_key_binding.py

示例15: _create_application

# 需要導入模塊: from prompt_toolkit import application [as 別名]
# 或者: from prompt_toolkit.application import Application [as 別名]
def _create_application(self):
        """
        Create CommandLineInterface instance.
        """
        # Create Application.
        application = Application(
            input=self.input,
            output=self.output,
            editing_mode=EditingMode.VI,
            layout=self.editor_layout.layout,
            key_bindings=self.key_bindings,
#            get_title=lambda: get_terminal_title(self),
            style=DynamicStyle(lambda: self.current_style),
            paste_mode=Condition(lambda: self.paste_mode),
#            ignore_case=Condition(lambda: self.ignore_case),  # TODO
            include_default_pygments_style=False,
            mouse_support=Condition(lambda: self.enable_mouse_support),
            full_screen=True,
            enable_page_navigation_bindings=True)

        # Handle command line previews.
        # (e.g. when typing ':colorscheme blue', it should already show the
        # preview before pressing enter.)
        def preview(_):
            if self.application.layout.has_focus(self.command_buffer):
                self.previewer.preview(self.command_buffer.text)
        self.command_buffer.on_text_changed += preview

        return application 
開發者ID:prompt-toolkit,項目名稱:pyvim,代碼行數:31,代碼來源:editor.py


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