|
|
@ -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,
|
|
|
|
s.add(show)
|
|
|
|
name = show_name,
|
|
|
|
s.commit()
|
|
|
|
year = show_year)
|
|
|
|
|
|
|
|
s.add(show)
|
|
|
|
|
|
|
|
s.commit()
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
click.ClickException(f"ShowDetailsScreen.addShow(): {repr(ex)}")
|
|
|
|
click.ClickException(f"ShowDetailsScreen.addShow(): {repr(ex)}")
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|