From 3a405e896c956a2ac094ae87fa3829376a46742e Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Wed, 6 Nov 2024 17:57:13 +0100 Subject: [PATCH] Big fat sales price display --- discodos/model_collection.py | 20 +++++------ discodos/view/collection.py | 64 +++++++++++++++++++----------------- discodos/view/tui_ls.tcss | 14 +++++++- 3 files changed, 57 insertions(+), 41 deletions(-) diff --git a/discodos/model_collection.py b/discodos/model_collection.py index b3dab48..8dd6f6a 100644 --- a/discodos/model_collection.py +++ b/discodos/model_collection.py @@ -162,16 +162,16 @@ def stats_releases_d_collection_online(self): def get_sales_listing_details(self, listing_id): listing = self.d.listing(listing_id) - l = [ - listing.condition, - listing.external_id, - str(listing.format_quantity), - str(listing.allow_offers), - listing.location, - str(listing.price.value), - datetime.strftime(listing.posted, "%Y-%m-%d"), - ] - return ", ".join(l) + l = { + "condition": listing.condition, + "external_id": listing.external_id, + "format_quantity": str(listing.format_quantity), + "allow_offers": "yes" if listing.allow_offers else "no", + "location": listing.location, + "price": str(listing.price.value), + "posted": datetime.strftime(listing.posted, "%Y-%m-%d"), + } + return l def rate_limit_slow_downer(self, remaining=10, sleep=2): '''Discogs util: stay in 60/min rate limit''' diff --git a/discodos/view/collection.py b/discodos/view/collection.py index 264e99c..f4ba086 100644 --- a/discodos/view/collection.py +++ b/discodos/view/collection.py @@ -2,7 +2,7 @@ import asyncio from tabulate import tabulate as tab from textual.app import App -from textual.widgets import DataTable, Label, Footer +from textual.widgets import DataTable, Label, Footer, Digits from textual.containers import Container, Grid, Horizontal, Vertical, HorizontalScroll, VerticalScroll, ScrollableContainer # from textual.css import StyleSheet @@ -58,27 +58,7 @@ def __init__(self, rows, headers, discogs=None): self.left_column_label = None self.middle_column_label = None self.right_column_label = None - - def compose(self): - table = DataTable(classes="ls_results-list") - table.focus() - table.add_columns(*self.headers) - table.cursor_type = "cell" - table.zebra_stripes = True - # Layout - self.left_column_label = Label("Left column data") - self.middle_column_label = Label("Middle column") - self.right_column_label = Label("Right column") - self.details_panel = HorizontalScroll( - VerticalScroll(self.left_column_label), - VerticalScroll(self.middle_column_label), - VerticalScroll(self.right_column_label), - classes="details-panel", - ) - - yield table - yield self.details_panel - yield Footer() + self.sales_price = None def action_toggle_dark(self): self.dark = not self.dark @@ -98,6 +78,12 @@ def action_edit_release(self): def action_edit_sale(self): pass + def _load_ls_results(self): + table_widget = self.query_one(DataTable) + for row in self.rows: + row_id, *_ = row + table_widget.add_row(*row, key=row_id) + def on_mount(self): self.title = "DiscoDOS ls results" self.sub_title = "Use keystrokes to edit/sell/view details, ..." @@ -109,15 +95,33 @@ def on_data_table_cell_selected(self, event): return result = self.get_sales_listing_details(event.value) # Load data into the left column - self.left_column_label.update(result) - self.middle_column_label.update("Middle column updated!") # Example update - self.right_column_label.update("Right column updated!") # Example update + # self.left_column_label.update(result) + self.sales_price.update(result['price']) + # self.right_column_label.update("Right column updated!") # Example update - def _load_ls_results(self): - table_widget = self.query_one(DataTable) - for row in self.rows: - row_id, *_ = row - table_widget.add_row(*row, key=row_id) + def compose(self): + table = DataTable(classes="ls_results-list") + table.focus() + table.add_columns(*self.headers) + table.cursor_type = "cell" + table.zebra_stripes = True + # Layout + self.left_column_label = Label("") + self.middle_column_label = Label("[b]Price[/b]") + self.right_column_label = Label("") + self.sales_price = Digits("0", id="pi") + self.details_panel = HorizontalScroll( + VerticalScroll(self.left_column_label), + VerticalScroll( + self.middle_column_label, self.sales_price, classes="centered" + ), + VerticalScroll(self.right_column_label), + classes="details-panel", + ) + + yield table + yield self.details_panel + yield Footer() class CollectionViewCommandline( diff --git a/discodos/view/tui_ls.tcss b/discodos/view/tui_ls.tcss index 115e529..cafaec5 100644 --- a/discodos/view/tui_ls.tcss +++ b/discodos/view/tui_ls.tcss @@ -5,6 +5,18 @@ } .details-panel > VerticalScroll { + height: 1fr; + width: 1fr; border: solid grey; padding: 0; -} \ No newline at end of file +} + +#pi { + border: double orange; + width: auto; +} + +.centered { + width: auto; + align: center top; +}