added basic connection between the files, fixed small issues. some parts were achieved using ai.
This commit is contained in:
parent
dd5816b175
commit
45e5cadc62
4 changed files with 184 additions and 63 deletions
|
|
@ -7,6 +7,7 @@ Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be
|
|||
The application will provide routing information and station departures/arrivals.
|
||||
"""
|
||||
|
||||
import backend
|
||||
from prompt_toolkit import Application
|
||||
from prompt_toolkit.buffer import Buffer
|
||||
from prompt_toolkit.layout.layout import Layout
|
||||
|
|
@ -17,59 +18,72 @@ import threading
|
|||
import time
|
||||
|
||||
|
||||
keyB=KeyBindings()
|
||||
inputBuffer=Buffer()
|
||||
resultBuffer=Buffer()
|
||||
stop_event=threading.Event()
|
||||
app_state="MONITOR"
|
||||
def run_station_monitor(hafas: backend.HafasClient | None = None):
|
||||
"""Run the station monitor TUI.
|
||||
|
||||
inputBuffer.text = "Monitor\n\nHaltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
Parameters:
|
||||
- hafas: optional shared HafasClient instance. If omitted, a new one is
|
||||
created. Prefer passing the shared client from `main.py`.
|
||||
|
||||
resultBuffer.text = "Ausgabe: "
|
||||
Note: Some parts of this monitor are incomplete; see TODO markers.
|
||||
"""
|
||||
if hafas is None:
|
||||
hafas = backend.HafasClient()
|
||||
|
||||
keyB = KeyBindings()
|
||||
inputBuffer = Buffer()
|
||||
resultBuffer = Buffer()
|
||||
stop_event = threading.Event()
|
||||
app_state = "MONITOR"
|
||||
|
||||
root_container= HSplit(children=[
|
||||
VSplit(children=[
|
||||
Window(content=BufferControl(buffer=inputBuffer, focusable=True)),
|
||||
|
||||
Window(width=1, char='│', style="fg:#9D1D75"),
|
||||
Window(content=BufferControl(buffer=resultBuffer, focusable=True)),
|
||||
]),
|
||||
Window(height=1, char='-', style="bg:#9D1D75 fg:#FFFFFF"),
|
||||
])
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
resultBuffer.text = "Ausgabe: "
|
||||
|
||||
layout = Layout(root_container, focused_element=inputBuffer)
|
||||
root_container = HSplit(children=[
|
||||
VSplit(children=[
|
||||
Window(content=BufferControl(buffer=inputBuffer, focusable=True)),
|
||||
Window(width=1, char='│', style="fg:#9D1D75"),
|
||||
Window(content=BufferControl(buffer=resultBuffer, focusable=True)),
|
||||
]),
|
||||
Window(height=1, char='-', style="bg:#9D1D75 fg:#FFFFFF"),
|
||||
])
|
||||
|
||||
@keyB.add("enter")
|
||||
def handle_enter(event):
|
||||
global app_state
|
||||
layout = Layout(root_container, focused_element=inputBuffer)
|
||||
|
||||
user_input = inputBuffer.text.replace("Haltestelle eingeben: ", "").strip()
|
||||
@keyB.add("enter")
|
||||
def handle_enter(event):
|
||||
global app_state
|
||||
|
||||
if user_input:
|
||||
app_state = "RESULTS"
|
||||
resultBuffer.text = f"Ergebnisse für: {user_input}\n\n"
|
||||
user_input = inputBuffer.text.replace("Haltestelle eingeben: ", "").strip()
|
||||
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
else:
|
||||
app_state = "MONITOR"
|
||||
resultBuffer.text = "MONITOR\n\n"
|
||||
if user_input:
|
||||
app_state = "RESULTS"
|
||||
# TODO: handle case of no results gracefully
|
||||
results = hafas.getStationNames(user_input)
|
||||
inputBuffer.insert_line_below()
|
||||
for station in results:
|
||||
inputBuffer.insert_text(f"\n {station[0]}")
|
||||
resultBuffer.text = f"Ergebnisse für: {results[0][1]}\n\n"
|
||||
station = results[0][1] if results else "Keine Ergebnisse gefunden."
|
||||
result = hafas.getArrDep(station, arrdep="ARR", count=3)
|
||||
inputBuffer.insert_line_below()
|
||||
for entry in result:
|
||||
resultBuffer.insert_text(f"\n {result[0]}")
|
||||
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
else:
|
||||
app_state = "MONITOR"
|
||||
|
||||
@keyB.add("c-q")
|
||||
def exit_(event):
|
||||
stop_event.set()
|
||||
event.app.exit()
|
||||
@keyB.add("c-q")
|
||||
def exit_(event):
|
||||
stop_event.set()
|
||||
event.app.exit()
|
||||
|
||||
app = Application(layout=layout, full_screen=True, key_bindings=keyB)
|
||||
app = Application(layout=layout, full_screen=True, key_bindings=keyB)
|
||||
|
||||
try:
|
||||
app.run()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
stop_event.set()
|
||||
try:
|
||||
app.run()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
stop_event.set()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue