Python prompt_toolkit.layout.containers.HSplit() Examples
The following are 8
code examples of prompt_toolkit.layout.containers.HSplit().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prompt_toolkit.layout.containers
, or try the search function
.
Example #1
Source File: layout.py From pymux with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 = {}
Example #2
Source File: layout.py From pymux with BSD 3-Clause "New" or "Revised" License | 6 votes |
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) ])
Example #3
Source File: dialogs.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #4
Source File: dialogs.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #5
Source File: dialogs.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: test_layout.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #7
Source File: application.py From python-sploitkit with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #8
Source File: dialogs.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 4 votes |
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