def main(): # Create a big layout of many text areas, then wrap them in a `ScrollablePane`. root_container = Frame( ScrollablePane( HSplit([ Frame(TextArea(text=f"label-{i}"), width=Dimension()) for i in range(20) ])) # ScrollablePane(HSplit([TextArea(text=f"label-{i}") for i in range(20)])) ) layout = Layout(container=root_container) # Key bindings. kb = KeyBindings() @kb.add("c-c") def exit(event) -> None: get_app().exit() kb.add("tab")(focus_next) kb.add("s-tab")(focus_previous) # Create and run application. application = Application(layout=layout, key_bindings=kb, full_screen=True) application.run()
def get_root_container(self) -> FloatContainer: buttons = [ *self._game_buttons.keys(), HorizontalLine(), Button("Quit", width=MENU_BUTTON_WIDTH, handler=self._exit), ] menu_keybindings = _create_menu_keybindings(buttons) game_buttons_container = Frame( HSplit( buttons, width=Dimension(min=MENU_BUTTON_WIDTH, max=40), height=Dimension(), ), title="Games", key_bindings=menu_keybindings, ) game_description_container = Frame( Box( Label( text=self._get_game_description, dont_extend_height=False, width=Dimension(min=40), ), padding=0, padding_left=1, ), ) return FloatContainer(VSplit([ game_buttons_container, game_description_container, ]), floats=[])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.riitag_info = user.RiitagInfo() # placeholder self.menu_settings_button = Button( 'Settings', handler=lambda: self._set_state('Settings')) self.menu_exit_button = Button('Exit', handler=self.quit_app) self.menu_logout_button = Button('Logout', handler=self._logout) self.settings_back_button = Button( 'Back...', width=12, handler=lambda: self._set_state('Menu')) self.settings_reset_button = Button('Reset...', width=12, handler=self._reset_preferences) self.settings_pres_timeout_button = PreferenceButton( value=self.app.preferences.presence_timeout, increments=10, limits=(10, 120)) self.settings_check_interval_button = PreferenceButton( value=self.app.preferences.check_interval, increments=10, limits=(10, 60)) self.right_panel_state = 'Menu' self.menu_layout = Frame(Box(HSplit([ self.menu_settings_button, Label(''), self.menu_exit_button, self.menu_logout_button, ]), padding_left=3, padding_top=2), title='Menu') self.settings_layout = Frame(Box(HSplit([ Window(FormattedTextControl( HTML( 'This is where you can modify settings\nregarding the underlying presence\nwatcher.' )), wrap_lines=True, width=25), Label(''), VSplit([ Label('Presence Timeout (min.):'), self.settings_pres_timeout_button ], width=15), VSplit([ Label('Refresh Interval (sec.):'), self.settings_check_interval_button ], padding=3), Label(''), VSplit([self.settings_back_button, self.settings_reset_button], align=WindowAlign.CENTER) ]), padding_left=3, padding_top=2), title='Settings')
def ToolbarFrame(body, toolbar_content, put_on_top=False): if put_on_top: return HSplit([toolbar_content, Frame(body)]) toolbar = ConditionalContainer(content=toolbar_content, filter=renderer_height_is_known) return HSplit([Frame(body), toolbar])
def make_canvas(_noise, args): global noise global debug_file global root_container noise = _noise ui = [ VSplit( [ Frame( title="Delete noise until only signal remains", body=Window(content=BufferControl(buffer=buffer)), ), Frame( title="Signals", body=Window(width=15, content=subcanvasses_display), ), Frame(title="Gaps", body=Window(width=10, content=gaps_display)), ] ), VSplit( [ Window(content=FormattedTextControl(text=legend_left)), Window(content=FormattedTextControl(text=legend_center)), Window( content=FormattedTextControl(text=legend_right), align=WindowAlign.RIGHT, ), ] ), ] if args.debug: debug_file = open(config.runtime.debug_log, "w") debug(f"cog started {datetime.now()}") ui.append(HorizontalLine()) ui.append(Window(content=debug_display)) root_container = HSplit(ui) subcanvasses.append(Data(Kind.signal, noise)) # start with the input noise as the signal buffer.text = noise kb = KeyBindings() @kb.add("c-c") def done(event): event.app.exit() # https://github.com/prompt-toolkit/python-prompt-toolkit/issues/502#issuecomment-466591259 sys.stdin = sys.stderr Application( key_bindings=kb, layout=Layout(root_container), editing_mode=EditingMode.VI ).run()
def __init__(self, title: str = "DLNest Output", routineTask=None, freq: int = 1, style: str = "class_analyzer_output"): super(AnalyzeOutput, self).__init__(title, routineTask, freq, style) self.infoText = FormattedTextControl( [("", " No analyze task is running ")], focusable=False, show_cursor=False) self.infoWindow = Window(content=self.infoText) self.infoLabel = Box( body=self.infoWindow, height=3, padding_top=1, padding_bottom=1, # padding_left=3, # padding_right=3, style="class:analyzer_info_label") self.window = Frame(HSplit([self.infoLabel, self.shower]), title=self.title, style=self.style, modal=True, key_bindings=self.kb)
def __init__(self, title: str = "DLNest Output", routineTask=None, freq: int = 1, style: str = "class:results_output"): self.title = title self.routineTask = routineTask self.scheduler = BackgroundScheduler() if not routineTask is None: self.scheduler.add_job(self.routineTask, 'interval', seconds=freq, args=[self]) self.scheduler.start() self.lexer = styledTextLexer() self.shower = SCTextArea(self.lexer) self.style = style self.setKeyBinding() self.window = Frame(self.shower, self.title, style=self.style, modal=True, key_bindings=self.kb)
def make_app(sec, width, height, frame=True, gcalender=None, color=False): """make auto refresh application class""" kb = KeyBindings() @kb.add('c-c') def _(event): event.app.exit() def _vsplit(padding, m): return VSplit([Window(width=padding, always_hide_cursor=True), m, Window(width=padding, always_hide_cursor=True)]) if height == 14: clock = BigClock(sec=sec, color=color, gcalender=gcalender) elif height == 7: clock = MinimumClock(sec=sec, color=color, gcalender=gcalender) else: clock = SmallClock(sec=sec, color=color, gcalender=gcalender) padding = to_dimension(D(preferred=0)) body = Window(content=FormattedTextControl(text=clock.get_clock), width=width, height=height, always_hide_cursor=True) if frame: body = Frame(body) if gcalender is None: under_text = Window(height=padding, always_hide_cursor=True) else: ct = gcalender.get_calender_text_formatted if color else gcalender.get_calender_text under_text = Window(content=FormattedTextControl(text=ct), width=gcalender.get_max_length(), height=padding, always_hide_cursor=True) # make container app root_container = HSplit([Window(height=padding, always_hide_cursor=True), _vsplit(padding, body), _vsplit(padding, under_text)], key_bindings=None) layout = Layout(container=root_container) return Application(layout=layout, key_bindings=kb, full_screen=True, refresh_interval=.1)
def get_root_container(self) -> FloatContainer: header_row = self.table.format_table().splitlines()[0] data_rows = self.table.format_table().splitlines()[1:] row_buttons = [ SelectableLabel(row, handler=functools.partial(self._handle_answer, i)) for i, row in enumerate(data_rows) ] table_container = HSplit([ Label(FormattedText([("class:column-name", header_row)]), ), HorizontalLine(), *row_buttons, ]) rules_container = Box( Label( self.table.format_constraints(separator="\n\n"), dont_extend_width=True, ), ) return FloatContainer( Box( Frame( VSplit([ table_container, VerticalLine(), rules_container, ])), ), floats=[], )
def get_user_comment(self): """Modifies the display to add an area to enter a comment for a command Creates a BufferControl in a Frame and replaces the toolbar with the Frame #bug: the new toolbar is unable to get focus right away; it requires the user to click in the area """ self._savedLayout = self.layout self.disabled_bindings = True commentControl = BufferControl( Buffer(accept_handler=self._set_user_comment), focus_on_click=True) user_in_area = Frame( Window( commentControl, height=Dimension(max=1, weight=10000), dont_extend_height=True, ), title="Enter Comment (alt-Enter to submit)", ) self.toolbar = user_in_area self.main_view = HSplit([self.body, self.toolbar], padding_char="-") self.layout = Layout(self.main_view, focused_element=user_in_area.body) self.layout.focus(user_in_area.body) self.invalidate()
def show_message(self, title, message, callback=None): cancel_button = Button('Cancel', handler=lambda: response_received(False)) ok_button = Button('OK', handler=lambda: response_received(True)) def response_received(is_ok): if callback: callback(is_ok) self._float_message_layout = None self.layout.focus_next() self.invalidate() message_frame = Frame( HSplit([ Window(FormattedTextControl(HTML(message + '\n\n')), align=WindowAlign.CENTER), VSplit([ cancel_button, ok_button ], padding=3, align=WindowAlign.CENTER) ], padding=1), title=title, ) self._float_message_layout = message_frame self.layout.focus(cancel_button) self.invalidate()
def __init__( self, title : str = "Tasks", routineTask = None, freq : int = 1, style : str = "class:task_info_shower" ): self.title = title self.routineTask = routineTask self.scheduler = BackgroundScheduler() if not routineTask is None: self.scheduler.add_job(self.routineTask,'interval',seconds=freq,args=[self]) self.scheduler.start() self.lexer =taskLexer() self.shower = SCTextArea( lexer = self.lexer, wrap_lines=False ) self.style = style self.window = Frame( self.shower, self.title, style = self.style, height=10 )
def __init__(self, notebook, idx: int = 0, cell_json: Optional[Dict[str, Any]] = None): self.notebook = notebook if cell_json is None: cell_json = { "cell_type": "code", "execution_count": None, "metadata": {}, "source": [], "outputs": [], } self.input_prefix = Window(width=10) input_text = "".join(cell_json["source"]) if cell_json["cell_type"] == "code": execution_count = cell_json["execution_count"] or " " self.input_prefix.content = FormattedTextControl( text=f"\nIn [{execution_count}]:") if "outputs" in cell_json: outputs = cell_json["outputs"] else: outputs = [] self.json = cell_json output_text, output_height = get_output_text_and_height(outputs) self.idx = idx self.input_window = Window() self.input_buffer = Buffer(on_text_changed=self.input_text_changed) self.input_buffer.text = input_text self.set_input_readonly() self.input = Frame(self.input_window) self.output = Window(content=FormattedTextControl(text=output_text)) self.output.height = output_height
def __init__(self, buffer, **kwargs): self.buffer = buffer self.before_input_text = kwargs.get("before_input_text", "➜ ") self.title = kwargs.get("title", "COMMAND SHELL") self._buffer = buffer self._buffer_control = BufferControl( buffer=self.buffer, input_processors=[BeforeInput(text=self.before_input_text)], focus_on_click=True, ) self.window = Frame( title=self.title, key_bindings=self.kbindings(), body=FloatContainer( content=Window(self._buffer_control), key_bindings=None, floats=[ Float( xcursor=True, ycursor=True, content=CompletionsMenu(max_height=5, scroll_offset=1), ) ], ), height=3, )
def get_root_container(self): solution_containers = [ HSplit([ self._get_grid_container(grid), Button( "Select", functools.partial(self.multi_screen.app.exit, result=grid)), ]) for grid in self.solution_grids ] challenge_grid_container = Box( self._get_grid_container(self.challenge_grid)) return FloatContainer( Box( Frame( HSplit( [ challenge_grid_container, VSplit( solution_containers, padding=2, ), ], padding=1, ), ), ), floats=[], )
def __init__(self) -> None: self.cmder_input = TextArea( height=1, multiline=False, wrap_lines=False, style="class:normal" ) self.input = self.cmder_input self.status_bar = Label("Loading status bar...", style="class:status") self.console = Frame( TextArea(plover_text, focusable=False), title="Console", style="class:normal", ) self.tape = Tape() self.suggestions = Suggestions() self.outputs = [self.console] self.container = HSplit( [ DynamicContainer(lambda: VSplit(self.outputs)), DynamicContainer(lambda: self.input), self.status_bar, ] )
def main(): # Create a big layout of many text areas, then wrap them in a `ScrollablePane`. root_container = VSplit([ Label("<left column>"), HSplit([ Label("ScrollContainer Demo"), Frame( ScrollablePane( HSplit([ Frame( TextArea( text=f"label-{i}", completer=animal_completer, )) for i in range(20) ])), ), ]), ]) root_container = FloatContainer( root_container, floats=[ Float( xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1), ), ], ) layout = Layout(container=root_container) # Key bindings. kb = KeyBindings() @kb.add("c-c") def exit(event) -> None: get_app().exit() kb.add("tab")(focus_next) kb.add("s-tab")(focus_previous) # Create and run application. application = Application(layout=layout, key_bindings=kb, full_screen=True, mouse_support=True) application.run()
def __init__(self, playback, save_location=None, *args, **kwargs): self.mainViewCondition = partial(self.mainView, self) self.mainViewCondition = Condition(self.mainViewCondition) self.disabled_bindings = False bindings = KeyBindings() self.init_bindings(bindings) super().__init__(full_screen=True, key_bindings=bindings, mouse_support=True, *args, **kwargs) self.displayingHelpScreen = ( False) # used to toggle between help screen on normal if save_location: self.save_location = save_location else: self.save_location = SAVE_LOCATION self.playback = playback self._savedLayout = Layout(Window()) self.command_cache = deque([], maxlen=5) ########################################## ### Setting up views ########################################## self.old_command_window = FormattedTextControl(text="Output goes here", focusable=True) self.new_command_window = FormattedTextControl(text="Output goes here", focusable=True) self.body = Frame( HSplit([ Frame(Window(self.old_command_window)), Frame(Window(self.new_command_window)), ])) self.toolbar = Window( FormattedTextControl(text=self.toolbar_text), height=Dimension(max=1, weight=10000), dont_extend_height=True, ) self.main_view = HSplit([self.body, self.toolbar], padding_char="-") self.layout = Layout(self.main_view)
def _create_popup_window(title, body): """ Return the layout for a pop-up window. It consists of a title bar showing the `title` text, and a body layout. The window is surrounded by borders. """ assert isinstance(title, six.text_type) assert isinstance(body, Container) return Frame(body=body, title=title)
def create_app(listen_handler, home): # components logo = Label(text=LOGO) text_area = TextArea(text=str(home), read_only=True, scrollbar=True) listen_btn = Button('Listen', handler=listen_handler(text_area=text_area)) help_btn = Button('Help', handler=help_handler) exit_btn = Button('Exit', handler=lambda: get_app().exit()) buttons = HSplit(children=[ Label(text=' MENU'), Frame(listen_btn), Frame(help_btn), Frame(exit_btn) ], style='bg:#00aa00 #000000') # root container root_container = FloatContainer(HSplit([ Box(body=VSplit([buttons, logo], padding=12), padding=0, style='bg:#888800 #000000'), text_area, ]), floats=[]) # key bindings bindings = KeyBindings() bindings.add('tab')(focus_next) bindings.add('s-tab')(focus_previous) @bindings.add('c-c') @bindings.add('q') def _(event): event.app.exit() # application application = Application(layout=Layout(root_container, focused_element=listen_btn), key_bindings=bindings, enable_page_navigation_bindings=True, mouse_support=True, full_screen=True) return application
def get_questions_widgets(self): question_widgets = [ Frame(body=Label(text=unicode(self.header))), ] question_widgets += self.questions.get_widgets_list() create_button = Button(u"Create", handler=self.accept_create) exit_button = Button(u"Exit", handler=self.accept_exit) question_widgets.append(Box(VSplit([create_button, exit_button]))) return question_widgets
def _get_grid_container(pattern_grid: PatternGrid): """Get a container for a given pattern grid.""" return Frame( Box( Label( text=pattern_grid.format_grid, dont_extend_width=True, ), padding_left=1, padding_right=1, ), )
def creationLayoutFactory(self): root_container = Box( Frame( TextArea( text="CREATION layout placeholder", width=40, height=10, )), ) return Layout(container=root_container)
def editingLayoutFactory(self): #TODO root_container = Box( Frame( TextArea( text="EDITING layout placeholder", width=40, height=10, )), ) return Layout(container=root_container)
def removingLayoutFactory(self): #TODO root_container = Box( Frame( TextArea( text="DELETE layout placeholder", width=40, height=10, )), ) return Layout(container=root_container)
def test_print_container(tmpdir): # Call `print_container`, render to a dummy file. f = tmpdir.join("output") with open(f, "w") as fd: print_container(Frame(TextArea(text="Hello world!\n"), title="Title"), file=fd) # Verify rendered output. with open(f, "r") as fd: text = fd.read() assert "Hello world" in text assert "Title" in text
def set_as_code(self): prev_cell_type = self.json["cell_type"] if prev_cell_type != "code": self.notebook.dirty = True self.json["cell_type"] = "code" self.json["outputs"] = [] self.json["execution_count"] = None text = rich_print("\nIn [ ]:", style="green") self.input_prefix.content = FormattedTextControl(text=ANSI(text)) self.set_input_readonly() self.input = Frame(self.input_window) self.notebook.focus(self.notebook.current_cell_idx, update_layout=True)
def layout(self): return Layout( FloatContainer(content=VSplit([ HSplit([ WindowManager.header(), ] + self._get_layout_folders()), VerticalLine(), HSplit([ WindowManager.player(self.playing), Frame(body=self.stations.radio_list, title=self.stations_folder) ]) ]), floats=[self.dialog] if self.dialog else []))
def help_modal(title, text): help_container = Float( Frame( HSplit([ Window(FormattedTextControl(title), height=1, style="reverse"), Window(height=1), Window(FormattedTextControl(text)), Window( FormattedTextControl("[?] Close this window"), height=1, style="reverse", ), ]))) return help_container
def get_column_details_container(column_names, column_details): # column names labels column_name_labels = {column_name: Label(text=column_name) for column_name in column_names} # column details labels # column_details_labels = { 'col_name': {attr_key: Label(), ...} } column_details_labels = { column_name: { attr_key: Label(text=f"{attr_key:20s}: {attr_val}") for attr_key, attr_val in column_details[column_name].items() } for column_name in column_names } # container for representing column details properly column_details_container = HSplit( children=[ VSplit( children=[ # On the left side, we have just the column name and its label. Frame(column_name_labels[column_name]), # On the right handed side we have attr_key: attr_val label for every column Frame( HSplit( children=[ attr_val for attr_key, attr_val in column_details_labels[column_name].items() ] ) ), ] ) for column_name in column_details_labels.keys() ], ) return column_name_labels, column_details_labels, column_details_container