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
87
main.py
87
main.py
|
|
@ -6,3 +6,90 @@ haTerm is a Terminal Based hafas client, using the ivb endpoint.
|
|||
Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI).
|
||||
The application will provide routing information and station departures/arrivals.
|
||||
"""
|
||||
|
||||
from backend import HafasClient
|
||||
import route_planning
|
||||
import station_monitor
|
||||
|
||||
from prompt_toolkit import Application
|
||||
from prompt_toolkit.layout import Layout, HSplit, VSplit, Window
|
||||
from prompt_toolkit.widgets import Button, Box
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
|
||||
|
||||
def pk_menu(client: HafasClient):
|
||||
"""Display a centered menu with two buttons selectable by arrow keys.
|
||||
|
||||
The function runs a full-screen prompt_toolkit application. Left/right
|
||||
arrows move focus between the buttons; Enter activates the focused
|
||||
button. The function returns the chosen mode as a string or None when
|
||||
the user quits.
|
||||
"""
|
||||
choice = {'value': None}
|
||||
|
||||
def on_rp():
|
||||
choice['value'] = 'rp'
|
||||
app.exit()
|
||||
|
||||
def on_sm():
|
||||
choice['value'] = 'sm'
|
||||
app.exit()
|
||||
|
||||
btn_rp = Button("Route Planning", handler=on_rp, width=20)
|
||||
btn_sm = Button("Station Monitor", handler=on_sm, width=20)
|
||||
|
||||
buttons = [btn_rp, btn_sm]
|
||||
index = {'i': 0}
|
||||
|
||||
kb = KeyBindings()
|
||||
|
||||
def focus_current():
|
||||
app.layout.focus(buttons[index['i']])
|
||||
|
||||
@kb.add('left')
|
||||
def _left(event):
|
||||
index['i'] = max(0, index['i'] - 1)
|
||||
focus_current()
|
||||
|
||||
@kb.add('right')
|
||||
def _right(event):
|
||||
index['i'] = min(len(buttons) - 1, index['i'] + 1)
|
||||
focus_current()
|
||||
|
||||
@kb.add('q')
|
||||
@kb.add('c-q')
|
||||
@kb.add('c-c')
|
||||
def _quit(event):
|
||||
app.exit()
|
||||
|
||||
root = HSplit(children=[
|
||||
Window(),
|
||||
Box(VSplit(children=[
|
||||
Window(),
|
||||
Box(VSplit(children=buttons, padding=6), padding=2, style="bg:#2A71D5 fg:#FFFFFF"),
|
||||
Window()
|
||||
])),
|
||||
Window()
|
||||
], align='CENTER')
|
||||
|
||||
app = Application(layout=Layout(root, focused_element=btn_rp), key_bindings=kb, full_screen=True)
|
||||
app.run()
|
||||
return choice['value']
|
||||
|
||||
|
||||
def main():
|
||||
client = HafasClient()
|
||||
|
||||
while True:
|
||||
result = pk_menu(client)
|
||||
if result == 'rp':
|
||||
route_planning.run_route_planning(client)
|
||||
elif result == 'sm':
|
||||
station_monitor.run_station_monitor(client)
|
||||
else:
|
||||
print("Exiting.")
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue