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.
142 lines
3.8 KiB
Python
142 lines
3.8 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, Static, Button
|
|
from textual.containers import Grid
|
|
|
|
from ffx.model.pattern import Pattern
|
|
from ffx.model.track import Track
|
|
from ffx.track_descriptor import TrackDescriptor
|
|
|
|
from .track_controller import TrackController
|
|
|
|
from .track_type import TrackType
|
|
|
|
# Screen[dict[int, str, int]]
|
|
class TrackDeleteScreen(Screen):
|
|
|
|
CSS = """
|
|
|
|
Grid {
|
|
grid-size: 4 9;
|
|
grid-rows: 2 2 2 2 2 2 2 2 2;
|
|
grid-columns: 30 30 30 30;
|
|
height: 100%;
|
|
width: 100%;
|
|
padding: 1;
|
|
}
|
|
|
|
Input {
|
|
border: none;
|
|
}
|
|
Button {
|
|
border: none;
|
|
}
|
|
#toplabel {
|
|
height: 1;
|
|
}
|
|
|
|
.two {
|
|
column-span: 2;
|
|
}
|
|
.three {
|
|
column-span: 3;
|
|
}
|
|
.four {
|
|
column-span: 4;
|
|
}
|
|
|
|
.box {
|
|
height: 100%;
|
|
border: solid green;
|
|
}
|
|
"""
|
|
|
|
def __init__(self, trackDescriptor : TrackDescriptor):
|
|
super().__init__()
|
|
|
|
self.context = self.app.getContext()
|
|
self.Session = self.context['database']['session'] # convenience
|
|
|
|
if type(trackDescriptor) is not TrackDescriptor:
|
|
raise click.ClickException('TrackDeleteScreen.init(): trackDescriptor is required to be of type TrackDescriptor')
|
|
|
|
self.__tc = TrackController(context = self.context)
|
|
|
|
self.__trackDescriptor = trackDescriptor
|
|
|
|
|
|
def on_mount(self):
|
|
|
|
self.query_one("#subindexlabel", Static).update(str(self.__trackDescriptor.getSubIndex()))
|
|
self.query_one("#patternlabel", Static).update(str(self.__trackDescriptor.getPatternId()))
|
|
self.query_one("#languagelabel", Static).update(str(self.__trackDescriptor.getLanguage().label()))
|
|
self.query_one("#titlelabel", Static).update(str(str(self.__trackDescriptor.getTitle())))
|
|
|
|
|
|
def compose(self):
|
|
|
|
yield Header()
|
|
|
|
with Grid():
|
|
|
|
#1
|
|
yield Static(f"Are you sure to delete the following {self.__trackDescriptor.getType().label()} track?", id="toplabel", classes="four")
|
|
|
|
#2
|
|
yield Static("sub index")
|
|
yield Static(" ", id="subindexlabel", classes="three")
|
|
|
|
#3
|
|
yield Static("from pattern")
|
|
yield Static(" ", id="patternlabel", classes="three")
|
|
|
|
#4
|
|
yield Static(" ", classes="four")
|
|
|
|
#5
|
|
yield Static("Language")
|
|
yield Static(" ", id="languagelabel", classes="three")
|
|
|
|
#6
|
|
yield Static("Title")
|
|
yield Static(" ", id="titlelabel", classes="three")
|
|
|
|
#7
|
|
yield Static(" ", classes="four")
|
|
|
|
#8
|
|
yield Static(" ", classes="four")
|
|
|
|
#9
|
|
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":
|
|
|
|
track = self.__tc.getTrack(self.__trackDescriptor.getPatternId(), self.__trackDescriptor.getIndex())
|
|
|
|
if track is None:
|
|
raise click.ClickException(f"Track is none: patternId={self.__trackDescriptor.getPatternId()} type={self.__trackDescriptor.getType()} subIndex={self.__trackDescriptor.getSubIndex()}")
|
|
|
|
if track is not None:
|
|
|
|
if self.__tc.deleteTrack(track.getId()):
|
|
self.dismiss(self.__trackDescriptor)
|
|
|
|
else:
|
|
#TODO: Meldung
|
|
self.app.pop_screen()
|
|
|
|
if event.button.id == "cancel_button":
|
|
self.app.pop_screen()
|
|
|