You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm implementing an interactive rich table, and wondering about the best way to do it.
I'm currently doing something like:
from rich import box
from rich.align import Align
from rich.console import RenderableType
from rich.panel import Panel
from rich.table import Table
import rich.repr
from textual.widget import Reactive, Widget
def public(opt): return not opt.startswith('_')
@rich.repr.auto(angular=False)
class ChoiceTableWidget(Widget, can_focus=True):
selected: Reactive[int] = Reactive(0)
def __rich_repr__(self) -> rich.repr.RichReprResult:
yield Align.center(self.table, vertical="middle")
def __init__(self, *args, title="Menu", choices=[], **kwargs):
self.title = title
self.table = Table()
self.choices = choices
self.length = len(choices)
self.table.box = box.SIMPLE
for key in filter(public, choices[0]):
self.table.add_column(key)
for item in choices:
self.table.add_row(*[str(b) for a, b in item.items() if public(a)])
for row in self.table.rows:
row.style = 'dim'
self.table.rows[self.selected].style = 'bold'
super().__init__(*args, **kwargs)
def render(self) -> RenderableType:
return Panel(self.table, title=self.title)
async def move(self, pos):
if self.length > self.selected + pos >= 0:
self.table.rows[self.selected].style = 'dim'
self.selected += pos
self.table.rows[self.selected].style = 'bold'
async def on_down(self):
await self.move(1)
async def on_up(self):
await self.move(-1)
async def on_enter(self, event):
return await self.choices[self.selected]['_callback'](self)
But I'm still wondering about the best way to bind keys only to a specific widget (whenver it has the focus), and how to navigate views, being able to replace a view with another, and do something like history.back()
The text was updated successfully, but these errors were encountered:
I realize that textual isn't ready yet, what I'm building is nothing serious. I'm a huge fan of rich, and textual has the same feeling. The work you've done up until now looks amazing!
About the views, I was wondering if it was going to be like that. I'm a pure backend developer kind of guy, so I'm a bit out of my element here, yet this feels like a modern web interface framework like vue or react.
I'm implementing an interactive rich table, and wondering about the best way to do it.
I'm currently doing something like:
But I'm still wondering about the best way to bind keys only to a specific widget (whenver it has the focus), and how to navigate views, being able to replace a view with another, and do something like history.back()
The text was updated successfully, but these errors were encountered: