Skip to content

Commit

Permalink
Fetch cell values via row select
Browse files Browse the repository at this point in the history
- Add cols with key to fix missing col labels issue.
- Also add an alternative version for rows populating when passed as
  sqlite3 Rows instances.
- Keep debugging RichLog panel intact, but maybe make it foldable in the
  future (3/3 horizontal tiling currently)
  • Loading branch information
JOJ0 committed Nov 9, 2024
1 parent b842c81 commit 4c49b36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
18 changes: 9 additions & 9 deletions discodos/ctrl/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,15 +935,15 @@ def tui_ls_releases(self, search_terms):

app = DiscodosListApp(
rows=search_results,
headers=[
"ID",
"Cat. #",
"Artist",
"Title",
"Is in C.",
"For Sale",
"Status"
],
headers={
"release_id": "ID",
"catno": "Cat. #",
"artist": "Artist",
"title:": "Title",
"isinc": "Is in C.",
"forsale": "For Sale",
"status": "Status"
},
discogs=self.d
)
app.run(inline=False)
Expand Down
49 changes: 32 additions & 17 deletions discodos/ctrl/tui.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging
from sqlite3 import Row
from rich.table import Table as rich_table
from textual.app import App
from textual.containers import Horizontal, Vertical, VerticalScroll
from textual.widgets import DataTable, Digits, Footer, Label, Static
from textual.widgets import DataTable, Digits, Footer, Label, Static, RichLog

from discodos.model import DiscogsMixin

log = logging.getLogger('discodos')


class DiscodosListApp(App, DiscogsMixin):
class DiscodosListApp(App, DiscogsMixin): # pylint: disable=too-many-instance-attributes
"""Inline Textual app to view and edit dsc ls results."""
CSS_PATH = "tui_ls.tcss"
BINDINGS = [
Expand Down Expand Up @@ -59,9 +60,12 @@ def action_edit_sale(self):

def _load_ls_results(self):
table_widget = self.query_one(DataTable)
for row_id, row in enumerate(self.rows):
#row_id = row['discogs_id']
table_widget.add_row(*row.values(), key=row_id)
if isinstance(self.rows[0], Row):
for row in self.rows:
table_widget.add_row(*row)
else:
for row_id, row in enumerate(self.rows):
table_widget.add_row(*row.values(), key=row_id)

def on_mount(self):
self.title = "DiscoDOS ls results"
Expand All @@ -88,22 +92,30 @@ def _two_column_rich_table(self, listing_details):
table.add_row(f"[bold]{key.capitalize()}[/bold]", str(value))
return table

def on_data_table_cell_selected(self, event):
log.debug(event.coordinate)
if event.coordinate.column == 5 and event.value is not None:
listing = self.get_sales_listing_details(event.value)
self.left_column_content.update(self._two_column_rich_table(listing))
self.sales_price.update(listing['price'])
if event.coordinate.column == 0 and event.value is not None:
stats = self.get_marketplace_stats(event.value)
self.middle_column_content.update(self._two_column_rich_table(stats))
def on_data_table_row_selected(self, event):
rlog = self.query_one(RichLog)
row_key = event.row_key
# Listing
listing_id = self.table.get_cell(row_key, "forsale")
rlog.write("Fetching Discogs Marketplace listing.")
listing = self.get_sales_listing_details(listing_id)
rlog.write("Done.")
self.left_column_content.update(self._two_column_rich_table(listing))
self.sales_price.update(listing['price'])
# Stats
release_id = self.table.get_cell(row_key, "release_id")
rlog.write("Fetching Discogs Marketplace stats.")
stats = self.get_marketplace_stats(release_id)
rlog.write("Done.")
self.middle_column_content.update(self._two_column_rich_table(stats))

def compose(self):
# The main data widget
self.table = DataTable()
self.table.focus()
self.table.add_columns(*self.headers)
self.table.cursor_type = "cell"
for key, label in self.headers.items():
self.table.add_column(label=label, key=key)
self.table.cursor_type = "row"
self.table.zebra_stripes = True
# Headline widgets
self.left_column_headline = Label("[b]Listing Details[/b]")
Expand All @@ -130,4 +142,7 @@ def compose(self):
with VerticalScroll(id="lower-right-column"):
yield self.right_column_headline
yield self.right_column_content
yield Footer()
with Horizontal(id="log-area"):
with VerticalScroll():
yield RichLog()
yield Footer()

0 comments on commit 4c49b36

Please sign in to comment.