本文整理汇总了Python中prompt_toolkit.layout.dimension.LayoutDimension类的典型用法代码示例。如果您正苦于以下问题:Python LayoutDimension类的具体用法?Python LayoutDimension怎么用?Python LayoutDimension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LayoutDimension类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dimensions
def get_dimensions(cli):
"""
Return a list of LayoutDimension instances for this split.
These dimensions will take the weight from the
arrangement.VSplit/HSplit instances.
"""
average_weight = get_average_weight()
# Make sure that weight is distributed
result = []
for i, item in enumerate(split):
result.append(D(weight=split.weights.get(item) or average_weight))
# Add dimension for the vertical border.
last_item = i == len(split) - 1
if is_vsplit and not last_item:
result.append(D.exact(1))
elif is_hsplit and not last_item:
if pymux.enable_pane_status:
result.append(D.exact(0))
else:
result.append(D.exact(1))
return result
示例2: __init__
def __init__(self, python_input):
token = Token.Toolbar.Status
version = sys.version_info
tokens = [
(token, ' [F2] Options'),
(token, ' - '),
(token.PythonVersion, '%s %i.%i.%i' % (platform.python_implementation(),
version[0], version[1], version[2])),
(token, ' '),
]
width = token_list_width(tokens)
def get_tokens(cli):
# Python version
return tokens
super(ShowSidebarButtonInfo, self).__init__(
content=Window(
TokenListControl(get_tokens, default_char=Char(token=token)),
height=LayoutDimension.exact(1),
width=LayoutDimension.exact(width)),
filter=~IsDone() & RendererHeightIsKnown() &
Condition(lambda cli: python_input.show_status_bar and
not python_input.show_exit_confirmation))
示例3: __init__
def __init__(self, editor, buffer_window, buffer_name):
def get_scroll_text():
info = buffer_window.render_info
if info:
if info.full_height_visible:
return 'All'
elif info.top_visible:
return 'Top'
elif info.bottom_visible:
return 'Bot'
else:
percentage = info.vertical_scroll_percentage
return '%2i%%' % percentage
return ''
def get_tokens(cli):
main_document = cli.buffers[buffer_name].document
return [
(Token.Toolbar.CursorPosition, '(%i,%i)' % (main_document.cursor_position_row + 1,
main_document.cursor_position_col + 1)),
(Token.Toolbar, ' - '),
(Token.Toolbar.Percentage, get_scroll_text()),
(Token.Toolbar, ' '),
]
super(WindowStatusBarRuler, self).__init__(
Window(
TokenListControl(get_tokens, default_char=Char(' ', Token.Toolbar), align_right=True),
height=LayoutDimension.exact(1),
width=LayoutDimension.exact(15)),
filter=Condition(lambda cli: editor.show_ruler))
示例4: __init__
def __init__(self, python_input):
def get_tokens(cli):
tokens = []
T = Token.Sidebar
# Show navigation info.
tokens.extend([
(T.Separator , ' ' * 43 + '\n'),
(T, ' '),
(T.Key, '[Arrows]'),
(T, ' '),
(T.Key.Description, 'Navigate'),
(T, ' '),
(T.Key, '[Enter]'),
(T, ' '),
(T.Key.Description, 'Hide menu'),
])
return tokens
super(PythonSidebarNavigation, self).__init__(
TokenListControl(get_tokens, Char(token=Token.Sidebar)),
width=LayoutDimension.exact(43),
height=LayoutDimension.exact(2),
filter=ShowSidebar(python_input) & ~IsDone())
示例5: python_sidebar_navigation
def python_sidebar_navigation(python_input):
"""
Create the `Layout` showing the navigation information for the sidebar.
"""
def get_tokens(cli):
tokens = []
T = Token.Sidebar
# Show navigation info.
tokens.extend([
(T.Separator, ' ' * 43 + '\n'),
(T, ' '),
(T.Key, '[Arrows]'),
(T, ' '),
(T.Key.Description, 'Navigate'),
(T, ' '),
(T.Key, '[Enter]'),
(T, ' '),
(T.Key.Description, 'Hide menu'),
])
return tokens
return ConditionalContainer(
content=Window(
TokenListControl(get_tokens, Char(token=Token.Sidebar)),
width=LayoutDimension.exact(43),
height=LayoutDimension.exact(2)),
filter=ShowSidebar(python_input) & ~IsDone())
示例6: show_sidebar_button_info
def show_sidebar_button_info(python_input):
"""
Create `Layout` for the information in the right-bottom corner.
(The right part of the status bar.)
"""
@if_mousedown
def toggle_sidebar(cli, mouse_event):
" Click handler for the menu. "
python_input.show_sidebar = not python_input.show_sidebar
token = Token.Toolbar.Status
version = sys.version_info
tokens = [
(token.Key, '[F2]', toggle_sidebar),
(token, ' Menu', toggle_sidebar),
(token, ' - '),
(token.PythonVersion, '%s %i.%i.%i' % (platform.python_implementation(),
version[0], version[1], version[2])),
(token, ' '),
]
width = token_list_width(tokens)
def get_tokens(cli):
# Python version
return tokens
return ConditionalContainer(
content=Window(
TokenListControl(get_tokens, default_char=Char(token=token)),
height=LayoutDimension.exact(1),
width=LayoutDimension.exact(width)),
filter=~IsDone() & RendererHeightIsKnown() &
Condition(lambda cli: python_input.show_status_bar and
not python_input.show_exit_confirmation))
示例7: get_anyhline
def get_anyhline(config):
""" if there is a line between descriptions and example """
if config.BOOLEAN_STATES[config.config.get('Layout', 'command_description')] or\
config.BOOLEAN_STATES[config.config.get('Layout', 'param_description')]:
return Window(
width=LayoutDimension.exact(1),
height=LayoutDimension.exact(1),
content=FillControl('-', token=Token.Line))
return get_empty()
示例8: signature_toolbar
def signature_toolbar(python_input):
"""
Return the `Layout` for the signature.
"""
def get_tokens(cli):
result = []
append = result.append
Signature = Token.Toolbar.Signature
if python_input.signatures:
sig = python_input.signatures[0] # Always take the first one.
append((Signature, ' '))
try:
append((Signature, sig.full_name))
except IndexError:
# Workaround for #37: https://github.com/jonathanslenders/python-prompt-toolkit/issues/37
# See also: https://github.com/davidhalter/jedi/issues/490
return []
append((Signature.Operator, '('))
for i, p in enumerate(sig.params):
# Workaround for #47: 'p' is None when we hit the '*' in the signature.
# and sig has no 'index' attribute.
# See: https://github.com/jonathanslenders/ptpython/issues/47
# https://github.com/davidhalter/jedi/issues/598
description = (p.description if p else '*') #or '*'
sig_index = getattr(sig, 'index', 0)
if i == sig_index:
# Note: we use `_Param.description` instead of
# `_Param.name`, that way we also get the '*' before args.
append((Signature.CurrentName, str(description)))
else:
append((Signature, str(description)))
append((Signature.Operator, ', '))
if sig.params:
# Pop last comma
result.pop()
append((Signature.Operator, ')'))
append((Signature, ' '))
return result
return ConditionalContainer(
content=Window(
TokenListControl(get_tokens),
height=LayoutDimension.exact(1)),
filter=
# Show only when there is a signature
HasSignature(python_input) &
# And there are no completions to be shown. (would cover signature pop-up.)
~(HasCompletions() & (show_completions_menu(python_input) |
show_multi_column_completions_menu(python_input)))
# Signature needs to be shown.
& ShowSignature(python_input) &
# Not done yet.
~IsDone())
示例9: __init__
def __init__(self, python_input):
def get_tokens(cli):
tokens = []
T = Token.Sidebar
tokens.extend([
(T, ' '),
(T.Title, 'Options'),
(T, '\n'),
])
def append(selected, label, status):
token = T.Selected if selected else T
tokens.append((T, ' >' if selected else ' '))
tokens.append((token.Label, '%-24s' % label))
tokens.append((token.Status, ' %-14s' % status))
tokens.append((T, '<' if selected else ''))
tokens.append((T, '\n'))
for i, option in enumerate(python_input.options):
append(i == python_input.selected_option,
option.description, '%s' % option.get_current_value())
tokens.pop() # Remove last newline.
return tokens
super(PythonSidebar, self).__init__(
TokenListControl(get_tokens, Char(token=Token.Sidebar)),
width=LayoutDimension.exact(43),
filter=ShowSidebar(python_input) & ~IsDone())
示例10: create_default_layout
def create_default_layout(message='', lexer=None, is_password=False,
reserve_space_for_menu=False, get_bottom_toolbar_tokens=None,
extra_input_processors=None):
"""
Generate default layout.
"""
assert get_bottom_toolbar_tokens is None or callable(get_bottom_toolbar_tokens)
# Create processors list.
# (DefaultPrompt should always be at the end.)
input_processors = [HighlightSearchProcessor(preview_search=Always()),
HighlightSelectionProcessor()]
if extra_input_processors:
input_processors.extend(extra_input_processors)
if is_password:
input_processors.extend([PasswordProcessor(), DefaultPrompt(message)])
else:
input_processors.append(DefaultPrompt(message))
# Create bottom toolbar.
if get_bottom_toolbar_tokens:
toolbars = [Window(TokenListControl(get_bottom_toolbar_tokens,
default_char=Char(' ', Token.Toolbar)),
height=LayoutDimension.exact(1),
filter=~IsDone())]
else:
toolbars = []
def get_height(cli):
# If there is an autocompletion menu to be shown, make sure that our
# layout has at least a minimal height in order to display it.
if reserve_space_for_menu and not cli.is_done:
return LayoutDimension(min=8)
else:
return LayoutDimension()
# Create and return Layout instance.
return HSplit([
FloatContainer(
Window(
BufferControl(
input_processors=input_processors,
lexer=lexer,
# Enable preview_search, we want to have immediate feedback
# in reverse-i-search mode.
preview_search=Always()),
get_height=get_height,
),
[
Float(xcursor=True,
ycursor=True,
content=CompletionsMenu(max_height=16,
extra_filter=HasFocus(DEFAULT_BUFFER)))
]
),
ValidationToolbar(),
SystemToolbar(),
] + toolbars)
示例11: __init__
def __init__(self):
super(CommandLine, self).__init__(
BufferControl(
buffer_name=COMMAND_BUFFER,
input_processors=[BeforeInput.static(':')],
lexer=create_command_lexer()),
height=LayoutDimension.exact(1),
filter=HasFocus(COMMAND_BUFFER))
示例12: python_sidebar
def python_sidebar(python_input):
"""
Create the `Layout` for the sidebar with the configurable options.
"""
def get_tokens(cli):
tokens = []
T = Token.Sidebar
def append_category(category):
tokens.extend([
(T, ' '),
(T.Title, ' %-36s' % category.title),
(T, '\n'),
])
def append(selected, label, status):
token = T.Selected if selected else T
tokens.append((T, ' >' if selected else ' '))
tokens.append((token.Label, '%-24s' % label))
tokens.append((token.Status, ' '))
tokens.append((token.Status, '%s' % status))
if selected:
tokens.append((Token.SetCursorPosition, ''))
tokens.append((token.Status, ' ' * (14 - len(status))))
tokens.append((T, '<' if selected else ''))
tokens.append((T, '\n'))
i = 0
for category in python_input.options:
append_category(category)
for option in category.options:
append(i == python_input.selected_option_index,
option.title, '%s' % option.get_current_value())
i += 1
tokens.pop() # Remove last newline.
return tokens
class Control(TokenListControl):
def move_cursor_down(self, cli):
python_input.selected_option_index += 1
def move_cursor_up(self, cli):
python_input.selected_option_index -= 1
return ConditionalContainer(
content=Window(
Control(get_tokens, Char(token=Token.Sidebar),
has_focus=ShowSidebar(python_input) & ~IsDone()),
width=LayoutDimension.exact(43),
height=LayoutDimension(min=3),
scroll_offsets=ScrollOffsets(top=1, bottom=1)),
filter=ShowSidebar(python_input) & ~IsDone())
示例13: __init__
def __init__(self, settings):
super(SignatureToolbar, self).__init__(
SignatureControl(settings),
height=LayoutDimension.exact(1),
filter=
# Show only when there is a signature
HasSignature(settings) &
# And there are no completions to be shown. (would cover signature pop-up.)
(~HasCompletions() | ~ShowCompletionsMenu(settings))
# Signature needs to be shown.
& ShowSignature(settings) &
# Not done yet.
~IsDone())
示例14: get_dimensions
def get_dimensions(cli):
"""
Return a list of LayoutDimension instances for this split.
These dimensions will take the weight from the
arrangement.VSplit/HSplit instances.
"""
average_weight = get_average_weight()
# Make sure that weight is distributed
result = []
for i, item in enumerate(split):
result.append(D(weight=split.weights.get(item) or average_weight))
# Add dimension for the vertical border.
if is_vsplit and i != len(split) - 1:
result.append(D.exact(1))
return result
示例15: create_layout_from_node
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 = self._create_window_frame(node.editor_buffer)
self._frames[key] = frame
return frame
elif isinstance(node, window_arrangement.VSplit):
children = []
for n in node:
children.append(create_layout_from_node(n))
children.append(Window(width=LayoutDimension.exact(1),
content=FillControl('\u2502', token=Token.FrameBorder)))
children.pop()
return VSplit(children)
if isinstance(node, window_arrangement.HSplit):
return HSplit([create_layout_from_node(n) for n in node])