本文整理汇总了Python中prompt_toolkit.layout.containers.HSplit方法的典型用法代码示例。如果您正苦于以下问题:Python containers.HSplit方法的具体用法?Python containers.HSplit怎么用?Python containers.HSplit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.layout.containers
的用法示例。
在下文中一共展示了containers.HSplit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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 = {}
示例2: _build_layout
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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)
])
示例3: input_dialog
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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)
示例4: radiolist_dialog
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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)
示例5: checkboxlist_dialog
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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)
示例6: test_layout_class
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [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
示例7: __init__
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [as 别名]
def __init__(self, *args, **kwargs):
console = kwargs.get('console')
if console is None:
raise Exception("No root console passed to the application")
#console.__class__ = type("ConsoleTextArea",
# (TextArea, console.__class__), {})
#console.scrollbar = True
root_container = HSplit([
console,
])
kwargs['layout'] = Layout(root_container, focused_element=console)
super(FrameworkApp, self).__init__(*args, **kwargs)
示例8: progress_dialog
# 需要导入模块: from prompt_toolkit.layout import containers [as 别名]
# 或者: from prompt_toolkit.layout.containers import HSplit [as 别名]
def progress_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
run_callback: Callable[[Callable[[int], None], Callable[[str], None]], None] = (
lambda *a: None
),
style: Optional[BaseStyle] = None,
) -> Application[None]:
"""
:param run_callback: A function that receives as input a `set_percentage`
function and it does the work.
"""
loop = get_event_loop()
progressbar = ProgressBar()
text_area = TextArea(
focusable=False,
# Prefer this text area as big as possible, to avoid having a window
# that keeps resizing when we add text to it.
height=D(preferred=10 ** 10),
)
dialog = Dialog(
body=HSplit(
[Box(Label(text=text)), Box(text_area, padding=D.exact(1)), progressbar,]
),
title=title,
with_background=True,
)
app = _create_app(dialog, style)
def set_percentage(value: int) -> None:
progressbar.percentage = int(value)
app.invalidate()
def log_text(text: str) -> None:
loop.call_soon_threadsafe(text_area.buffer.insert_text, text)
app.invalidate()
# Run the callback in the executor. When done, set a return value for the
# UI, so that it quits.
def start() -> None:
try:
run_callback(set_percentage, log_text)
finally:
app.exit()
def pre_run() -> None:
run_in_executor_with_context(start)
app.pre_run_callables.append(pre_run)
return app