diff --git a/bin/ffx/show_details_screen.py b/bin/ffx/show_details_screen.py index b6cbd07..05694f2 100644 --- a/bin/ffx/show_details_screen.py +++ b/bin/ffx/show_details_screen.py @@ -56,13 +56,11 @@ class ShowDetailsScreen(Screen): self.show_obj = show - def action_submit(self): - quit() - def on_mount(self): if self.show_obj: - self.query_one("#id_input", Input).value = self.show_obj['id'] + + self.query_one("#id_wdg", Static).update(str(self.show_obj['id'])) self.query_one("#name_input", Input).value = self.show_obj['name'] self.query_one("#year_input", Input).value = self.show_obj['year'] @@ -74,7 +72,12 @@ class ShowDetailsScreen(Screen): yield Static("New Show" if self.show_obj else "Show", id="toplabel") yield Static("ID") - yield Input(type="text", id="id_input") + + if self.show_obj: + yield Static("", id="id_wdg") + else: + yield Input(type="text", id="id_wdg") + yield Static("Name") yield Input(type="text", id="name_input") yield Static("Year") @@ -89,13 +92,16 @@ class ShowDetailsScreen(Screen): yield Button("Save", id="save_button") yield Button("Cancel", id="cancel_button") - yield Static("", id="output_static") - yield Footer() def getValues(self): - showId = int(self.query_one("#id_input", Input).value) + + if self.show_obj: + showId = int(self.show_obj['id']) + else: + showId = int(self.query_one("#id_wdg", Input).value) + showName = self.query_one("#name_input", Input).value showYear = self.query_one("#year_input", Input).value return showId, showName, showYear @@ -107,9 +113,8 @@ class ShowDetailsScreen(Screen): if event.button.id == "save_button": showId, showName, showYear = self.getValues() - self.query_one("#output_static", Static).update(f"{showId} - {showName} ({showYear})") - if self.addShow(showId, showName, showYear): + if self.updateShow(showId, showName, showYear): screenResult = {} screenResult['id'] = showId @@ -124,7 +129,7 @@ class ShowDetailsScreen(Screen): if event.button.id == "cancel_button": self.app.pop_screen() - def addShow(self, show_id, show_name, show_year): + def updateShow(self, show_id, show_name, show_year): try: s = self.Session() @@ -138,10 +143,22 @@ class ShowDetailsScreen(Screen): s.commit() return True else: - return False - + + currentShow = q.first() + + changed = False + if currentShow.name != show_name: + currentShow.name = show_name + changed = True + if currentShow.year != show_year: + currentShow.year = show_year + changed = True + if changed: + s.commit() + return changed + except Exception as ex: - click.ClickException(f"ShowDetailsScreen.addShow(): {repr(ex)}") + click.ClickException(f"ShowDetailsScreen.updateShow(): {repr(ex)}") finally: s.close() diff --git a/bin/ffx/shows_screen.py b/bin/ffx/shows_screen.py index 3c3a110..3bb826f 100644 --- a/bin/ffx/shows_screen.py +++ b/bin/ffx/shows_screen.py @@ -64,8 +64,6 @@ class ShowsScreen(Screen): if row_key is not None: selected_row_data = self.table.get_row(row_key) - #)[selected_row_index] - selectedShow = {} selectedShow['id'] = selected_row_data[0] selectedShow['name'] = selected_row_data[1] @@ -75,9 +73,10 @@ class ShowsScreen(Screen): def handle_edit_screen(self, screenResult): - show = (screenResult['id'], screenResult['name'], screenResult['year']) - self.table.add_row(*map(str, show)) + row_key, col_key = self.table.coordinate_to_cell_key(self.table.cursor_coordinate) + self.table.update_cell(row_key, self.column_key_name, screenResult['name']) + self.table.update_cell(row_key, self.column_key_year, screenResult['year']) def __init__(self): @@ -114,9 +113,9 @@ class ShowsScreen(Screen): self.table = DataTable() # Define the columns with headers - self.table.add_column("ID", width=10) - self.table.add_column("Name", width=50) - self.table.add_column("Year", width=10) + self.column_key_id = self.table.add_column("ID", width=10) + self.column_key_name = self.table.add_column("Name", width=50) + self.column_key_year = self.table.add_column("Year", width=10) self.table.cursor_type = 'row'