You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.8 KiB

from textual.containers import Container, Vertical
from textual.app import ComposeResult, App
from textual.widgets import Static, Header, DataTable
from textual.widget import Widget
class FeedPane(Widget):
def __init__(self):
super().__init__()
self.id = "feed-pane"
def add(self, content):
table = self.query_one(DataTable)
table.add_rows([[item] for item in content])
def addColumn(self, title):
table = self.query_one(DataTable)
table.add_column(title, width=60)
def clear(self):
table = self.query_one(DataTable)
table.data = {}
table.rows = {}
table.row_count = 0
table._line_no = 0
table._y_offsets = []
table._new_rows = set()
table._clear_caches()
table._require_update_dimensions = True
table.check_idle()
def currentValue(self):
table = self.query_one(DataTable)
row_num = table.cursor_cell.row
column_num = table.cursor_cell.column
return table.data[row_num][column_num]
def focus(self):
table = self.query_one(DataTable)
table.focus()
def compose(self):
yield DataTable(id="feeds_table")
class FeedItem(Static):
def __init__(self, content, id):
super().__init__()
self.content = content
self.id = "feed-" + str(id)
if id == 0:
self.set_styles("color: blue;")
def on_mount(self):
self.update(self.content)
self.on_event
class GUI(App):
CSS_PATH = "app.css"
def __init__(self):
super().__init__()
def on_key(self, event):
if event.key == "j":
pane = self.query_one(DataTable)
pane.key_down(event)
elif event.key == "k":
pane = self.query_one(DataTable)
pane.key_up(event)
elif event.key == "a":
pane = self.query_one(FeedPane)
pane.add(["XXX"])
elif event.key == "r":
pane = self.query_one(FeedPane)
pane.clear()
elif event.key == "space":
pane = self.query_one(FeedPane)
pane.add([pane.currentValue()])
else:
pass
def compose(self) -> ComposeResult:
yield Header()
yield Container(
FeedPane(),
Vertical(
*[Static("Horizontally"),
Static("Positioned"),
Static("Children"),
Static("Here")],
id="right-pane",
),
id="app-grid",
)
def on_mount(self):
fp = self.query_one(FeedPane)
fp.addColumn("Feeds")
fp.add(["Feed#" + str(number) for number in range(15)])
# fp.add_rows([[FeedItem(f"Feed# {number}", number)] for number in range(15)])
fp.focus()
if __name__ == "__main__":
app = GUI()
app.run()