本文整理汇总了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
示例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)
示例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)
示例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,
)
示例5: _
# 需要导入模块: from prompt_toolkit import application [as 别名]
# 或者: from prompt_toolkit.application import Application [as 别名]
def _(event):
" Quit application. "
event.app.exit()
# 3. The `Application`
示例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`
示例7: _
# 需要导入模块: from prompt_toolkit import application [as 别名]
# 或者: from prompt_toolkit.application import Application [as 别名]
def _(event):
event.app.layout.focus_previous()
# 3. The `Application`
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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