This commit is contained in:
恍兮惚兮 2024-04-13 16:41:31 +08:00
parent cb3cdf1ce3
commit a5d7a92fd8
2 changed files with 49 additions and 27 deletions

View File

@ -21,7 +21,7 @@ from PyQt5.QtWidgets import (
QTabWidget, QTabWidget,
) )
import windows import windows
from PyQt5.QtCore import QRect, QSize, Qt, pyqtSignal from PyQt5.QtCore import QRect, QSize, Qt, pyqtSignal, QObject
import os, hashlib import os, hashlib
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QApplication,
@ -34,13 +34,12 @@ from PyQt5.QtWidgets import (
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QCloseEvent, QCloseEvent,
QIntValidator, QIntValidator,
QMouseEvent,
QResizeEvent, QResizeEvent,
QPixmap, QPixmap,
QPainter, QPainter,
QPen, QPen,
) )
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, QPoint
from gui.usefulwidget import ( from gui.usefulwidget import (
getsimplecombobox, getsimplecombobox,
getspinbox, getspinbox,
@ -430,7 +429,19 @@ def getvndbrealtags(vndbtags_naive):
return vndbtags return vndbtags
@Singleton _global_dialog_savedgame_new = None
_global_dialog_setting_game = None
def calculate_centered_rect(original_rect: QRect, size: QSize) -> QRect:
original_center = original_rect.center()
new_left = original_center.x() - size.width() // 2
new_top = original_center.y() - size.height() // 2
new_rect = QRect(new_left, new_top, size.width(), size.height())
return new_rect
@Singleton_close
class dialog_setting_game(QDialog): class dialog_setting_game(QDialog):
def selectexe(self): def selectexe(self):
f = QFileDialog.getOpenFileName(directory=self.exepath) f = QFileDialog.getOpenFileName(directory=self.exepath)
@ -452,10 +463,6 @@ class dialog_setting_game(QDialog):
"", "", functools.partial(opendir, res), qicon=_icon "", "", functools.partial(opendir, res), qicon=_icon
), ),
) )
if self.gametitleitme:
if savehook_new_data[res]["imagepath"] is None:
self.gametitleitme.setimg(getExeIcon(res, False, cache=True))
self.gametitleitme.connectexepath(res)
self.setWindowIcon(_icon) self.setWindowIcon(_icon)
self.editpath.setText(res) self.editpath.setText(res)
@ -465,10 +472,13 @@ class dialog_setting_game(QDialog):
self.isopened = False self.isopened = False
return super().closeEvent(a0) return super().closeEvent(a0)
def __init__(self, parent, exepath, item=None, gametitleitme=None) -> None: def __init__(self, parent, exepath, item=None) -> None:
super().__init__(parent, Qt.WindowCloseButtonHint) super().__init__(parent, Qt.WindowCloseButtonHint)
global _global_dialog_setting_game
_global_dialog_setting_game = self
self.isopened = True self.isopened = True
checkifnewgame(exepath) checkifnewgame(exepath)
print(item)
vbox = QVBoxLayout(self) # 配置layout vbox = QVBoxLayout(self) # 配置layout
self.setLayout(vbox) self.setLayout(vbox)
formwidget = QWidget() formwidget = QWidget()
@ -476,16 +486,10 @@ class dialog_setting_game(QDialog):
formwidget.setLayout(formLayout) formwidget.setLayout(formLayout)
self.item = item self.item = item
self.exepath = exepath self.exepath = exepath
self.gametitleitme = gametitleitme
editpath = QLineEdit(exepath) editpath = QLineEdit(exepath)
editpath.setReadOnly(True) editpath.setReadOnly(True)
if item:
self.table = parent.table
self.model = parent.model
editpath.textEdited.connect(lambda _: item.__setitem__("savetext", _))
self.editpath = editpath
self.setWindowTitle(savehook_new_data[exepath]["title"]) self.setWindowTitle(savehook_new_data[exepath]["title"])
self.resize(QSize(600, 200))
self.setWindowIcon(getExeIcon(exepath, cache=True)) self.setWindowIcon(getExeIcon(exepath, cache=True))
formLayout.addRow( formLayout.addRow(
_TR("路径"), _TR("路径"),
@ -509,7 +513,6 @@ class dialog_setting_game(QDialog):
savehook_new_data[exepath]["istitlesetted"] = True savehook_new_data[exepath]["istitlesetted"] = True
savehook_new_data[exepath]["searchnoresulttime"] = 0 savehook_new_data[exepath]["searchnoresulttime"] = 0
self.setWindowTitle(x) self.setWindowTitle(x)
gametitleitme.settitle(x)
titleedit.textChanged.connect(_titlechange) titleedit.textChanged.connect(_titlechange)
formLayout.addRow(_TR("标题"), titleedit) formLayout.addRow(_TR("标题"), titleedit)
@ -529,7 +532,6 @@ class dialog_setting_game(QDialog):
savehook_new_data[exepath]["imagepath"] = res savehook_new_data[exepath]["imagepath"] = res
savehook_new_data[exepath]["isimagepathusersetted"] = True savehook_new_data[exepath]["isimagepathusersetted"] = True
imgpath.setText(res) imgpath.setText(res)
gametitleitme.setimg(_pixmap)
vndbid = QLineEdit(str(savehook_new_data[exepath]["vid"])) vndbid = QLineEdit(str(savehook_new_data[exepath]["vid"]))
vndbid.setValidator(QIntValidator()) vndbid.setValidator(QIntValidator())
@ -597,6 +599,17 @@ class dialog_setting_game(QDialog):
vbox.addWidget(methodtab) vbox.addWidget(methodtab)
self.show() self.show()
self.resize(QSize(600, 1))
self.adjustSize()
self.resize(QSize(600, self.height()))
try:
self.setGeometry(
calculate_centered_rect(
_global_dialog_savedgame_new.geometry(), self.size()
)
)
except:
pass
def selectbackupdir(self, edit): def selectbackupdir(self, edit):
res = QFileDialog.getExistingDirectory( res = QFileDialog.getExistingDirectory(
@ -838,7 +851,7 @@ class dialog_setting_game(QDialog):
def _lbclick(tp, t): def _lbclick(tp, t):
try: try:
self.parent().tagswidget.addTag(t, tp) _global_dialog_savedgame_new.tagswidget.addTag(t, tp)
except: except:
pass pass
@ -1573,6 +1586,8 @@ class dialog_savedgame_new(saveposwindow):
dic=globalconfig, dic=globalconfig,
key="savegamedialoggeo", key="savegamedialoggeo",
) )
global _global_dialog_savedgame_new
_global_dialog_savedgame_new = self
self.setWindowTitle(_TR("已保存游戏")) self.setWindowTitle(_TR("已保存游戏"))
if globalconfig["showintab_sub"]: if globalconfig["showintab_sub"]:
showintab(int(self.winId()), True) showintab(int(self.winId()), True)
@ -1612,15 +1627,22 @@ class dialog_savedgame_new(saveposwindow):
else: else:
self.tagschanged(tuple()) self.tagschanged(tuple())
class WindowEventFilter(QObject):
def eventFilter(__, obj, event):
try:
if obj == self:
global _global_dialog_setting_game
_global_dialog_setting_game.raise_()
except:
pass
return False
self.__filter = WindowEventFilter() # keep ref
self.installEventFilter(self.__filter)
def showsettingdialog(self): def showsettingdialog(self):
idx = self.idxsave.index(self.currentfocuspath)
try: try:
dialog_setting_game( dialog_setting_game(self.parent(), self.currentfocuspath)
self,
self.currentfocuspath,
None,
gametitleitme=self.flow.widget(idx),
)
except: except:
print_exc() print_exc()

View File

@ -757,7 +757,7 @@ class hookselect(closeashidewindow):
def opengamesetting(self): def opengamesetting(self):
try: try:
dialog_setting_game(self, gobject.baseobject.textsource.pname, None) dialog_setting_game(self, gobject.baseobject.textsource.pname)
except: except:
print_exc() print_exc()