Basis tui, aber noch ein paar kleinigkeiten zu verbessern
This commit is contained in:
parent
31c10e81b9
commit
fa76a3de0e
1 changed files with 46 additions and 14 deletions
|
|
@ -12,32 +12,64 @@ from prompt_toolkit.buffer import Buffer
|
|||
from prompt_toolkit.layout.layout import Layout
|
||||
from prompt_toolkit.layout.containers import Window, VSplit, HSplit
|
||||
from prompt_toolkit.layout.controls import BufferControl
|
||||
from prompt_toolkit.widgets import Button
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
hstelle=Buffer()
|
||||
keyB=KeyBindings()
|
||||
inputBuffer=Buffer()
|
||||
resultBuffer=Buffer()
|
||||
stop_event=threading.Event()
|
||||
app_state="MONITOR"
|
||||
|
||||
inputBuffer.text = "Monitor\n\nHaltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
|
||||
resultBuffer.text = "Ausgabe: "
|
||||
|
||||
def button_handler():
|
||||
print("Haltestelle")
|
||||
|
||||
|
||||
monitor = Button(text= "Monitor", handler= button_handler, width= 12, left_symbol= '<', right_symbol= '>')
|
||||
|
||||
root_container= HSplit(children=[
|
||||
VSplit(children=[
|
||||
monitor,
|
||||
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"),
|
||||
|
||||
|
||||
Window(height=1, char='-', style="bg:#9D1D75 fg:#FFFFFF"),
|
||||
])
|
||||
|
||||
layout = Layout(root_container)
|
||||
layout = Layout(root_container, focused_element=inputBuffer)
|
||||
|
||||
@keyB.add("enter")
|
||||
def handle_enter(event):
|
||||
global app_state
|
||||
|
||||
user_input = inputBuffer.text.replace("Haltestelle eingeben: ", "").strip()
|
||||
|
||||
app = Application(layout=layout, full_screen=True)
|
||||
if user_input:
|
||||
app_state = "RESULTS"
|
||||
resultBuffer.text = f"Ergebnisse für: {user_input}\n\n"
|
||||
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
else:
|
||||
app_state = "MONITOR"
|
||||
resultBuffer.text = "MONITOR\n\n"
|
||||
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
|
||||
@keyB.add("c-q")
|
||||
def exit_(event):
|
||||
stop_event.set()
|
||||
event.app.exit()
|
||||
|
||||
app = Application(layout=layout, full_screen=True, key_bindings=keyB)
|
||||
|
||||
try:
|
||||
app.run()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
stop_event.set()
|
||||
Loading…
Add table
Add a link
Reference in a new issue