Skip to content

Commit

Permalink
修改保存图片
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Jul 22, 2023
1 parent 794cb43 commit 6361f8c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/tools/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class Str:
SupportDrop = 148 # 支持拖拽文件导入
AlreadyHave = 149 # 已存在
SameWight = 150 # 等宽模式

CopyFileLast = 151 # 保存上次路径

@classmethod
def Reload(cls):
cls.obj = QtStrObj()
Expand Down Expand Up @@ -434,6 +435,7 @@ def Reload(cls):
cls.strDict[cls.Copy] = QCoreApplication.translate("cls.obj", "复制", None)
cls.strDict[cls.CopyPicture] = QCoreApplication.translate("cls.obj", "复制图片到剪贴板", None)
cls.strDict[cls.CopyFile] = QCoreApplication.translate("cls.obj", "保存文件", None)
cls.strDict[cls.CopyFileLast] = QCoreApplication.translate("cls.obj", "保存上次路径", None)
cls.strDict[cls.MainUi] = QCoreApplication.translate("cls.obj", "主界面", None)
cls.strDict[cls.ShowMin] = QCoreApplication.translate("cls.obj", "最小化", None)
cls.strDict[cls.DownloadAll] = QCoreApplication.translate("cls.obj", "批量下载", None)
Expand Down
6 changes: 6 additions & 0 deletions src/view/read/read_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ def eventFilter(self, obj, ev) -> bool:
self.qtTool.FullScreen()
elif ev.key() == Qt.Key_F2:
self.qtTool.curWaifu2x.click()
elif ev.key() == Qt.Key_F4:
self.readImg.CopyLastFile()
elif ev.key() == Qt.Key_F3:
self.readImg.CopyFile()
elif ev.key() == Qt.Key_F1:
self.readImg.CopyPicture()
elif ev.key() == Qt.Key_F12:
self.readImg.ShowAndCloseTool()
elif ev.key() == Qt.Key_Space:
Expand Down
65 changes: 54 additions & 11 deletions src/view/read/read_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self):
self.isOffline = False
self.isLocal = False
self.cacheBook = None
self.lastPath = ""
# QtOwner().owner.WindowsSizeChange.connect(self.qtTool.ClearQImage)

@property
Expand Down Expand Up @@ -143,11 +144,15 @@ def AddScaleMode(name, value):
action.triggered.connect(self.qtTool.OpenNextEps)

menu4 = popMenu.addMenu(Str.GetStr(Str.Copy))
action = menu4.addAction(Str.GetStr(Str.CopyPicture))
action = menu4.addAction(Str.GetStr(Str.CopyPicture) + "(F1)")
action.triggered.connect(self.CopyPicture)
action = menu4.addAction(Str.GetStr(Str.CopyFile))

action = menu4.addAction(Str.GetStr(Str.CopyFile) + "(F3)")
action.triggered.connect(self.CopyFile)

action = menu4.addAction(Str.GetStr(Str.CopyFileLast) + "(F4)")
action.triggered.connect(self.CopyLastFile)

action = popMenu.addAction(Str.GetStr(Str.AutoScroll)+"(F5)")
action.triggered.connect(self.qtTool.SwitchScrollAndTurn)

Expand Down Expand Up @@ -862,29 +867,67 @@ def CopyFile(self):
if not info.data and not info.waifuData:
return

today = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
# today = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
if info.waifuData:
path = "{}_waifu2x.jpg".format(today)
path = "{}_{}_waifu2x.jpg".format(self.bookId, self.curIndex+1)
data = info.waifuData
else:
path = "{}.jpg".format(today)
if not (self.isLocal or self.isOffline) and info.saveParams:
epsId, scrambleId, pitureName = info.saveParams
data = ToolUtil.SegmentationPicture(info.data, epsId, scrambleId, pitureName)
else:
data = info.data
path = "{}_{}.jpg".format(self.bookId, self.curIndex+1)
data = info.data
if not data:
return
try:
if self.lastPath:
path = os.path.join(self.lastPath, path)
filepath = QFileDialog.getSaveFileName(self, Str.GetStr(Str.Save), path, "Image Files(*.jpg *.png)")
if filepath and len(filepath) >= 1:
name = filepath[0]
if not name:
return
self.lastPath = os.path.dirname(name)
f = open(name, "wb")
f.write(data)
f.close()
QtOwner().ShowMsg(Str.GetStr(Str.CopySuc))
QtOwner().ShowMsg(Str.GetStr(Str.SaveSuc))
except Exception as es:
Log.Error(es)

def CopyLastFile(self):
info = self.pictureData.get(self.curIndex)
if not info:
return
assert isinstance(info, QtFileData)
if not info.data and not info.waifuData:
return

if info.waifuData:
path = "{}_{}_waifu2x.jpg".format(self.bookId, self.curIndex+1)
data = info.waifuData
else:
path = "{}_{}.jpg".format(self.bookId, self.curIndex+1)
data = info.data
if not data:
return
try:
if self.lastPath:
name = os.path.join(self.lastPath, path)
else:
if self.lastPath:
path = os.path.join(self.lastPath, path)
filepath = QFileDialog.getSaveFileName(self, Str.GetStr(Str.Save), path, "Image Files(*.jpg *.png)")
if filepath and len(filepath) >= 1:
name = filepath[0]
if not name:
return
self.lastPath = os.path.dirname(name)
else:
return

# self.lastPath = os.path.dirname(name)
f = open(name, "wb")
f.write(data)
f.close()
QtOwner().ShowMsg(Str.GetStr(Str.SaveSuc))
except Exception as es:
Log.Error(es)

Expand Down

0 comments on commit 6361f8c

Please sign in to comment.