| 572 | |
| 573 | |
| 574 | class PtPythonLayout: |
| 575 | def __init__( |
| 576 | self, |
| 577 | python_input: PythonInput, |
| 578 | lexer: Lexer, |
| 579 | extra_body: AnyContainer | None = None, |
| 580 | extra_toolbars: list[AnyContainer] | None = None, |
| 581 | extra_buffer_processors: list[Processor] | None = None, |
| 582 | input_buffer_height: AnyDimension | None = None, |
| 583 | ) -> None: |
| 584 | D = Dimension |
| 585 | extra_body_list: list[AnyContainer] = [extra_body] if extra_body else [] |
| 586 | extra_toolbars = extra_toolbars or [] |
| 587 | |
| 588 | input_buffer_height = input_buffer_height or D(min=6) |
| 589 | |
| 590 | search_toolbar = SearchToolbar(python_input.search_buffer) |
| 591 | |
| 592 | def create_python_input_window() -> Window: |
| 593 | def menu_position() -> int | None: |
| 594 | """ |
| 595 | When there is no autocompletion menu to be shown, and we have a |
| 596 | signature, set the pop-up position at `bracket_start`. |
| 597 | """ |
| 598 | b = python_input.default_buffer |
| 599 | |
| 600 | if python_input.signatures: |
| 601 | row, col = python_input.signatures[0].bracket_start |
| 602 | index = b.document.translate_row_col_to_index(row - 1, col) |
| 603 | return index |
| 604 | return None |
| 605 | |
| 606 | return Window( |
| 607 | BufferControl( |
| 608 | buffer=python_input.default_buffer, |
| 609 | search_buffer_control=search_toolbar.control, |
| 610 | lexer=lexer, |
| 611 | include_default_input_processors=False, |
| 612 | input_processors=[ |
| 613 | ConditionalProcessor( |
| 614 | processor=HighlightIncrementalSearchProcessor(), |
| 615 | filter=has_focus(SEARCH_BUFFER) |
| 616 | | has_focus(search_toolbar.control), |
| 617 | ), |
| 618 | HighlightSelectionProcessor(), |
| 619 | DisplayMultipleCursors(), |
| 620 | TabsProcessor(), |
| 621 | # Show matching parentheses, but only while editing. |
| 622 | ConditionalProcessor( |
| 623 | processor=HighlightMatchingBracketProcessor(chars="[](){}"), |
| 624 | filter=has_focus(DEFAULT_BUFFER) |
| 625 | & ~is_done |
| 626 | & Condition( |
| 627 | lambda: python_input.highlight_matching_parenthesis |
| 628 | ), |
| 629 | ), |
| 630 | ConditionalProcessor( |
| 631 | processor=AppendAutoSuggestion(), filter=~is_done |