feat: 完成新版缓存管理器
This commit is contained in:
@@ -1 +1 @@
|
||||
print("Hello from HeurAMS Program :)")
|
||||
print("欢迎使用 HeurAMS 及其组件!")
|
||||
|
||||
@@ -39,9 +39,10 @@ class PrecachingScreen(Screen):
|
||||
self.current_file = ""
|
||||
self.current_item = ""
|
||||
self.progress = 0
|
||||
self.total = 0
|
||||
self.total = len(nucleons)
|
||||
self.processed = 0
|
||||
self.precache_worker = None
|
||||
self.cancel_flag = 0
|
||||
self.desc = desc
|
||||
for i in nucleons:
|
||||
i: pt.Nucleon
|
||||
@@ -70,6 +71,10 @@ class PrecachingScreen(Screen):
|
||||
yield Button("取消预缓存", id="cancel_precache", variant="error")
|
||||
yield Button("清空缓存", id="clear_cache", variant="warning")
|
||||
yield Button("返回", id="go_back", variant="default")
|
||||
|
||||
yield Static("若您离开此界面, 未完成的缓存进程会自动停止.")
|
||||
yield Static("缓存程序支持 \"断点续传\".")
|
||||
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self):
|
||||
@@ -116,17 +121,22 @@ class PrecachingScreen(Screen):
|
||||
def precache_by_list(self, nucleons: list):
|
||||
"""依据 Nucleons 列表缓存"""
|
||||
for idx, nucleon in enumerate(nucleons):
|
||||
print(f"PROC: {nucleon}")
|
||||
#print(f"PROC: {nucleon}")
|
||||
worker = get_current_worker()
|
||||
if worker and worker.is_cancelled: # 函数在worker中执行且已被取消
|
||||
return False
|
||||
text = nucleon.metadata['formation']['tts_text']
|
||||
#self.current_item = text[:30] + "..." if len(text) > 50 else text
|
||||
print(text)
|
||||
#print(text)
|
||||
self.processed += 1
|
||||
#print(self.processed)
|
||||
#print(self.total)
|
||||
progress = int((self.processed / self.total) * 100) if self.total > 0 else 0
|
||||
#print(progress)
|
||||
self.update_status(
|
||||
f"正处理 ({idx + 1}/{len(nucleons)})"
|
||||
f"正处理 ({idx + 1}/{len(nucleons)})",
|
||||
text,
|
||||
progress
|
||||
)
|
||||
ret = self.precache_by_nucleon(nucleon)
|
||||
if not ret:
|
||||
@@ -136,6 +146,10 @@ class PrecachingScreen(Screen):
|
||||
)
|
||||
import time
|
||||
time.sleep(1)
|
||||
if self.cancel_flag:
|
||||
worker.cancel()
|
||||
self.cancel_flag = 0
|
||||
return False
|
||||
return True
|
||||
|
||||
def precache_by_nucleons(self):
|
||||
@@ -197,6 +211,8 @@ class PrecachingScreen(Screen):
|
||||
if self.precache_worker:
|
||||
self.precache_worker.cancel()
|
||||
self.is_precaching = False
|
||||
self.processed = 0
|
||||
self.progress = 0
|
||||
self.update_status("已取消", "预缓存操作被用户取消", 0)
|
||||
|
||||
elif event.button.id == "clear_cache":
|
||||
@@ -208,6 +224,9 @@ class PrecachingScreen(Screen):
|
||||
self.update_status("已清空", "音频缓存已清空", 0)
|
||||
except Exception as e:
|
||||
self.update_status("错误", f"清空缓存失败: {e}")
|
||||
self.cancel_flag = 1
|
||||
self.processed = 0
|
||||
self.progress = 0
|
||||
|
||||
elif event.button.id == "go_back":
|
||||
self.action_go_back()
|
||||
|
||||
Reference in New Issue
Block a user