def generate_layout(self) -> Layout: """ Generate layout on refresh :return: Piloton Layout """ # Split layout layout = Layout() layout.split( Layout(name="upper", size=5), Layout(name="hz", size=5), Layout(name="pz", size=5), ) # Add upper panels layout["upper"].split( Layout(self._generate_cadence_panel(), name="cadence"), Layout(self._generate_resistance_panel(), name="resistance"), Layout(self._generate_power_panel(), name="power"), direction="horizontal", ) # Add lower panels layout["hz"].split( Layout(self._generate_heart_rate_panel(), name="heart_rate"), direction="horizontal", ) layout["pz"].split( Layout(self._generate_power_zone_panel(), name="power_zone"), direction="horizontal", ) return layout
class TerminalUI: def __init__(self, probe, target, tree): """ UI for terminal info panels showing probe parameters, regions touched by probe etc. Built as a Live dispay of Layout's showing rich renderables (classes above). """ self.layout = Layout() self.layout.split( Layout(name="left", ratio=2), Layout(tree, name="right", ratio=4), direction="horizontal", ) self.layout["left"].split( Layout(target, name="ltop"), Layout( Panel( probe, title="Probe", border_style=salmon_light, title_align="left", ), name="lbottom", ratio=3, ), ) def __rich_console__(self, console, measure): yield self.layout
def make_layout() -> Layout: """Define the layout.""" layout = Layout(name="root") layout.split( Layout(name="header", size=3), Layout(name="brightvol", size=3), Layout(name="status", size=4), Layout(name="filesys", size=4), Layout(name="bluetooth", size=4), Layout(name="lights", size=11), Layout(name="motors", size=5), Layout(name="motor_rate", size=5), Layout(name="audio", size=7), ) layout["brightvol"].split_row( Layout(name="bright"), Layout(name="vol", ratio=1), ) layout["status"].split_row( Layout(name="status1"), Layout(name="status2"), ) layout["audio"].split_row( Layout(name="audio_ch"), Layout(name="audio_state"), ) layout["audio_state"].split_column( Layout(name="audio_peak"), Layout(name="audio_idx"), ) return layout
def update_postseason(title: str, data: Games) -> None: layout["header"].update(Panel(Text(title, justify="center"))) for subleague, games in data.items(): tables = [] for game in games.values(): table = Table.grid(expand=True) table.add_column("Seed", width=1) table.add_column("Name") table.add_column("Championships", style="#FFEB57", width=4) table.add_column("Wins", width=1) for row in game: table.add_row( row.seed, Text(row.name, style=row.color), "●" * row.championships if row.championships < 4 else f"●x{row.championships}", row.wins, ) tables.append(Layout(table)) all_tables = Layout() all_tables.split(*tables) layout[subleague].update(Panel( all_tables, title=subleague, padding=0 ))
class MainMenuLayout: """ Return the main menu layout """ def __init__(self) -> None: self.layout = Layout() self.table = Table(title="LDMA PARSER ACTIONS", expand=True) def __rich__(self) -> Layout: self.layout.split( Layout(name="head", size=3), Layout(name="body"), ) self.layout["body"].split_column( Layout(name='should_be_unused', visible=False), Layout(name='table2'), Layout(name='action_table'), ) self.table.add_column("Action Button", justify="center", style="cyan", no_wrap=True) self.table.add_column("Actions", style="magenta", justify="center") self.table.add_row("1", "TO SEARCH WITH LINK CODE") self.table.add_row("2", "TO SEARCH WITH SITE ID") self.table.add_row("0", "BACK TO MAIN MENU") self.layout["head"].update(Header("LDMA-PARSER")) self.layout["action_table"].update(self.table) self.layout["table2"].update(make_sponsor_message()) return self.layout
def update_postseason(data: Brackets) -> None: for bracket, leagues in data.items(): if bracket == "overbracket": layout["header"].update( Text(f"{leagues['name']} {leagues['round']}", justify="center")) else: layout["footer"].update( Text(f"{leagues['name']} {leagues['round']}", justify="center")) for subleague, games in leagues["games"].items(): tables = [] for game in games.values(): table = Table.grid(expand=True) table.add_column("Seed", width=1) table.add_column("Name") table.add_column("Championships", width=2) table.add_column("Wins", width=1) for row in game: table.add_row( str(row.seed), f"[{row.color}]{row.name}[/]", clip_championships(row), str(row.wins), ) tables.append(Layout(table)) all_tables = Layout() all_tables.split(*tables) layout[bracket][subleague].update( Panel(all_tables, title=subleague, padding=0))
def RichLayout(self) -> Layout: layout = Layout() layout.split( # Layout(name="upper"), Layout(" ", name="BufferTop"), Layout(Panel(self.calendarView.RichGrid(), title="Calendar", style='grey50'), name="Calendar"), Layout(Panel(self.taskView.RichGrid(), title="Tasks", style='grey50'), name="Tasks"), # Layout(Panel(str(datetime.now()), title="Console"), name="Console") Layout(self.inputManager.RichGrid(), name='Console') # Layout(" ", name="BufferBot") # Layout(datetime.datetime.now().strftime('%H:%M:%S') + ' ' + self.input, name='Console') ) # layout["upper"].split( # Layout(Panel(self.calendarView.RichGrid(), title="Calendar"), name="Calendar"), # # Layout(Panel(self.overview.RichGrid(), title="Overview"), name="Overview"), # direction="horizontal" # ) # layout['Calendar'].ratio = 2.5 # layout['Overview'].ratio = layout["BufferTop"].size = 1 layout["Tasks"].ratio = 1.5 # layout["BufferBot"].size = 1 layout['Console'].size = 1 return layout
def test_add_split(): layout = Layout() layout.split(Layout(), Layout()) assert len(layout.children) == 2 layout.add_split(Layout(name="foo")) assert len(layout.children) == 3 assert layout.children[2].name == "foo"
def test_unsplit(): layout = Layout() layout.split(Layout(), Layout()) assert len(layout.children) == 2 layout.unsplit() assert len(layout.children) == 0
def test_render(): layout = Layout(name="root") repr(layout) layout.split(Layout(name="top"), Layout(name="bottom")) top = layout["top"] top.update(Panel("foo")) print(type(top._renderable)) assert isinstance(top.renderable, Panel) layout["bottom"].split(Layout(name="left"), Layout(name="right"), direction="horizontal") assert layout["root"].name == "root" assert layout["left"].name == "left" with pytest.raises(KeyError): top["asdasd"] layout["left"].update("foobar") print(layout["left"].children) console = Console(width=60, color_system=None) with console.capture() as capture: console.print(layout, height=10) result = capture.get() expected = "╭──────────────────────────────────────────────────────────╮\n│ foo │\n│ │\n│ │\n╰──────────────────────────────────────────────────────────╯\nfoobar ╭───── 'right' (30 x 5) ─────╮\n │ { │\n │ 'size': None, │\n │ 'minimum_size': 1, │\n ╰────────────────────────────╯\n" assert result == expected
def make_layout(): """Define the layout.""" layout = Layout(name="root") layout.split(Layout(name="header", size=4), Layout(name="main")) layout["main"].split_column(Layout(name="info", size=4), Layout(name="body", ratio=2, minimum_size=60)) layout["info"].split_row(Layout(name="time"), Layout(name="files")) return layout
def layout() -> Layout: layout = Layout(name="root") layout.split( Layout(name="header", size=3), Layout(name="body"), ) return layout
def setup_console(): layout = Layout(name="Autoworkflow") layout.split(Layout(name="main", ratio=1), ) layout["main"].split( Layout(name="side"), Layout(name="body", ratio=2, minimum_size=60), direction="horizontal", ) return layout
def get_layout() -> Layout: layout = Layout() layout.split( Layout(name="header", size=3) # Layout(name="body", size=2), ) layout["header"].update(Header("Create NCR")) return layout
def make_exit_layout() -> Layout: """Define the layout.""" layout = Layout(name="root") message = make_message() layout.split(Layout(name="body", )) layout["body"].update(message) return layout
def make_report(self): layout = Layout(direction="horizontal", height=20) layout.split( Layout(SceneContent(self.scene), name="scene", ratio=1), Layout( Empty(), ratio=0.2, ), Layout(self, name="summary", ratio=2), ) print(layout)
def test_tree(): layout = Layout(name="root") layout.split(Layout("foo", size=2), Layout("bar")) console = Console(width=60, color_system=None) with console.capture() as capture: console.print(layout.tree, height=10) result = capture.get() print(repr(result)) expected = "⬇ 'root' (ratio=1) \n├── ■ (size=2) \n└── ■ (ratio=1) \n" assert result == expected
def _prep_layout(self): layout = Layout() right_body = Layout(name="right_body", ratio=1) layout.split( Layout(name="left_body", ratio=2), right_body, splitter="row", ) right_body.split(Layout(name="up_footer", ratio=2), Layout(name="bottom_footer", ratio=1)) return layout
def test_tree(): layout = Layout(name="root") layout.split(Layout("foo", size=2), Layout("bar", name="bar")) layout["bar"].split_row(Layout(), Layout()) console = Console(width=60, color_system=None) with console.capture() as capture: console.print(layout.tree, height=10) result = capture.get() print(repr(result)) expected = "⬍ Layout(name='root') \n├── ⬍ Layout(size=2) \n└── ⬌ Layout(name='bar') \n ├── ⬍ Layout() \n └── ⬍ Layout() \n" print(result, "\n", expected) assert result == expected
def display_options(options, selected): grids = [] for i, opt in enumerate(options): text = Text(f'{i + 1}. {opt}') if selected[opt]: text.stylize('yellow') grids.append(Layout(text)) layout = Layout(name='options') layout.split(*grids, direction='horizontal') return layout
def make_layout(portfolio): layout = Layout(name="Tinkoff") layout.split( Layout(name="header", size=3), Layout(name="main"), ) layout['main'].split( Layout(name='table', ratio=5), Layout(name='currencies', ratio=1.5), direction="horizontal", ) layout['header'].update(Header()) layout['table'].update(Align.center(PortfolioTable(portfolio), )) layout['currencies'].update(CurrenciesTable()) return layout
def make_layout() -> Layout: """Define the layout.""" layout = Layout(name="root") layout.split( Layout(name="header", size=3), Layout(name="main", ratio=1), Layout(name="footer", size=7), ) layout["main"].split_row( Layout(name="side"), Layout(name="body", ratio=2, minimum_size=60), ) layout["side"].split(Layout(name="box1"), Layout(name="box2")) return layout
def make_layout() -> Layout: """Define the layout.""" layout = Layout(name="root") layout.split( Layout(name="header", ratio=1), Layout(name="main", ratio=15), Layout(name="footer", ratio=4), ) layout["main"].split_row( Layout(name="body", ratio=10), Layout(name="side", ratio=15) ) layout["side"].split(Layout(name="box1", minimum_size=15, ratio=10), Layout(name="box2", ratio=10), Layout(name="box3", ratio=15)) return layout
def generate_layout(self) -> Layout: """ Generate layout on refresh :return: Piloton training layout """ # Split layout layout = Layout() layout.split(Layout(name="main", size=15)) # Add main panel layout["main"].split( Layout(self._generate_training_panel(), name="training"), ) return layout
def make_layout() -> Layout: """Define the layout.""" layout = Layout(name="root") layout.split( Layout(name="header", size=3), Layout(name="main", ratio=1), Layout(name="footer", size=5), ) layout["main"].split( Layout(name="side"), Layout(name="body", ratio=2, minimum_size=40), direction="horizontal", ) # layout["side"].split(Layout(name="box1"), Layout(name="box2")) return layout
def printui(): print() health = ''.join(' ' for i in range(10)) stamina = "100" player_name = "Corengenie" player_floor = 14 # console.print(f''' # [bold green]Здоровье: [/bold green][white on green]{health}[/white on green] # __ffhkfghkfghjffgggggggggggggggggggggh__ # [bold cyan]Will[/bold cyan] # ''', justify="center") layout = Layout() layout.split( Layout(name="upper"), Layout(name="lower") ) layout["upper"].split( Layout(name="tabs"), Layout(name="stats"), Layout(name="maplevel"), direction="horizontal" ) layout["upper"]["tabs"].size = 3 layout["upper"]["stats"].size = 27 layout["upper"]["maplevel"].size = 70 layout["upper"]["tabs"].update("") layout["upper"]["stats"].update(f''' Персонаж: {player_name} Этаж: {player_floor} [bold green]Здоровье: [/bold green][white on green]{health}[/white on green] [bold gold1]Выносливость: {stamina}[bold gold1] Очки защиты: 10 Очки уворота: 2 ''') print(layout)
def make_layout() -> Layout: """ Setup the GUI layout. :return The GUI layout. """ layout = Layout(name="root") layout.split( Layout(name="header", size=4), Layout(name="main", ratio=1), Layout(name="footer", size=4), ) layout["main"].split( Layout(name="carts", ratio=1), Layout(name="content", ratio=2, minimum_size=60), direction="horizontal", ) return layout
def make_layout(apps) -> Layout: """Define the layout.""" layout = Layout(name="root") layout.split( Layout(name="header", size=3), Layout(name="main", ratio=1), Layout(name="footer", size=7), ) layout["main"].split( Layout(name="side"), Layout(name="body", ratio=2, minimum_size=60), direction="horizontal", ) app_layouts = [Layout(name=app) for app in apps] layout["body"].split(*app_layouts, direction="horizontal") layout["side"].split(Layout(name="box1"), Layout(name="box2")) return layout
def get_grid(self): layout = Layout() upper = Layout() upper.split(Layout(display_corpus( self.token_pos, self.display_state.token, self.display_state.current_corpus(), selected=self.display_state.get_selected_pos(), highlight_token=self.display_state.highlight_token), name='panel', ratio=4), Layout(Panel(self.display_state.instruction, title='Controls', expand=False), name='instruction', ratio=1), direction='horizontal') lower = Layout() lower.split(Layout(display_options(self.options, self.selected), ratio=4), Layout(Panel(self.msg, title='Command', height=5), name='cmd', ratio=1), direction='horizontal') layout.split(upper, lower) return layout
class MenuLayout: def __init__(self): self._layout = Layout() self._table = Table(title="AUTOBOT MENU", expand=True, show_lines=True, box=box.SQUARE_DOUBLE_HEAD, title_style="#0000ff italic") def __rich__(self): self._layout.split( Layout(name="head", size=3), Layout(name="body", ratio=1), ) self._layout["body"].split_column(Layout(name="mid_section", ratio=2), Layout(name="table", ratio=3)) # Tables self._table.add_column("Action Button", justify="center", header_style="#3be13b", no_wrap=True, style="#3be13b") self._table.add_column("Action Description", justify="center", header_style="bold cyan", no_wrap=True, style="cyan") self._table.add_row("1", "CREATE NCR 🧩") self._table.add_row("2", "CLOSE NCR 🎯") self._table.add_row("3", "CANCEL NCR 🧨") self._table.add_row("4", "LDMA PARSER 📆") self._table.add_row("0", "EXIT AUTOBOT ⚔") self._layout["head"].update(Header("WELCOME TO AUTOBOT")) self._layout["mid_section"].update(make_sponsor_message()) self._layout["table"].update(self._table) return self._layout