fixed a bug
This commit is contained in:
@@ -901,6 +901,7 @@ class MediaPlayerApp(tk.Tk):
|
|||||||
self._controls_media_path = None
|
self._controls_media_path = None
|
||||||
self._generation_token = 0
|
self._generation_token = 0
|
||||||
self._explanation_window = None
|
self._explanation_window = None
|
||||||
|
self._explanation_text = None
|
||||||
self._explanation_generation = 0
|
self._explanation_generation = 0
|
||||||
|
|
||||||
self.engine = self._create_engine()
|
self.engine = self._create_engine()
|
||||||
@@ -2030,8 +2031,15 @@ class MediaPlayerApp(tk.Tk):
|
|||||||
text = tk.Text(frame, wrap="word", state="disabled", relief="flat", background="#f6f6f6")
|
text = tk.Text(frame, wrap="word", state="disabled", relief="flat", background="#f6f6f6")
|
||||||
text.grid(row=1, column=0, sticky="nsew")
|
text.grid(row=1, column=0, sticky="nsew")
|
||||||
text.insert("1.0", "AI 正在讲解这句话…")
|
text.insert("1.0", "AI 正在讲解这句话…")
|
||||||
ttk.Button(frame, text="关闭", command=window.destroy, takefocus=0).grid(row=2, column=0, sticky="e", pady=(10, 0))
|
self._explanation_text = text
|
||||||
|
ttk.Button(
|
||||||
|
frame,
|
||||||
|
text="关闭",
|
||||||
|
command=lambda: self._close_explanation(generation),
|
||||||
|
takefocus=0,
|
||||||
|
).grid(row=2, column=0, sticky="e", pady=(10, 0))
|
||||||
self._explanation_window = window
|
self._explanation_window = window
|
||||||
|
window.protocol("WM_DELETE_WINDOW", lambda: self._close_explanation(generation))
|
||||||
|
|
||||||
path = self._current_path() or ""
|
path = self._current_path() or ""
|
||||||
course_title = Path(path).stem
|
course_title = Path(path).stem
|
||||||
@@ -2056,7 +2064,7 @@ class MediaPlayerApp(tk.Tk):
|
|||||||
self.server_url + "/api/v1/sentences/explain",
|
self.server_url + "/api/v1/sentences/explain",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=payload,
|
json=payload,
|
||||||
timeout=(15, 90),
|
timeout=(15, 180),
|
||||||
)
|
)
|
||||||
if response.status_code == 401:
|
if response.status_code == 401:
|
||||||
raise RuntimeError("登录已过期,请在“服务…”中重新登录")
|
raise RuntimeError("登录已过期,请在“服务…”中重新登录")
|
||||||
@@ -2074,15 +2082,28 @@ class MediaPlayerApp(tk.Tk):
|
|||||||
window = self._explanation_window
|
window = self._explanation_window
|
||||||
if window is None:
|
if window is None:
|
||||||
return
|
return
|
||||||
|
text = self._explanation_text
|
||||||
|
if text is None:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
text = window.nametowidget(window.grid_slaves(row=1, column=0)[0])
|
|
||||||
text.configure(state="normal")
|
text.configure(state="normal")
|
||||||
text.delete("1.0", "end")
|
text.delete("1.0", "end")
|
||||||
text.insert("1.0", explanation)
|
text.insert("1.0", explanation)
|
||||||
text.configure(state="disabled")
|
text.configure(state="disabled")
|
||||||
if error:
|
if error:
|
||||||
window.title("AI 讲解失败")
|
window.title("AI 讲解失败")
|
||||||
except (tk.TclError, IndexError):
|
self.status_var.set(explanation)
|
||||||
|
except tk.TclError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _close_explanation(self, generation):
|
||||||
|
self._explanation_generation = max(self._explanation_generation, generation + 1)
|
||||||
|
window = self._explanation_window
|
||||||
|
self._explanation_window = None
|
||||||
|
self._explanation_text = None
|
||||||
|
try:
|
||||||
|
window.destroy()
|
||||||
|
except (tk.TclError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _update_status(self):
|
def _update_status(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user