Update dialog_savedgame.py

Update dialog_savedgame.py

Update dialog_savedgame.py

1

Update dialog_savedgame.py
This commit is contained in:
恍兮惚兮 2024-07-24 01:19:02 +08:00
parent 386655c02d
commit e79f9a588d
4 changed files with 133 additions and 39 deletions

View File

@ -1,3 +1,4 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from qtsymbols import * from qtsymbols import *
import os, functools, uuid, threading, hashlib import os, functools, uuid, threading, hashlib
@ -11,6 +12,7 @@ from myutils.config import (
uid2gamepath, uid2gamepath,
_TR, _TR,
postprocessconfig, postprocessconfig,
extradatas,
globalconfig, globalconfig,
static_data, static_data,
) )
@ -26,6 +28,7 @@ from myutils.wrapper import (
from myutils.utils import ( from myutils.utils import (
find_or_create_uid, find_or_create_uid,
str2rgba, str2rgba,
get_time_stamp,
gamdidchangedtask, gamdidchangedtask,
checkpostlangmatch, checkpostlangmatch,
loadpostsettingwindowmethod_private, loadpostsettingwindowmethod_private,
@ -2026,10 +2029,10 @@ class dialog_savedgame_new(QWidget):
exists = os.path.exists(uid2gamepath[self.currentfocusuid]) exists = os.path.exists(uid2gamepath[self.currentfocusuid])
if exists: if exists:
menu.addAction(startgame) menu.addAction(startgame)
menu.addAction(delgame)
if exists: if exists:
menu.addAction(opendir) menu.addAction(opendir)
menu.addAction(gamesetting) menu.addAction(gamesetting)
menu.addAction(delgame)
menu.addSeparator() menu.addSeparator()
menu.addAction(addtolist) menu.addAction(addtolist)
else: else:
@ -2603,6 +2606,7 @@ class fadeoutlabel(QLabel):
effect = QGraphicsOpacityEffect(self) effect = QGraphicsOpacityEffect(self)
self.setGraphicsEffect(effect) self.setGraphicsEffect(effect)
self.setStyleSheet("""background-color: rgba(255,255,255, 0);""")
self.animation = QPropertyAnimation(effect, b"opacity") self.animation = QPropertyAnimation(effect, b"opacity")
self.animation.setDuration(4000) self.animation.setDuration(4000)
self.animation.setStartValue(1.0) self.animation.setStartValue(1.0)
@ -2667,7 +2671,6 @@ def getselectpos(parent, callback):
class previewimages(QWidget): class previewimages(QWidget):
showpixmap = pyqtSignal(QPixmap)
changepixmappath = pyqtSignal(str) changepixmappath = pyqtSignal(str)
removepath = pyqtSignal(str) removepath = pyqtSignal(str)
@ -2716,13 +2719,9 @@ class previewimages(QWidget):
def _visidx(self, _): def _visidx(self, _):
item = self.list.currentItem() item = self.list.currentItem()
if item is None: if item is None:
return self.showpixmap.emit(QPixmap()) return self.changepixmappath.emit(None)
pixmap_ = item.imagepath pixmap_ = item.imagepath
pixmap = QPixmap.fromImage(QImage(pixmap_))
if pixmap is None or pixmap.isNull():
return self.showpixmap.emit(QPixmap())
self.changepixmappath.emit(pixmap_) self.changepixmappath.emit(pixmap_)
self.showpixmap.emit(pixmap)
def removecurrent(self): def removecurrent(self):
idx = self.list.currentRow() idx = self.list.currentRow()
@ -2741,6 +2740,104 @@ class previewimages(QWidget):
return super().resizeEvent(e) return super().resizeEvent(e)
class hoverbtn(QLabel):
clicked = pyqtSignal()
def mousePressEvent(self, a0: QMouseEvent) -> None:
self.clicked.emit()
return super().mousePressEvent(a0)
def __init__(self, p):
super().__init__(p)
style = r"""QLabel{
background: transparent;
border-radius:0;
}
QLabel:hover{
background-color: rgba(255,255,255,0.5);
}"""
self.setStyleSheet(style)
class viewpixmap_x(QWidget):
tolastnext = pyqtSignal(int)
def sizeHint(self):
return QSize(400, 400)
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.pixmapviewer = pixmapviewer(self)
self.leftclick = hoverbtn(self)
self.rightclick = hoverbtn(self)
self.maybehavecomment = hoverbtn(self)
self.leftclick.clicked.connect(lambda: self.tolastnext.emit(-1))
self.rightclick.clicked.connect(lambda: self.tolastnext.emit(1))
self.maybehavecomment.clicked.connect(self.viscomment)
self.commentedit = QPlainTextEdit(self)
self.commentedit.textChanged.connect(self.changecommit)
self.pathandtime = QLabel(self)
self.centerwidget = QWidget(self)
self.centerwidgetlayout = QVBoxLayout()
self.centerwidget.setLayout(self.centerwidgetlayout)
self.centerwidgetlayout.addWidget(self.pathandtime)
self.centerwidgetlayout.addWidget(self.commentedit)
self.centerwidget.setVisible(False)
self.pathview = fadeoutlabel(self)
self.infoview = fadeoutlabel(self)
self.infoview.setAlignment(Qt.AlignmentFlag.AlignRight)
self.currentimage = None
def changecommit(self):
if "imagecomment" not in extradatas:
extradatas["imagecomment"] = {}
extradatas["imagecomment"][self.currentimage] = self.commentedit.toPlainText()
def viscomment(self):
self.centerwidget.setVisible(not self.centerwidget.isVisible())
def resizeEvent(self, e: QResizeEvent):
self.pixmapviewer.resize(e.size())
self.pathview.resize(e.size().width(), self.pathview.height())
self.infoview.resize(e.size().width(), self.infoview.height())
self.leftclick.setGeometry(
0, e.size().height() // 5, e.size().width() // 5, 3 * e.size().height() // 5
)
self.rightclick.setGeometry(
4 * e.size().width() // 5,
e.size().height() // 5,
e.size().width() // 5,
3 * e.size().height() // 5,
)
self.maybehavecomment.setGeometry(
e.size().width() // 5, 0, 3 * e.size().width() // 5, e.size().height() // 5
)
self.centerwidget.setGeometry(
e.size().width() // 5,
e.size().height() // 5,
3 * e.size().width() // 5,
3 * e.size().height() // 5,
)
super().resizeEvent(e)
def changepixmappath(self, path):
self.centerwidget.setVisible(False)
if not path:
return self.pixmapviewer.showpixmap(QPixmap())
pixmap = QPixmap.fromImage(QImage(path))
if pixmap is None or pixmap.isNull():
return self.pixmapviewer.showpixmap(QPixmap())
self.pixmapviewer.showpixmap(pixmap)
self.pathview.setText(path)
self.infoview.setText(get_time_stamp(ct=os.path.getctime(path), ms=False))
self.currentimage = path
self.commentedit.setPlainText(extradatas.get("imagecomment", {}).get(path, ""))
self.pathandtime.setText(
path + "\n" + get_time_stamp(ct=os.path.getctime(path), ms=False)
)
class pixwrapper(QWidget): class pixwrapper(QWidget):
def setrank(self, rank): def setrank(self, rank):
if rank: if rank:
@ -2767,15 +2864,13 @@ class pixwrapper(QWidget):
self.previewimages = previewimages(self) self.previewimages = previewimages(self)
self.vlayout = QVBoxLayout(self) self.vlayout = QVBoxLayout(self)
self.vlayout.setContentsMargins(0, 0, 0, 0) self.vlayout.setContentsMargins(0, 0, 0, 0)
self.pixview = pixmapviewer(self) self.pixview = viewpixmap_x(self)
self.spliter = QSplitter(self) self.spliter = QSplitter(self)
self.vlayout.addWidget(self.spliter) self.vlayout.addWidget(self.spliter)
self.setrank(rank) self.setrank(rank)
self.sethor(hor) self.sethor(hor)
self.pixview.tolastnext.connect(self.previewimages.tolastnext) self.pixview.tolastnext.connect(self.previewimages.tolastnext)
self.setLayout(self.vlayout) self.setLayout(self.vlayout)
self.pathview = fadeoutlabel(self)
self.previewimages.showpixmap.connect(self.pixview.showpixmap)
self.previewimages.changepixmappath.connect(self.changepixmappath) self.previewimages.changepixmappath.connect(self.changepixmappath)
self.previewimages.removepath.connect(self.removepath) self.previewimages.removepath.connect(self.removepath)
self.k = None self.k = None
@ -2835,12 +2930,9 @@ class pixwrapper(QWidget):
lst.pop(lst.index(path)) lst.pop(lst.index(path))
def changepixmappath(self, path): def changepixmappath(self, path):
savehook_new_data[self.k]["currentvisimage"] = path if path:
self.pathview.setText(path) savehook_new_data[self.k]["currentvisimage"] = path
self.pixview.changepixmappath(path)
def resizeEvent(self, e: QResizeEvent):
self.pathview.resize(e.size().width(), self.pathview.height())
super().resizeEvent(e)
def setpix(self, k): def setpix(self, k):
self.k = k self.k = k
@ -2972,12 +3064,17 @@ class dialog_savedgame_v3(QWidget):
exists = os.path.exists(uid2gamepath[self.currentfocusuid]) exists = os.path.exists(uid2gamepath[self.currentfocusuid])
if exists: if exists:
menu.addAction(startgame) menu.addAction(startgame)
menu.addAction(delgame) menu.addAction(delgame)
if exists:
menu.addAction(opendir) menu.addAction(opendir)
menu.addSeparator() menu.addSeparator()
menu.addAction(addtolist) menu.addAction(addtolist)
else:
menu.addAction(addtolist)
menu.addSeparator()
menu.addAction(delgame)
action = menu.exec(QCursor.pos()) action = menu.exec(QCursor.pos())
if action == startgame: if action == startgame:

View File

@ -1864,18 +1864,6 @@ def getsimplepatheditor(
class pixmapviewer(QWidget): class pixmapviewer(QWidget):
tolastnext = pyqtSignal(int) tolastnext = pyqtSignal(int)
def sizeHint(self):
return QSize(400, 400)
def mousePressEvent(self, a0: QMouseEvent) -> None:
if a0.pos().x() < self.width() / 3:
self.tolastnext.emit(-1)
elif a0.pos().x() > self.width() * 2 / 3:
self.tolastnext.emit(1)
else:
pass
return super().mousePressEvent(a0)
def __init__(self, p=None) -> None: def __init__(self, p=None) -> None:
super().__init__(p) super().__init__(p)
self.pix = None self.pix = None

View File

@ -54,6 +54,7 @@ if _savehook:
savehook_new_data = _savehook[1] savehook_new_data = _savehook[1]
savegametaged = _savehook[2] savegametaged = _savehook[2]
# gamepath2uid = _savehook[3] 不再使用允许重复的path # gamepath2uid = _savehook[3] 不再使用允许重复的path
else: else:
_savehook = tryreadconfig("savehook_new_1.39.4.json", default=[[], {}]) _savehook = tryreadconfig("savehook_new_1.39.4.json", default=[[], {}])
@ -72,7 +73,6 @@ else:
savegametaged = _savehook[2] savegametaged = _savehook[2]
except: except:
savegametaged = [None] savegametaged = [None]
# 将savehook_new_data转换为新的格式 # 将savehook_new_data转换为新的格式
__gamepath2uid = {} __gamepath2uid = {}
__savehook_new_data = {} __savehook_new_data = {}
@ -97,6 +97,11 @@ else:
if sub is None: if sub is None:
continue continue
parselist(sub["games"]) parselist(sub["games"])
try:
extradatas = _savehook[4]
except:
extradatas = {}
translatorsetting = tryreadconfig("translatorsetting.json") translatorsetting = tryreadconfig("translatorsetting.json")
ocrsetting = tryreadconfig("ocrsetting.json") ocrsetting = tryreadconfig("ocrsetting.json")
@ -483,7 +488,7 @@ def saveallconfig():
safesave("./userconfig/ocrsetting.json", ocrsetting) safesave("./userconfig/ocrsetting.json", ocrsetting)
safesave( safesave(
"./userconfig/savegamedata_5.3.1.json", "./userconfig/savegamedata_5.3.1.json",
[savehook_new_list, savehook_new_data, savegametaged, None], [savehook_new_list, savehook_new_data, savegametaged, None, extradatas],
beatiful=False, beatiful=False,
) )
safesave( safesave(

View File

@ -625,13 +625,17 @@ def str2rgba(string, alpha100):
) )
def get_time_stamp(): def get_time_stamp(ct=None, ms=True):
ct = time.time() if ct is None:
ct = time.time()
local_time = time.localtime(ct) local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time) data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - int(ct)) * 1000 if ms:
time_stamp = "%s.%03d" % (data_head, data_secs) data_secs = (ct - int(ct)) * 1000
return time_stamp time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp
else:
return data_head
class LRUCache: class LRUCache: