Rekipjan's picture
Upload folder using huggingface_hub
136c905 verified
raw
history blame contribute delete
699 Bytes
# main.py
import keyboard
from candidate_window import CandidateWindow
from engine import Engine
cw = CandidateWindow()
engine = Engine()
def on_key(e):
if e.event_type != "down":
return
# ESC 隐藏
if e.name == "esc":
cw.hide()
engine.reset()
return
# 普通字符
if len(e.name) == 1:
candidates = engine.input(e.name)
text = "\n".join([
f"{i+1}. {c}" for i, c in enumerate(candidates)
])
cw.set_text(text)
cw.show()
# 空格选择(模拟)
if e.name == "space":
engine.reset()
cw.hide()
keyboard.hook(on_key)
cw.start()