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.
ffx/bin/ffx/track_details_screen.py

223 lines
6.7 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
from ffx.model.pattern import Pattern
from .track_controller import TrackController
# from .pattern_controller import PatternController
# from .show_controller import ShowController
from .track_type import TrackType
# Screen[dict[int, str, int]]
class TrackDetailsScreen(Screen):
CSS = """
Grid {
grid-size: 5 11;
grid-rows: 2 2 2 2 6 2 2 6 2 2 2;
grid-columns: 25 25 25 25 25;
height: 100%;
width: 100%;
padding: 1;
}
Input {
border: none;
}
Button {
border: none;
}
DataTable {
min-height: 6;
}
#toplabel {
height: 1;
}
.three {
column-span: 3;
}
.four {
column-span: 4;
}
.five {
column-span: 5;
}
.box {
height: 100%;
border: solid green;
}
"""
STREAM_TYPE_LABELS = [
'video',
'audio',
'subtitle'
]
def __init__(self, trackType : TrackType, streamId = None, patternId = None):
super().__init__()
self.context = self.app.getContext()
self.Session = self.context['database_session'] # convenience
self.trackType = trackType
self.__tc = TrackController(context = self.context)
#self.__pc = PatternController(context = self.context)
#self.__sc = ShowController(context = self.context)
# self.pattern_obj = self.__pc.getPatternDescriptor(patternId) if patternId is not None else {}
# self.show_obj = self.__sc.getShowDesciptor(showId) if showId is not None else {}
self.track_obj = {}
# def loadPatterns(self, show_id):
#
# try:
# s = self.Session()
# q = s.query(Pattern).filter(Pattern.show_id == int(show_id))
#
# return [{'id': int(p.id), 'pattern': p.pattern} for p in q.all()]
#
# except Exception as ex:
# click.ClickException(f"loadPatterns(): {repr(ex)}")
# finally:
# s.close()
def on_mount(self):
pass
# if self.pattern_obj:
# self.query_one("#pattern_input", Input).value = str(self.pattern_obj['pattern'])
# if self.show_obj:
# self.query_one("#showlabel", Static).update(f"{self.show_obj['id']} - {self.show_obj['name']} ({self.show_obj['year']})")
# for pattern in self.loadPatterns(int(self.show_obj['id'])):
# row = (pattern['pattern'],)
# self.patternTable.add_row(*map(str, row))
# for subIndex in range(3):
#
# row4 = (str(subIndex),str(subIndex),str(subIndex),str(subIndex),)
# self.audioStreamsTable.add_row(*map(str, row4))
#
# row5 = (str(subIndex),str(subIndex),str(subIndex),str(subIndex),str(subIndex),)
# self.subtitleStreamsTable.add_row(*map(str, row5))
def compose(self):
# self.audioStreamsTable = DataTable(classes="five")
#
# # Define the columns with headers
# self.column_key_audio_subid = self.audioStreamsTable.add_column("Subindex", width=10)
# self.column_key_audio_layout = self.audioStreamsTable.add_column("Layout", width=10)
# self.column_key_audio_language = self.audioStreamsTable.add_column("Language", width=10)
# self.column_key_audio_title = self.audioStreamsTable.add_column("Title", width=10)
#
# self.audioStreamsTable.cursor_type = 'row'
#
#
# self.subtitleStreamsTable = DataTable(classes="five")
#
# # Define the columns with headers
# self.column_key_subtitle_subid = self.subtitleStreamsTable.add_column("Subindex", width=10)
# self.column_key_subtitle_language = self.subtitleStreamsTable.add_column("Language", width=10)
# self.column_key_subtitle_title = self.subtitleStreamsTable.add_column("Title", width=10)
# self.column_key_subtitle_default = self.subtitleStreamsTable.add_column("Default", width=10)
# self.column_key_subtitle_forced = self.subtitleStreamsTable.add_column("Forced", width=10)
#
# self.subtitleStreamsTable.cursor_type = 'row'
typeLabel = TrackDetailsScreen.STREAM_TYPE_LABELS[self.trackType-1]
yield Header()
with Grid():
# 1
yield Static(f"Edit {typeLabel} stream" if self.track_obj else f"New {typeLabel} stream", id="toplabel", classes="five")
# yield Input(type="text", id="pattern_input", classes="four")
# 2
# yield Static("from show")
# yield Static("", id="showlabel")
#
# # 3
# yield Static(" ", classes="five")
# # 4
# yield Static(" ", classes="five")
#
# # 5
# yield Static("Audio streams")
# yield Static(" ")
# yield Button("Add", id="button_add_audio_stream")
# yield Button("Edit", id="button_edit_audio_stream")
# yield Button("Delete", id="button_delete_audio_stream")
# # 6
# yield self.audioStreamsTable
#
# # 7
# yield Static(" ", classes="five")
#
# # 8
# yield Static("Subtitle streams")
# yield Static(" ")
# yield Button("Add", id="button_add_subtitle_stream")
# yield Button("Edit", id="button_edit_subtitle_stream")
# yield Button("Delete", id="button_delete_subtitle_stream")
# # 9
# yield self.subtitleStreamsTable
#
# 10
yield Static(" ", classes="five")
# 11
yield Button("Save", id="save_button")
yield Button("Cancel", id="cancel_button")
yield Footer()
# def getPatternFromInput(self):
# return str(self.query_one("#pattern_input", Input).value)
# Event handler for button press
def on_button_pressed(self, event: Button.Pressed) -> None:
# Check if the button pressed is the one we are interested in
# if event.button.id == "save_button":
#
# pattern = self.getPatternFromInput()
#
# if self.__pc.updatePattern(self.show_obj['id'], pattern):
#
# screenResult = {}
# screenResult['show_id'] = self.show_obj['id']
# screenResult['pattern'] = pattern
#
# self.dismiss(screenResult)
# else:
# #TODO: Meldung
# self.app.pop_screen()
if event.button.id == "cancel_button":
self.app.pop_screen()