Starta på TUI
This commit is contained in:
parent
bc611e91e9
commit
60824e5bd3
158
event_mgr.py
158
event_mgr.py
@ -14,55 +14,129 @@ from rich.columns import Columns
|
|||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.console import Group
|
from rich.console import Group
|
||||||
|
from rich.syntax import Syntax
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
|
from time import monotonic
|
||||||
|
|
||||||
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.containers import ScrollableContainer, Horizontal, Vertical
|
||||||
|
from textual.reactive import reactive
|
||||||
|
from textual.widgets import Button, Footer, Header, Static, RichLog, DataTable, Label
|
||||||
|
class RunnerTable(Static):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield DataTable(id="runnertable")
|
||||||
|
|
||||||
|
def RowSelected(self, data_table, cursor_row, row_key) -> None:
|
||||||
|
name = self.query_one("#inspname")
|
||||||
|
name.update(renderable='test')
|
||||||
|
ecard_log = app.query_one("#ecardlog")
|
||||||
|
ecard_log.write('aaaaaaaaaaaaaaaaa')
|
||||||
|
|
||||||
|
class RunnerInsp(Static):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Static("NAVN", id="inspname")
|
||||||
|
yield Label("RESULTAT", id="inspresult")
|
||||||
|
yield Label("POSTER", id="inspcontr")
|
||||||
|
class EcardLog(Static):
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield RichLog(highlight=True, markup=True, id="ecardlog")
|
||||||
|
|
||||||
def run_otime():
|
class MTRDash(Static):
|
||||||
event = otime.Event.from_toml(open("/home/trygve/Prosjekter/otime-testing/sc3/sc3.toml", "rb"))
|
def compose(self) -> ComposeResult:
|
||||||
event.import_ttime_db(open("/home/trygve/Prosjekter/otime-testing/sc3/db.csv"))
|
yield Label("MTR")
|
||||||
|
|
||||||
data = (open("/home/trygve/Prosjekter/otime-testing/sc3/mtr.json")).readlines()
|
class TimeApp(App):
|
||||||
for l in data:
|
CSS_PATH = "event_mgr.tcss"
|
||||||
d = json.loads(l)
|
BINDINGS = [("d", "toggle_dark", "Toggle dark mode"), ("r", "rerun", "Rerun")]
|
||||||
#print(l)
|
|
||||||
event.card_dumps.append(otime.CardDump(d['card'], d['controls'], d['splits'],
|
|
||||||
datetime.datetime.fromisoformat(d['read_time']),
|
|
||||||
datetime.datetime.fromisoformat(d['s_time']),
|
|
||||||
datetime.datetime.fromisoformat(d['f_time'])))
|
|
||||||
print('Ecards:'+str(len(event.card_dumps)))
|
|
||||||
print('Løpere:'+str(len(event.runners)))
|
|
||||||
event.match_all()
|
|
||||||
#cli.print_runners(event.runners)
|
|
||||||
for n in event.o_classes:
|
|
||||||
cli.print_class_result(event.runners, n)
|
|
||||||
|
|
||||||
def read_mtr(mtr):
|
def compose(self) -> ComposeResult:
|
||||||
global event
|
"""Create child widgets for the app."""
|
||||||
if mtr.in_waiting > 0:
|
yield Header()
|
||||||
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
yield Footer()
|
||||||
size = mtr.read(size=1)
|
yield RunnerTable(classes="box")
|
||||||
if size == b'\xe6':
|
yield RunnerInsp(classes="box")
|
||||||
meat = mtr.read(229)
|
yield EcardLog(classes="box")
|
||||||
full = b'\xFF\xFF\xFF\xFF' + size + meat
|
yield MTRDash(classes="box")
|
||||||
card_r = otime.CardDump.from_mtr_bytes(full)
|
|
||||||
print(json.dumps(card_r.asdict()))
|
|
||||||
with open("sc3/mtr.json", "a") as myfile:
|
|
||||||
myfile.write('\n' + json.dumps(card_r.asdict()))
|
|
||||||
run_otime()
|
|
||||||
|
|
||||||
elif size == b'\x37':
|
def on_ready(self) -> None:
|
||||||
meat = mtr.read(55)
|
mtr = serial.Serial(port="/dev/pts/2", baudrate=9600, timeout=40)
|
||||||
status = mtrreader.MtrStatusMessage(meat)
|
ecard_log = self.query_one("#ecardlog")
|
||||||
inspect(status)
|
ecard_log.write("[bold magenta]Write text or any Rich renderable!")
|
||||||
print(status.year(),status.month(),status.day(),status.hours(),status.minutes())
|
#self.run_worker(self.watch_serial())
|
||||||
|
self.render_table()
|
||||||
|
self.read_mtr()
|
||||||
|
|
||||||
|
def action_toggle_dark(self) -> None:
|
||||||
|
"""An action to toggle dark mode."""
|
||||||
|
self.dark = not self.dark
|
||||||
|
def action_rerun(self) -> None:
|
||||||
|
"""Rerun otime"""
|
||||||
|
self.run_otime()
|
||||||
|
|
||||||
|
def read_mtr(app):
|
||||||
|
mtr = serial.Serial(port="/dev/pts/2", baudrate=9600, timeout=40)
|
||||||
|
# mtr.write(b'/SA')
|
||||||
|
global event
|
||||||
|
if mtr.in_waiting > 0:
|
||||||
|
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
||||||
|
size = mtr.read(size=1)
|
||||||
|
if size == b'\xe6':
|
||||||
|
meat = mtr.read(229)
|
||||||
|
full = b'\xFF\xFF\xFF\xFF' + size + meat
|
||||||
|
card_r = otime.CardDump.from_mtr_bytes(full)
|
||||||
|
ecard_log.write(json.dumps(card_r.asdict()))
|
||||||
|
with open("sc3/mtr.json", "a") as myfile:
|
||||||
|
myfile.write('\n' + json.dumps(card_r.asdict()))
|
||||||
|
run_otime()
|
||||||
|
|
||||||
|
elif size == b'\x37':
|
||||||
|
meat = mtr.read(55)
|
||||||
|
status = mtrreader.MtrStatusMessage(meat)
|
||||||
|
inspect(status)
|
||||||
|
ecard_log.write(status.year(),status.month(),status.day(),status.hours(),status.minutes())
|
||||||
|
|
||||||
|
def run_otime(app):
|
||||||
|
ecard_log = app.query_one("#ecardlog")
|
||||||
|
event = otime.Event.from_toml(open("/home/trygve/Prosjekter/otime-testing/sc3/sc3.toml", "rb"))
|
||||||
|
event.import_ttime_db(open("/home/trygve/Prosjekter/otime-testing/sc3/db.csv"))
|
||||||
|
|
||||||
|
data = (open("/home/trygve/Prosjekter/otime-testing/sc3/mtr.json")).readlines()
|
||||||
|
for l in data:
|
||||||
|
d = json.loads(l)
|
||||||
|
ecard_log.write(l)
|
||||||
|
event.card_dumps.append(otime.CardDump(d['card'], d['controls'], d['splits'],
|
||||||
|
datetime.datetime.fromisoformat(d['read_time']),
|
||||||
|
datetime.datetime.fromisoformat(d['s_time']),
|
||||||
|
datetime.datetime.fromisoformat(d['f_time'])))
|
||||||
|
#ecard_log.write('Ecards:'+str(len(event.card_dumps)))
|
||||||
|
#ecard_log.write('Løpere:'+str(len(event.runners)))
|
||||||
|
event.match_all()
|
||||||
|
#cli.print_runners(event.runners)
|
||||||
|
#for n in event.o_classes:
|
||||||
|
#cli.print_class_result(event.runners, n)
|
||||||
|
return event
|
||||||
|
|
||||||
|
def render_table(app):
|
||||||
|
table = app.query_one("#runnertable")
|
||||||
|
table.cursor_type = "row"
|
||||||
|
table.add_column("Name")
|
||||||
|
table.add_column("Status")
|
||||||
|
table.add_column("club")
|
||||||
|
table.add_column("card")
|
||||||
|
table.add_column("class")
|
||||||
|
table.add_column("start_time")
|
||||||
|
table.add_column("fork")
|
||||||
|
|
||||||
|
for i in app.run_otime().runners:
|
||||||
|
try:
|
||||||
|
o_class = i.o_class.name
|
||||||
|
except:
|
||||||
|
o_class = ''
|
||||||
|
table.add_row(i.fullname(), i.status(), i.club ,str(i.card), o_class, i.start_time, str(i.fork))
|
||||||
|
|
||||||
def main():
|
|
||||||
mtr = serial.Serial(port="/dev/pts/2", baudrate=9600, timeout=40)
|
|
||||||
# mtr.write(b'/SA')
|
|
||||||
while True:
|
|
||||||
read_mtr(mtr)
|
|
||||||
sleep(0.1)
|
|
||||||
|
|
||||||
db_file_u = None
|
db_file_u = None
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
app = TimeApp()
|
||||||
|
app.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user