You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
2.6 KiB
Python
123 lines
2.6 KiB
Python
import click
|
|
|
|
from textual import events
|
|
from textual.app import App, ComposeResult
|
|
from textual.screen import Screen
|
|
from textual.widgets import Header, Footer, Placeholder, Label, ListView, ListItem, Static, DataTable, Button, Input
|
|
from textual.containers import Grid, Horizontal
|
|
|
|
from ffx.model.show import Show
|
|
|
|
# Screen[dict[int, str, int]]
|
|
class ShowDeleteScreen(Screen):
|
|
|
|
CSS = """
|
|
|
|
Grid {
|
|
grid-size: 2;
|
|
grid-rows: 2 auto;
|
|
grid-columns: 30 auto;
|
|
height: 100%;
|
|
width: 100%;
|
|
padding: 1;
|
|
}
|
|
|
|
Input {
|
|
border: none;
|
|
}
|
|
Button {
|
|
border: none;
|
|
}
|
|
#toplabel {
|
|
height: 1;
|
|
column-span: 2;
|
|
}
|
|
|
|
|
|
#two {
|
|
column-span: 2;
|
|
row-span: 2;
|
|
tint: magenta 40%;
|
|
}
|
|
|
|
.box {
|
|
height: 100%;
|
|
border: solid green;
|
|
}
|
|
"""
|
|
|
|
def __init__(self, show = {}):
|
|
super().__init__()
|
|
|
|
self.context = self.app.getContext()
|
|
|
|
self.Session = self.context['database_session'] # convenience
|
|
|
|
self.show_obj = show
|
|
|
|
|
|
def on_mount(self):
|
|
|
|
if self.show_obj:
|
|
|
|
self.query_one("#showlabel", Static).update(f"{self.show_obj['id']} - {self.show_obj['name']} ({self.show_obj['year']})")
|
|
|
|
|
|
def compose(self):
|
|
|
|
yield Header()
|
|
|
|
with Grid():
|
|
|
|
yield Static("Are you sure to delete the following show?", id="toplabel")
|
|
|
|
yield Static("")
|
|
yield Static("")
|
|
|
|
yield Static("", id="showlabel")
|
|
yield Static("")
|
|
|
|
yield Static("")
|
|
yield Static("")
|
|
|
|
yield Static("")
|
|
yield Static("")
|
|
|
|
yield Button("Delete", id="delete_button")
|
|
yield Button("Cancel", id="cancel_button")
|
|
|
|
|
|
yield Footer()
|
|
|
|
|
|
# Event handler for button press
|
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
|
|
if event.button.id == "delete_button":
|
|
|
|
if self.deleteShow(self.show_obj['id']):
|
|
self.dismiss(self.show_obj['id'])
|
|
|
|
else:
|
|
#TODO: Meldung
|
|
self.app.pop_screen()
|
|
|
|
if event.button.id == "cancel_button":
|
|
self.app.pop_screen()
|
|
|
|
def deleteShow(self, show_id):
|
|
try:
|
|
s = self.Session()
|
|
q = s.query(Show).filter(Show.id == int(show_id))
|
|
|
|
if q.count():
|
|
q.delete()
|
|
s.commit()
|
|
return True
|
|
return False
|
|
|
|
except Exception as ex:
|
|
click.ClickException(f"ShowDetailsScreen.updateShow(): {repr(ex)}")
|
|
finally:
|
|
s.close()
|