mirror of
https://github.com/kristoferssolo/LU-bookstore.git
synced 2025-10-21 18:00:34 +00:00
refactor(tui): refactor create_books_table
This commit is contained in:
parent
8b8cdd00d0
commit
a78734252c
@ -3,26 +3,18 @@ from bookstore.book import Book
|
||||
from bookstore.inventory import Inventory
|
||||
|
||||
from .handlers import exit_on_q
|
||||
|
||||
from .widgets.table import Table
|
||||
|
||||
|
||||
FOCUS_STYLE = urwid.AttrMap("default", "dark red", "standout")
|
||||
UNFOCUS_STYLE = urwid.AttrMap("default", "default", "standout")
|
||||
def create_row(cells) -> urwid.Columns:
|
||||
return urwid.Columns([urwid.Text(str(cell)) for cell in cells])
|
||||
|
||||
|
||||
def create_books_table(books: list[Book]) -> Table:
|
||||
header = urwid.Columns([urwid.Text(header) for header in Book.fields()])
|
||||
header = urwid.AttrMap(header, "header", focus_map=FOCUS_STYLE)
|
||||
|
||||
rows = [header]
|
||||
|
||||
for book in books:
|
||||
row = urwid.Columns([urwid.Text(str(value)) for value in book.field_values()])
|
||||
rows.append(urwid.AttrMap(row, "body", focus_map=FOCUS_STYLE))
|
||||
|
||||
walker = urwid.SimpleListWalker(rows)
|
||||
books_table = Table(walker)
|
||||
return books_table
|
||||
header = create_row(Book.fields())
|
||||
rows = [create_row(book.field_values()) for book in books]
|
||||
return Table(urwid.SimpleListWalker([header] + rows))
|
||||
|
||||
|
||||
def render(inventory: Inventory):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user