Starta på søke tui

This commit is contained in:
Trygve 2023-11-24 00:42:02 +01:00
parent 24f8c30c81
commit f1612cf838
2 changed files with 37 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import iof_xml
import pdf
from pdf import format_m_s
from rich import print
import search_tui
# Main entrypoint for now. Cli with two options; init will make the files needed and run will start the program from the specified directory
def main():
@ -27,6 +28,10 @@ def main():
parser_init.add_argument('--port', required=False, dest='port', action='store', help='specify a serial port')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
parser_init = subparsers.add_parser('viewer', help='View otime data')
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./', help='specify a directory')
parser_init.add_argument('--xml', required=False, dest='xml_path', action='store', default=None, help='Where the xml result file should be saved')
args = parser.parse_args()
if not args.xml_path:
@ -37,6 +42,8 @@ def main():
init_dir(args.dir, args.entries_file, args.courses_file)
case 'run':
run(args.port, args.dir, args.xml_path)
case 'viewer':
search_tui.main(args.dir)
def init_dir(project_dir, entries_xml_file, courses_xml_file):
# Lager mappe med en config fil, en csv fil med løpere og en fil med mtr data

30
otime/search_tui.py Normal file
View File

@ -0,0 +1,30 @@
from textual.app import App, ComposeResult
from textual.widgets import DataTable
import otime
import file_io
from pdf import format_m_s
global ROWS
class TableApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
global ROWS
table = self.query_one(DataTable)
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])
def main(path):
event = file_io.event_from_yaml_and_csv(path + '/config.yaml', path + '/mtr.yaml', path + '/runners.csv')
result = event.get_result()
global ROWS
ROWS = []
for o_class in result:
ROWS += [(str(i.id), str(i.place), i.fullname(), i.o_class, i.club, str(i.card_id), format_m_s(i.total_time), str(i.controls)) for i in o_class.runner_results]
print(ROWS)
app = TableApp()
app.run()
if __name__ == "__main__":
main()