nightly
This commit is contained in:
@@ -8,11 +8,7 @@ from textual.containers import Grid, Horizontal
|
|||||||
|
|
||||||
from ffx.model.show import Show
|
from ffx.model.show import Show
|
||||||
|
|
||||||
# class IdInput(Input):
|
# Screen[dict[int, str, int]]
|
||||||
# def on_key(self, event: events.Key) -> None:
|
|
||||||
# if event == "enter":
|
|
||||||
# quit()
|
|
||||||
|
|
||||||
class ShowDetailsScreen(Screen):
|
class ShowDetailsScreen(Screen):
|
||||||
|
|
||||||
CSS = """
|
CSS = """
|
||||||
@@ -50,33 +46,33 @@ class ShowDetailsScreen(Screen):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#BINDINGS = [
|
def __init__(self, show = {}):
|
||||||
# #("q", "quit()", "Quit"),
|
|
||||||
# ("h", "switch_mode('help')", "Help")
|
|
||||||
#]
|
|
||||||
|
|
||||||
#def action_quit(self):
|
|
||||||
# quit()
|
|
||||||
|
|
||||||
def __init__(self, show_id = None):
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.context = self.app.getContext()
|
self.context = self.app.getContext()
|
||||||
|
|
||||||
self.Session = self.context['database_session'] # convenience
|
self.Session = self.context['database_session'] # convenience
|
||||||
|
|
||||||
self.show_id = show_id
|
self.show_obj = show
|
||||||
|
|
||||||
|
|
||||||
def action_submit(self):
|
def action_submit(self):
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
def on_mount(self):
|
||||||
|
|
||||||
|
if self.show_obj:
|
||||||
|
self.query_one("#id_input", Input).value = 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']
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
|
|
||||||
yield Header()
|
yield Header()
|
||||||
|
|
||||||
with Grid():
|
with Grid():
|
||||||
|
|
||||||
yield Static("New Show" if self.show_id is None else "Show", id="toplabel")
|
yield Static("New Show" if self.show_obj else "Show", id="toplabel")
|
||||||
yield Static("ID")
|
yield Static("ID")
|
||||||
yield Input(type="text", id="id_input")
|
yield Input(type="text", id="id_input")
|
||||||
yield Static("Name")
|
yield Static("Name")
|
||||||
@@ -105,33 +101,6 @@ class ShowDetailsScreen(Screen):
|
|||||||
return showId, showName, showYear
|
return showId, showName, showYear
|
||||||
|
|
||||||
|
|
||||||
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
||||||
|
|
||||||
showId, showName, showYear = self.getValues()
|
|
||||||
|
|
||||||
#self.query_one("#output_static", Static).update(f"{showId} - {showName} ({showYear})")
|
|
||||||
|
|
||||||
# if event.input.id == "id_input":
|
|
||||||
# # Retrieve the entered text
|
|
||||||
# name = event.value
|
|
||||||
# # Display the result in the output label
|
|
||||||
# self.query_one("#output_static", Static).update(f"Hello, {name}!")
|
|
||||||
# self.set_focus(self.query_one("#name_input", Input))
|
|
||||||
#
|
|
||||||
# if event.input.id == "name_input":
|
|
||||||
# # Retrieve the entered text
|
|
||||||
# name = event.value
|
|
||||||
# # Display the result in the output label
|
|
||||||
# self.query_one("#output_static", Static).update(f"Yo, {name}!")
|
|
||||||
# self.set_focus(self.query_one("#year_input", Input))
|
|
||||||
#
|
|
||||||
# if event.input.id == "year_input":
|
|
||||||
# # Retrieve the entered text
|
|
||||||
# name = event.value
|
|
||||||
# # Display the result in the output label
|
|
||||||
# self.query_one("#output_static", Static).update(f"Ya, {name}!")
|
|
||||||
# self.set_focus(None)
|
|
||||||
|
|
||||||
# Event handler for button press
|
# Event handler for button press
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
# Check if the button pressed is the one we are interested in
|
# Check if the button pressed is the one we are interested in
|
||||||
@@ -140,11 +109,17 @@ class ShowDetailsScreen(Screen):
|
|||||||
showId, showName, showYear = self.getValues()
|
showId, showName, showYear = self.getValues()
|
||||||
self.query_one("#output_static", Static).update(f"{showId} - {showName} ({showYear})")
|
self.query_one("#output_static", Static).update(f"{showId} - {showName} ({showYear})")
|
||||||
|
|
||||||
self.addShow(showId, showName, showYear)
|
if self.addShow(showId, showName, showYear):
|
||||||
#TODO: Validation
|
|
||||||
|
|
||||||
# self.app.pop_screen()
|
screenResult = {}
|
||||||
self.dismiss(showId)
|
screenResult['id'] = showId
|
||||||
|
screenResult['name'] = showName
|
||||||
|
screenResult['year'] = showYear
|
||||||
|
|
||||||
|
self.dismiss(screenResult)
|
||||||
|
else:
|
||||||
|
#TODO: Meldung
|
||||||
|
self.app.pop_screen()
|
||||||
|
|
||||||
if event.button.id == "cancel_button":
|
if event.button.id == "cancel_button":
|
||||||
self.app.pop_screen()
|
self.app.pop_screen()
|
||||||
@@ -153,12 +128,18 @@ class ShowDetailsScreen(Screen):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
s = self.Session()
|
s = self.Session()
|
||||||
show = Show(id = show_id,
|
q = s.query(Show).filter(Show.id == show_id)
|
||||||
name = show_name,
|
|
||||||
year = show_year)
|
if not q.count():
|
||||||
|
show = Show(id = show_id,
|
||||||
|
name = show_name,
|
||||||
|
year = show_year)
|
||||||
|
s.add(show)
|
||||||
|
s.commit()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
s.add(show)
|
|
||||||
s.commit()
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.ClickException(f"ShowDetailsScreen.addShow(): {repr(ex)}")
|
click.ClickException(f"ShowDetailsScreen.addShow(): {repr(ex)}")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -42,29 +42,41 @@ class ShowsScreen(Screen):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
#("q", "quit()", "Quit"),
|
("e", "edit_show", "Edit Show"),
|
||||||
("e", "switch_mode('show_details')", "Edit Show"),
|
|
||||||
("n", "new_show", "New Show"),
|
("n", "new_show", "New Show"),
|
||||||
#("h", "switch_mode('help')", "Help")
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# MODES = {
|
|
||||||
# "show_details": ShowDetailsScreen,
|
|
||||||
# "show_new": ShowNewScreen,
|
|
||||||
# "help": HelpScreen,
|
|
||||||
# }
|
|
||||||
|
|
||||||
def action_new_show(self):
|
def action_new_show(self):
|
||||||
self.app.push_screen(ShowDetailsScreen(), self.handle_new_screen)
|
self.app.push_screen(ShowDetailsScreen(), self.handle_new_screen)
|
||||||
|
|
||||||
|
def handle_new_screen(self, screenResult):
|
||||||
|
|
||||||
def handle_new_screen(self, showId):
|
show = (screenResult['id'], screenResult['name'], screenResult['year'])
|
||||||
|
self.table.add_row(*map(str, show))
|
||||||
|
|
||||||
showList = self.loadShows()
|
|
||||||
|
|
||||||
for show in showList:
|
def action_edit_show(self):
|
||||||
if show[0] == showId:
|
|
||||||
self.table.add_row(*map(str, show))
|
# Fetch the currently selected row when 'Enter' is pressed
|
||||||
|
#selected_row_index = self.table.cursor_row
|
||||||
|
row_key, col_key = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
|
||||||
|
|
||||||
|
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]
|
||||||
|
selectedShow['year'] = selected_row_data[2]
|
||||||
|
|
||||||
|
self.app.push_screen(ShowDetailsScreen(show = selectedShow), self.handle_edit_screen)
|
||||||
|
|
||||||
|
def handle_edit_screen(self, screenResult):
|
||||||
|
|
||||||
|
show = (screenResult['id'], screenResult['name'], screenResult['year'])
|
||||||
|
self.table.add_row(*map(str, show))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -95,23 +107,6 @@ class ShowsScreen(Screen):
|
|||||||
self.table.add_row(*map(str, show)) # Convert each element to a string before adding
|
self.table.add_row(*map(str, show)) # Convert each element to a string before adding
|
||||||
|
|
||||||
|
|
||||||
#def on_resume(self) -> None:
|
|
||||||
|
|
||||||
# quit()
|
|
||||||
|
|
||||||
# showList = self.loadShows()
|
|
||||||
#
|
|
||||||
# tableIdSet = set({int(r[0]) for r in self.table.rows})
|
|
||||||
# databaseIdSet = set({int(s[0]) for s in showList})
|
|
||||||
#
|
|
||||||
# missingIdSet = databaseIdSet - tableIdSet
|
|
||||||
# removedIdSet = tableIdSet - databaseIdSet
|
|
||||||
#
|
|
||||||
# for show in showList:
|
|
||||||
# if show[0] in missingIdSet:
|
|
||||||
# self.table.add_row(*map(str, show))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user