This commit is contained in:
恍兮惚兮 2024-07-23 23:23:17 +08:00
parent 6606491cb1
commit a38578e027
7 changed files with 249 additions and 183 deletions

View File

@ -40,7 +40,7 @@ from gui.edittext import edittext
import importlib, qtawesome import importlib, qtawesome
from functools import partial from functools import partial
from gui.setting import Setting from gui.setting import Setting
from gui.showocrimage import showocrimage from gui.setting_textinput_ocr import showocrimage
from gui.attachprocessdialog import AttachProcessDialog from gui.attachprocessdialog import AttachProcessDialog
import windows import windows
import gobject import gobject

View File

@ -1,3 +1,4 @@
from PyQt5.QtWidgets import QWidget
from qtsymbols import * from qtsymbols import *
import os, functools, uuid, threading, hashlib import os, functools, uuid, threading, hashlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -50,6 +51,7 @@ from gui.specialwidget import (
) )
from gui.usefulwidget import ( from gui.usefulwidget import (
yuitsu_switch, yuitsu_switch,
pixmapviewer,
FocusCombo, FocusCombo,
TableViewW, TableViewW,
saveposwindow, saveposwindow,
@ -1731,33 +1733,37 @@ def __scaletosize(_pix: QPixmap, tgt):
_pix.save(tgt) _pix.save(tgt)
def _getcachedimage(src, small):
if not small:
_pix = QPixmap(src)
if _pix.isNull():
return None
return _pix
src2 = gobject.getcachedir(f"icon2/{__b64string(src)}.jpg")
_pix = QPixmap(src2)
if not _pix.isNull():
return _pix
_pix = QPixmap(src)
if _pix.isNull():
return None
__scaletosize(_pix, src2)
return _pix
def _getpixfunction(kk, small=False): def _getpixfunction(kk, small=False):
if ( if (
savehook_new_data[kk]["currentmainimage"] savehook_new_data[kk]["currentmainimage"]
in savehook_new_data[kk]["imagepath_all"] in savehook_new_data[kk]["imagepath_all"]
): ):
src = savehook_new_data[kk]["currentmainimage"] src = savehook_new_data[kk]["currentmainimage"]
if small: pix = _getcachedimage(src, small)
src2 = gobject.getcachedir(f"icon2/{__b64string(src)}.jpg") if pix:
_pix = QPixmap(src2) return pix
if _pix and not _pix.isNull():
return _pix
_pix = QPixmap(src)
if _pix and not _pix.isNull():
if small:
__scaletosize(_pix, src2)
return _pix
for _ in savehook_new_data[kk]["imagepath_all"]: for _ in savehook_new_data[kk]["imagepath_all"]:
if small: pix = _getcachedimage(_, small)
src2 = gobject.getcachedir(f"icon2/{__b64string(_)}.jpg") if pix:
_pix = QPixmap(src2) return pix
if _pix and not _pix.isNull():
return _pix
_pix = QPixmap(_)
if _pix and not _pix.isNull():
if small:
__scaletosize(_pix, src2)
return _pix
_pix = getExeIcon(uid2gamepath[kk], False, cache=True) _pix = getExeIcon(uid2gamepath[kk], False, cache=True)
return _pix return _pix
@ -2608,91 +2614,130 @@ class fadeoutlabel(QLabel):
self.animation.start() self.animation.start()
class XQListWidget(QListWidget):
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.setFlow(QListWidget.LeftToRight)
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel)
class previewimages(QWidget):
showpixmap = pyqtSignal(QPixmap)
changepixmappath = pyqtSignal(str)
removepath = pyqtSignal(str)
def sizeHint(self):
return QSize(100, 100)
def __init__(self, p) -> None:
super().__init__(p)
self.lay = QHBoxLayout()
self.lay.setContentsMargins(0, 0, 0, 0)
self.list = XQListWidget(self)
self.list.currentRowChanged.connect(self._visidx)
self.lay.addWidget(self.list)
self.setLayout(self.lay)
self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.customContextMenuRequested.connect(self.menu)
def menu(self, _):
menu = QMenu(self)
deleteimage = LAction(("删除图片"))
menu.addAction(deleteimage)
action = menu.exec(QCursor.pos())
if action == deleteimage:
self.removecurrent()
def tolastnext(self, dx):
if self.list.count() == 0:
return self.list.setCurrentRow(-1)
self.list.setCurrentRow((self.list.currentRow() + dx) % self.list.count())
def setpixmaps(self, paths, currentpath):
self.list.setCurrentRow(-1)
pixmapi = 0
if currentpath in paths:
pixmapi = paths.index(currentpath)
self.list.blockSignals(True)
self.list.clear()
for path in paths:
item = QListWidgetItem()
item.imagepath = path
item.setIcon(QIcon(_getcachedimage(path, True)))
self.list.addItem(item)
self.list.blockSignals(False)
self.list.setCurrentRow(pixmapi)
def _visidx(self, _):
item = self.list.currentItem()
if item is None:
return self.showpixmap.emit(QPixmap())
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.showpixmap.emit(pixmap)
def removecurrent(self):
idx = self.list.currentRow()
item = self.list.currentItem()
if item is None:
return
path = item.imagepath
self.removepath.emit(path)
self.list.takeItem(idx)
def resizeEvent(self, e: QResizeEvent):
self.list.setIconSize(QSize(self.height(), self.height()))
return super().resizeEvent(e)
class pixwrapper(QWidget): class pixwrapper(QWidget):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self.pixview = QLabel(self) self.previewimages = previewimages(self)
self.vlayout = QVBoxLayout(self)
self.vlayout.setContentsMargins(0, 0, 0, 0)
self.pixview = pixmapviewer(self)
self.spliter = QSplitter(self)
self.spliter.setOrientation(Qt.Orientation.Vertical)
self.vlayout.addWidget(self.spliter)
self.spliter.addWidget(self.pixview)
self.pixview.tolastnext.connect(self.previewimages.tolastnext)
self.spliter.addWidget(self.previewimages)
self.setLayout(self.vlayout)
self.pathview = fadeoutlabel(self) self.pathview = fadeoutlabel(self)
self.pixmaps = [] self.previewimages.showpixmap.connect(self.pixview.showpixmap)
self.rflist = [] self.previewimages.changepixmappath.connect(self.changepixmappath)
self.iternalpixmaps = [] self.previewimages.removepath.connect(self.removepath)
self.k = None self.k = None
self.pixmapi = 0 self.removecurrent = self.previewimages.removecurrent
self.pixview.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.current = None
def tolastnext(self, dx): def removepath(self, path):
if len(self.pixmaps) == 0: lst = savehook_new_data[self.k]["imagepath_all"]
return lst.pop(lst.index(path))
self.pixmapi = (self.pixmapi + dx) % len(self.pixmaps) def changepixmappath(self, path):
self.visidx() savehook_new_data[self.k]["currentvisimage"] = path
self.pathview.setText(path)
def mousePressEvent(self, a0: QMouseEvent) -> None: def setpixmenu(self, function):
if a0.pos().x() < self.width() / 3: self.pixview.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.tolastnext(-1) self.pixview.customContextMenuRequested.connect(function)
elif a0.pos().x() > self.width() * 2 / 3:
self.tolastnext(1)
else:
pass
return super().mousePressEvent(a0)
def resizeEvent(self, e: QResizeEvent): def resizeEvent(self, e: QResizeEvent):
self.pixview.resize(e.size().width(), e.size().height())
self.pathview.resize(e.size().width(), self.pathview.height()) self.pathview.resize(e.size().width(), self.pathview.height())
if self.current is None: super().resizeEvent(e)
self.visidx()
else:
self.scalepix(self.current)
def visidx(self):
if len(self.pixmaps) == 0:
if not self.k:
return
pixmap = getExeIcon(uid2gamepath[self.k], False, cache=True)
pixmap_ = None
else:
self.pixmapi = min(len(self.pixmaps) - 1, self.pixmapi)
pixmap_ = self.pixmaps[self.pixmapi]
pixmap = QPixmap.fromImage(QImage(pixmap_))
if pixmap is None or pixmap.isNull():
self.pixmaps.pop(self.pixmapi)
return self.visidx()
self.pathview.setText(pixmap_)
savehook_new_data[self.k]["currentvisimage"] = pixmap_
pixmap.setDevicePixelRatio(self.devicePixelRatioF())
self.current = pixmap
self.scalepix(pixmap)
def removecurrent(self):
if self.pixmapi < len(self.pixmaps):
path = self.pixmaps[self.pixmapi]
self.rflist.pop(self.rflist.index(path))
self.pixmaps.pop(self.pixmapi)
if self.pixmapi < len(self.pixmaps):
pass
else:
self.pixmapi -= 1
self.visidx()
def setpix(self, k): def setpix(self, k):
self.k = k self.k = k
self.pixmaps = savehook_new_data[k]["imagepath_all"].copy() pixmaps = savehook_new_data[k]["imagepath_all"].copy()
self.rflist = savehook_new_data[k]["imagepath_all"] self.previewimages.setpixmaps(pixmaps, savehook_new_data[k]["currentvisimage"])
self.pixmapi = 0
if savehook_new_data[k]["currentvisimage"] in self.pixmaps:
self.pixmapi = self.pixmaps.index(savehook_new_data[k]["currentvisimage"])
self.visidx()
def scalepix(self, pix: QPixmap):
pix = pix.scaled(
self.pixview.size() * self.devicePixelRatioF(),
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
self.pixview.setPixmap(pix)
def loadvisinternal(skipid=False, skipidid=None): def loadvisinternal(skipid=False, skipidid=None):
@ -2937,10 +2982,7 @@ class dialog_savedgame_v3(QWidget):
self.righttop.addTab(_w, "画廊") self.righttop.addTab(_w, "画廊")
lay.addWidget(self.righttop) lay.addWidget(self.righttop)
rightlay.addWidget(self.pixview) rightlay.addWidget(self.pixview)
self.pixview.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.pixview.setpixmenu(functools.partial(self.stack_showmenu, True))
self.pixview.customContextMenuRequested.connect(
functools.partial(self.stack_showmenu, True)
)
self.buttonlayout = QHBoxLayout() self.buttonlayout = QHBoxLayout()
self.savebutton = [] self.savebutton = []
rightlay.addLayout(self.buttonlayout) rightlay.addLayout(self.buttonlayout)

View File

@ -1,6 +1,5 @@
from qtsymbols import * from qtsymbols import *
import functools, os import functools, os
import gobject
from myutils.config import globalconfig, ocrsetting, ocrerrorfix from myutils.config import globalconfig, ocrsetting, ocrerrorfix
from myutils.utils import splitocrtypes, dynamiclink from myutils.utils import splitocrtypes, dynamiclink
from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items from gui.inputdialog import autoinitdialog, postconfigdialog, autoinitdialog_items
@ -12,8 +11,62 @@ from gui.usefulwidget import (
D_getcolorbutton, D_getcolorbutton,
D_getsimpleswitch, D_getsimpleswitch,
selectcolor, selectcolor,
saveposwindow,
pixmapviewer,
) )
from gui.dynalang import LPushButton from gui.dynalang import LPushButton
import qtawesome, gobject
from myutils.ocrutil import imagesolve
from myutils.wrapper import Singleton_close
@Singleton_close
class showocrimage(saveposwindow):
setimage = pyqtSignal(list)
def closeEvent(self, e):
gobject.baseobject.showocrimage = None
super().closeEvent(e)
def __init__(self, parent, cached):
self.img1 = None
self.originimage = None
super().__init__(parent, poslist=globalconfig["showocrgeo"])
self.setWindowIcon(qtawesome.icon("fa.picture-o"))
self.setWindowTitle("查看处理效果")
self.originlabel = pixmapviewer()
qw = QWidget()
self.solvedlabel = pixmapviewer()
self.lay2 = QHBoxLayout()
button = QPushButton(
icon=qtawesome.icon("fa.rotate-right", color=globalconfig["buttoncolor"])
)
button.clicked.connect(self.retest)
self.layout1 = QVBoxLayout()
# self.lay2.addWidget(button)
self.lay2.addLayout(self.layout1)
self.setCentralWidget(qw)
qw.setLayout(self.lay2)
self.layout1.addWidget(self.originlabel)
self.layout1.addWidget(button)
self.layout1.addWidget(self.solvedlabel)
self.setimage.connect(self.setimagefunction)
if cached:
self.setimagefunction(cached)
def retest(self):
if self.originimage is None:
return
img = imagesolve(self.originimage)
self.setimagefunction([self.originimage, img])
def setimagefunction(self, image):
originimage, solved = image
self.originimage = originimage
self.img1 = QPixmap.fromImage(originimage)
self.img2 = QPixmap.fromImage(solved)
self.originlabel.showpixmap(self.img1)
self.solvedlabel.showpixmap(self.img2)
def __label1(self): def __label1(self):

View File

@ -1,84 +0,0 @@
from qtsymbols import *
import qtawesome, gobject
from myutils.ocrutil import imagesolve
from myutils.config import globalconfig
from myutils.wrapper import Singleton_close
from gui.usefulwidget import saveposwindow
class pixlabel(QLabel):
def __init__(self):
super().__init__()
self.pix = None
def paintEvent(self, a0) -> None:
if self.pix:
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.drawPixmap(
0,
0,
self.pix.scaled(
self.size() * self.devicePixelRatioF(),
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
),
)
return super().paintEvent(a0)
def setpix(self, pix):
pix.setDevicePixelRatio(self.devicePixelRatioF())
self.pix = pix
self.update()
@Singleton_close
class showocrimage(saveposwindow):
setimage = pyqtSignal(list)
def closeEvent(self, e):
gobject.baseobject.showocrimage = None
super().closeEvent(e)
def __init__(self, parent, cached):
self.img1 = None
self.originimage = None
super().__init__(parent, poslist=globalconfig["showocrgeo"])
self.setWindowIcon(qtawesome.icon("fa.picture-o"))
self.setWindowTitle("查看处理效果")
self.originlabel = pixlabel()
qw = QWidget()
self.solvedlabel = pixlabel()
self.lay2 = QHBoxLayout()
button = QPushButton(
icon=qtawesome.icon("fa.rotate-right", color=globalconfig["buttoncolor"])
)
button.clicked.connect(self.retest)
self.layout1 = QVBoxLayout()
# self.lay2.addWidget(button)
self.lay2.addLayout(self.layout1)
self.setCentralWidget(qw)
qw.setLayout(self.lay2)
self.layout1.addWidget(self.originlabel)
self.layout1.addWidget(button)
self.layout1.addWidget(self.solvedlabel)
self.setimage.connect(self.setimagefunction)
if cached:
self.setimagefunction(cached)
def retest(self):
if self.originimage is None:
return
img = imagesolve(self.originimage)
self.setimagefunction([self.originimage, img])
def setimagefunction(self, image):
originimage, solved = image
self.originimage = originimage
self.img1 = QPixmap.fromImage(originimage)
self.img2 = QPixmap.fromImage(solved)
self.originlabel.setpix(self.img1)
self.solvedlabel.setpix(self.img2)

View File

@ -1859,3 +1859,57 @@ def getsimplepatheditor(
lay.addWidget(e) lay.addWidget(e)
lay.addWidget(bu) lay.addWidget(bu)
return lay return lay
class pixmapviewer(QWidget):
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:
super().__init__(p)
self.pix = None
self._pix = None
def showpixmap(self, pix: QPixmap):
pix.setDevicePixelRatio(self.devicePixelRatioF())
self.pix = pix
self._pix = None
self.update()
def paintEvent(self, e):
if self.pix:
if self._pix:
if self._pix.size() != self.size() * self.devicePixelRatioF():
self._pix = None
if not self._pix:
rate = self.devicePixelRatioF()
self._pix = QPixmap(self.size() * rate)
self._pix.setDevicePixelRatio(rate)
self._pix.fill(Qt.GlobalColor.transparent)
if not self.pix.isNull():
painter = QPainter(self._pix)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
pix = self.pix.scaled(
self.size() * self.devicePixelRatioF(),
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
x = self.width() / 2 - pix.width() / 2 / self.devicePixelRatioF()
y = self.height() / 2 - pix.height() / 2 / self.devicePixelRatioF()
painter.drawPixmap(int(x), int(y), pix)
painter = QPainter(self)
painter.drawPixmap(0, 0, self._pix)
return super().paintEvent(e)

View File

@ -201,7 +201,8 @@ class searcher(common):
developers = [] developers = []
for _ in response["infobox"]: for _ in response["infobox"]:
if _["key"] in ["游戏开发商", "开发", "发行"]: if _["key"] in ["游戏开发商", "开发", "发行"]:
developers += [_["value"]] for __ in _["value"]:
developers.append(__['v'])
return { return {
# "namemap": namemap, # "namemap": namemap,
"title": response["name"], "title": response["name"],

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 15) set(VERSION_MINOR 15)
set(VERSION_PATCH 5) set(VERSION_PATCH 6)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)