Skip to content

Commit 4145849

Browse files
committed
v1.9.1: 添加仅修复模式,修复编辑器文件管理bug
新功能: - 添加'仅修复'翻译模式,跳过OCR和翻译,只进行文字检测和修复 - 修复模式使用完整的mask refinement流程,确保修复质量 Bug修复: - 修复主页添加单个文件后,编辑器显示整个文件夹的问题 - 修复卸载文件夹后,编辑器画布不清空的问题 - 修复编辑器删除文件时列表重建导致文件夹折叠的问题 - 修复inpainting时mask尺寸不匹配的问题 - 统一主页和编辑器的文件删除逻辑,确保数据同步 优化: - 改进编辑器文件列表管理,使用app_logic的文件列表,避免重复展开 - 优化文件删除流程,删除单个文件不重建列表 - 改进文件夹路径转换逻辑,正确处理翻译后的文件夹
1 parent 1e67469 commit 4145849

24 files changed

Lines changed: 453 additions & 162 deletions

desktop_qt_ui/app_logic.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,39 @@ def remove_file(self, file_path: str):
747747
# 情况1:直接在 source_files 中(文件夹或单独添加的文件)
748748
if norm_file_path in self.source_files:
749749
self.source_files.remove(norm_file_path)
750+
# 如果是文件,清理 file_to_folder_map
751+
if norm_file_path in self.file_to_folder_map:
752+
del self.file_to_folder_map[norm_file_path]
750753
self.file_removed.emit(file_path)
751754
return
752755

753-
# 情况2:文件夹内的单个文件(只处理文件,不处理文件夹)
756+
# 情况2:文件夹路径(通过单独添加文件自动分组的)
757+
if os.path.isdir(norm_file_path):
758+
# 删除该文件夹下的所有文件
759+
files_to_remove = []
760+
for source_file in self.source_files:
761+
if os.path.isfile(source_file):
762+
try:
763+
# 检查文件是否在这个文件夹内
764+
common = os.path.commonpath([norm_file_path, source_file])
765+
if common == norm_file_path:
766+
files_to_remove.append(source_file)
767+
except ValueError:
768+
# 不同驱动器,跳过
769+
continue
770+
771+
# 移除所有找到的文件
772+
for f in files_to_remove:
773+
self.source_files.remove(f)
774+
# 同时清理 file_to_folder_map
775+
if f in self.file_to_folder_map:
776+
del self.file_to_folder_map[f]
777+
778+
if files_to_remove:
779+
self.file_removed.emit(file_path)
780+
return
781+
782+
# 情况3:文件夹内的单个文件(只处理文件,不处理文件夹)
754783
if os.path.isfile(norm_file_path):
755784
# 检查这个文件是否来自某个文件夹
756785
parent_folder = None
@@ -785,6 +814,10 @@ def remove_file(self, file_path: str):
785814
# 如果还有剩余文件,将它们作为单独的文件添加回去
786815
if remaining_files:
787816
self.source_files.extend(remaining_files)
817+
# 更新 file_to_folder_map:这些文件现在仍然属于原文件夹
818+
# 保持文件夹映射关系,以便输出路径计算正确
819+
for f in remaining_files:
820+
self.file_to_folder_map[f] = parent_folder
788821

