Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
柴进
/
GoogleNanoBananaApp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
cf1cdc86
authored
2026-02-28 11:41:32 +0800
by
柴进
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
处理mac打包后粘贴图片缩略图不可见的问题,处理历史history不可见问题
1 parent
68235b13
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
3 deletions
image_generator.py
image_generator.py
View file @
cf1cdc8
...
...
@@ -511,6 +511,22 @@ class HistoryManager:
return
timestamp
def
_fix_history_path
(
self
,
stored_path
:
Path
,
timestamp
:
str
)
->
Path
:
"""修正历史记录中的路径,使其指向当前 base_path
存储迁移后,index 里的绝对路径可能指向旧位置(如 .app 内部),
而实际文件已在新的 base_path 下。用 timestamp + 文件名重建路径。
"""
if
stored_path
.
exists
():
return
stored_path
# 尝试在当前 base_path 下找到对应文件
corrected
=
self
.
base_path
/
timestamp
/
stored_path
.
name
if
corrected
.
exists
():
return
corrected
return
stored_path
def
load_history_index
(
self
)
->
List
[
HistoryItem
]:
"""加载历史记录索引
...
...
@@ -525,6 +541,28 @@ class HistoryManager:
data
=
json
.
load
(
f
)
history_items
=
[
HistoryItem
.
from_dict
(
item
)
for
item
in
data
]
# 修正可能过期的绝对路径(存储迁移后旧路径不再有效)
needs_save
=
False
for
item
in
history_items
:
fixed_gen
=
self
.
_fix_history_path
(
item
.
generated_image_path
,
item
.
timestamp
)
if
fixed_gen
!=
item
.
generated_image_path
:
item
.
generated_image_path
=
fixed_gen
needs_save
=
True
fixed_refs
=
[]
for
ref_path
in
item
.
reference_image_paths
:
fixed_ref
=
self
.
_fix_history_path
(
ref_path
,
item
.
timestamp
)
if
fixed_ref
!=
ref_path
:
needs_save
=
True
fixed_refs
.
append
(
fixed_ref
)
item
.
reference_image_paths
=
fixed_refs
# 路径修正后持久化,避免每次都修正
if
needs_save
:
self
.
logger
.
info
(
"检测到历史记录路径变更,已自动修正"
)
self
.
_save_history_index
(
history_items
)
# 按时间戳倒序排列
history_items
.
sort
(
key
=
lambda
x
:
x
.
timestamp
,
reverse
=
True
)
return
history_items
...
...
@@ -2093,11 +2131,13 @@ class ImageGeneratorWindow(QMainWindow):
"""Update image preview thumbnails"""
self
.
logger
.
info
(
f
"更新图片预览,共 {len(self.uploaded_images)} 张图片"
)
try
:
# Clear existing previews
# Clear existing previews
- 立即删除而非 deleteLater,避免布局刷新时序问题
while
self
.
img_layout
.
count
()
>
1
:
# Keep the stretch
item
=
self
.
img_layout
.
takeAt
(
0
)
if
item
.
widget
():
item
.
widget
()
.
deleteLater
()
widget
=
item
.
widget
()
if
widget
:
widget
.
setParent
(
None
)
widget
.
deleteLater
()
# Add thumbnails
for
idx
,
file_path
in
enumerate
(
self
.
uploaded_images
):
...
...
@@ -2157,6 +2197,10 @@ class ImageGeneratorWindow(QMainWindow):
except
Exception
as
e
:
self
.
logger
.
error
(
f
"创建缩略图失败: {file_path}, 错误: {str(e)}"
,
exc_info
=
True
)
# 强制刷新布局和滚动区域(macOS 打包环境下可能需要)
self
.
img_container
.
adjustSize
()
self
.
img_scroll
.
update
()
except
Exception
as
e
:
self
.
logger
.
error
(
f
"更新图片预览失败: {str(e)}"
,
exc_info
=
True
)
...
...
Please
register
or
sign in
to post a comment