789822
self.file_removed.emit(file_path)
790823
return
@@ -812,7 +845,9 @@ def _resolve_input_files(self) -> List[str]:
812845
按文件夹分组排序:先对文件夹进行排序,然后对每个文件夹内的图片排序。
813846
"""
814847
resolved_files = []
815-
self.file_to_folder_map.clear() # 清空旧的映射
848+
# 保存旧的映射,用于处理删除文件后的情况
849+
old_map = self.file_to_folder_map.copy()
850+
self.file_to_folder_map.clear()
816851

817852
# 分离文件和文件夹
818853
folders = []
@@ -841,8 +876,13 @@ def _resolve_input_files(self) -> List[str]:
841876
individual_files.sort(key=self.file_service._natural_sort_key)
842877
for file_path in individual_files:
843878
resolved_files.append(file_path)
844-
# 单独添加的文件,不属于任何文件夹
845-
self.file_to_folder_map[file_path] = None
879+
# 检查是否有旧的文件夹映射(删除文件后剩余的文件)
880+
if file_path in old_map and old_map[file_path] is not None:
881+
# 保留原来的文件夹映射
882+
self.file_to_folder_map[file_path] = old_map[file_path]
883+
else:
884+
# 真正单独添加的文件,不属于任何文件夹
885+
self.file_to_folder_map[file_path] = None
846886

847887
return list(dict.fromkeys(resolved_files)) # Return unique files
848888

desktop_qt_ui/core/config_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class CliSettings(BaseModel):
122122
generate_and_export: bool = False
123123
colorize_only: bool = False
124124
upscale_only: bool = False # 仅超分模式
125+
inpaint_only: bool = False # 仅输出修复图片模式
125126

126127
class AppSection(BaseModel):
127128
last_open_dir: str = '.'

desktop_qt_ui/editor/editor_logic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ def load_file_lists(self, source_files: List[str], translated_files: List[str],
215215
else:
216216
single_files.append(file_path)
217217

218-
# 构建文件列表:先是文件夹,再是单独文件
218+
# 构建文件列表:按文件夹分组,但只添加文件,不添加文件夹路径
219+
# 这样可以保持文件夹分组的顺序,但不会让FileListView重新展开文件夹
219220
grouped_list = []
220221
for folder, files in sorted(folder_groups.items()):
221-
grouped_list.append(folder) # 添加文件夹路径
222-
# 注意:FileListView 会自动展开文件夹
222+
# 只添加文件,不添加文件夹路径
223+
# 文件会按文件夹分组显示,但不会重新展开文件夹
224+
grouped_list.extend(files)
223225
grouped_list.extend(single_files) # 添加单独的文件
224226

225227
self.file_list_changed.emit(grouped_list)

desktop_qt_ui/editor_view.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,42 @@ def _create_right_panel(self) -> QWidget:
390390

391391
@pyqtSlot(str)
392392
def _on_file_remove_requested(self, file_path: str):
393-
"""处理文件移除请求:先在视图中移除,再更新逻辑层"""
394-
# 先在视图中移除文件(不会触发重新构建)
393+
"""处理文件移除请求:先在视图中移除,再调用app_logic同步"""
394+
import os
395+
396+
# 如果是翻译后的文件/文件夹,需要找到对应的源文件/文件夹
397+
source_path, translated_path = self.logic._find_file_pair(file_path)
398+
399+
# 如果是文件夹,需要特殊处理
400+
if os.path.isdir(file_path):
401+
# 翻译后的文件夹,需要找到对应的源文件夹
402+
# 从 file_to_folder_map 中查找任意一个文件,获取其源文件夹
403+
source_folder = None
404+
for src_file, folder in self.app_logic.file_to_folder_map.items():
405+
if folder:
406+
# 检查这个文件是否在当前要删除的翻译文件夹内
407+
# 通过文件名匹配(因为翻译文件夹和源文件夹的文件名相同)
408+
try:
409+
# 获取源文件的文件名
410+
src_filename = os.path.basename(src_file)
411+
# 检查翻译文件夹中是否有同名文件
412+
translated_file = os.path.join(file_path, src_filename)
413+
if os.path.exists(translated_file):
414+
source_folder = folder
415+
break
416+
except:
417+
pass
418+
419+
path_to_remove = source_folder if source_folder else file_path
420+
else:
421+
# 单个文件,使用 _find_file_pair 的结果
422+
path_to_remove = source_path if source_path else file_path
423+
424+
# 先在视图中移除(避免重建列表)
395425
self.file_list.remove_file(file_path)
396-
# 然后更新逻辑层的数据(不发射信号)
397-
self.logic.remove_file(file_path, emit_signal=False)
426+
427+
# 再调用app_logic同步数据
428+
self.app_logic.remove_file(path_to_remove)
398429

399430
@pyqtSlot(list)
400431
def update_file_list(self, files: list):

desktop_qt_ui/locales/en_US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,7 @@
354354
"📊 Sequential processing mode: {total} images": "📊 Sequential processing mode: {total} images",
355355
"📥 Importing translations from TXT files to JSON...": "📥 Importing translations from TXT files to JSON...",
356356
"Import result: {result}": "Import result: {result}",
357-
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ Warning: Cannot find template file, skipping auto-import"
357+
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ Warning: Cannot find template file, skipping auto-import",
358+
"Inpaint Only": "Inpaint Only",
359+
"Start Inpainting": "Start Inpainting"
358360
}

desktop_qt_ui/locales/es_ES.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@
212212
"Drag and drop files or folders here\nor click the buttons above to add": "Arrastre y suelte archivos o carpetas aquí\no haga clic en los botones de arriba para agregar",
213213
"Start Translation": "Iniciar traducción",
214214
"Stop Translation": "Detener traducción",
215-
"Export Translation": "Exportar traducción",
216-
"Translation Workflow Mode:": "Modo de flujo de trabajo de traducción:",
215+
"Export Translation": "Exportar Traducción",
216+
"Translation Workflow Mode:": "Modo de Flujo de Traducción:",
217217
"Output Directory:": "Directorio de salida:",
218218
"Log output...": "Salida de registro...",
219-
"Normal Translation": "Traducción normal",
220-
"Export Original Text": "Exportar texto original",
221-
"Import Translation and Render": "Importar traducción y renderizar",
222-
"Colorize Only": "Solo colorear",
223-
"Upscale Only": "Solo ampliar",
219+
"Normal Translation": "Traducción Normal",
220+
"Export Original Text": "Exportar Texto Original",
221+
"Import Translation and Render": "Importar Traducción y Renderizar",
222+
"Colorize Only": "Solo Colorear",
223+
"Upscale Only": "Solo Escalar",
224224
"Start Colorizing": "Iniciar colorización",
225225
"Start Upscaling": "Iniciar ampliación",
226226
"Generate Original Text Template": "Generar plantilla de texto original",
@@ -354,5 +354,7 @@
354354
"📊 Sequential processing mode: {total} images": "📊 Modo de procesamiento secuencial: {total} imágenes",
355355
"📥 Importing translations from TXT files to JSON...": "📥 Importando traducciones de archivos TXT a JSON...",
356356
"Import result: {result}": "Resultado de importación: {result}",
357-
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ Advertencia: No se puede encontrar el archivo de plantilla, omitiendo importación automática"
357+
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ Advertencia: No se puede encontrar el archivo de plantilla, omitiendo importación automática",
358+
"Inpaint Only": "Solo Reparar",
359+
"Start Inpainting": "Iniciar Reparación"
358360
}

desktop_qt_ui/locales/ja_JP.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
"Normal Translation": "通常翻訳",
220220
"Export Original Text": "原文をエクスポート",
221221
"Import Translation and Render": "翻訳をインポートしてレンダリング",
222-
"Colorize Only": "着色のみ",
222+
"Colorize Only": "カラー化のみ",
223223
"Upscale Only": "アップスケールのみ",
224224
"Start Colorizing": "着色を開始",
225225
"Start Upscaling": "アップスケールを開始",
@@ -354,5 +354,7 @@
354354
"📊 Sequential processing mode: {total} images": "📊 順次処理モード:{total}枚の画像",
355355
"📥 Importing translations from TXT files to JSON...": "📥 TXTファイルからJSONに翻訳をインポート中...",
356356
"Import result: {result}": "インポート結果:{result}",
357-
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 警告:テンプレートファイルが見つかりません、自動インポートをスキップします"
357+
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 警告:テンプレートファイルが見つかりません、自動インポートをスキップします",
358+
"Inpaint Only": "修復のみ",
359+
"Start Inpainting": "修復を開始"
358360
}

desktop_qt_ui/locales/ko_KR.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"Start Translation": "번역 시작",
214214
"Stop Translation": "번역 중지",
215215
"Export Translation": "번역 내보내기",
216-
"Translation Workflow Mode:": "번역 워크플로 모드:",
216+
"Translation Workflow Mode:": "번역 워크플로 모드",
217217
"Output Directory:": "출력 디렉토리:",
218218
"Log output...": "로그 출력...",
219219
"Normal Translation": "일반 번역",
@@ -354,5 +354,7 @@
354354
"📊 Sequential processing mode: {total} images": "📊 순차 처리 모드: {total}개 이미지",
355355
"📥 Importing translations from TXT files to JSON...": "📥 TXT 파일에서 JSON으로 번역 가져오는 중...",
356356
"Import result: {result}": "가져오기 결과: {result}",
357-
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 경고: 템플릿 파일을 찾을 수 없어 자동 가져오기를 건너뜁니다"
357+
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 경고: 템플릿 파일을 찾을 수 없어 자동 가져오기를 건너뜁니다",
358+
"Inpaint Only": "복원만",
359+
"Start Inpainting": "복원 시작"
358360
}

desktop_qt_ui/locales/zh_CN.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"Start Translation": "开始翻译",
214214
"Stop Translation": "停止翻译",
215215
"Export Translation": "导出翻译",
216-
"Translation Workflow Mode:": "翻译流程模式:",
216+
"Translation Workflow Mode:": "翻译流程模式",
217217
"Output Directory:": "输出目录:",
218218
"Log output...": "日志输出...",
219219
"Normal Translation": "正常翻译流程",
@@ -354,5 +354,7 @@
354354
"📊 Sequential processing mode: {total} images": "📊 顺序处理模式:共 {total} 张图片",
355355
"📥 Importing translations from TXT files to JSON...": "📥 正在从TXT文件导入翻译到JSON...",
356356
"Import result: {result}": "导入结果:{result}",
357-
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 警告:无法找到模板文件,跳过自动导入翻译"
358-
}
357+
"⚠️ Warning: Cannot find template file, skipping auto-import": "⚠️ 警告:无法找到模板文件,跳过自动导入翻译",
358+
"Inpaint Only": "仅修复",
359+
"Start Inpainting": "开始修复"
360+
}

desktop_qt_ui/locales/zh_TW.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"Select or drag output folder...": "選擇或拖曳輸出資料夾...",
2828
"Browse...": "瀏覽...",
2929
"Open": "開啟",
30-
"Translation Workflow Mode:": "翻譯工作流程模式",
31-
"Normal Translation": "一般翻譯",
30+
"Translation Workflow Mode:": "翻譯流程模式",
31+
"Normal Translation": "正常翻譯流程",
3232
"Export Translation": "匯出翻譯",
3333
"Export Original Text": "匯出原文",
3434
"Import Translation and Render": "匯入翻譯並渲染",
3535
"Colorize Only": "僅上色",
36-
"Upscale Only": "僅放大",
36+
"Upscale Only": "僅超分",
3737
"Start Translation": "開始翻譯",
3838
"Export Config": "匯出設定",
3939
"Import Config": "匯入設定",
@@ -354,5 +354,7 @@
354354
"label_max_font_size": "最大字型大小",
355355
"Mark selected text as horizontal display": "標記選取文字为橫排顯示",
356356
"📥 Importing translations from TXT files to JSON...": "📥 正在从TXT檔案匯入翻譯到JSON...",
357-
"upscale_ratio_not_use": "不使用"
357+
"upscale_ratio_not_use": "不使用",
358+
"Inpaint Only": "僅修復",
359+
"Start Inpainting": "開始修復"
358360
}

0 commit comments

Comments
 (0)