From beb189b5901d5b6435bccbccb0f15e0571fd1bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:48:11 +0800 Subject: [PATCH] fix --- .../LunaTranslator/gui/dialog_savedgame.py | 4 ++-- LunaTranslator/LunaTranslator/myutils/hwnd.py | 15 +-------------- LunaTranslator/LunaTranslator/myutils/utils.py | 8 +++++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index a835663b..f42ab501 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -44,7 +44,7 @@ from gui.usefulwidget import ( ) from PyQt5.QtCore import QPoint, QRect, QSize, Qt, pyqtSignal import os -from myutils.hwnd import showintab, getScreenRate +from myutils.hwnd import showintab from PyQt5.QtGui import QStandardItem, QStandardItemModel from PyQt5.QtCore import Qt, QSize from myutils.config import savehook_new_list, savehook_new_data @@ -363,7 +363,7 @@ class browserdialog(QDialog): if self._resizable == False: return self.nettab.resize(a0.size().width(), self.nettab.height()) - rate = getScreenRate() + rate = QApplication.instance().devicePixelRatio() rect = ( 0, int(rate * self.nettab.height()), diff --git a/LunaTranslator/LunaTranslator/myutils/hwnd.py b/LunaTranslator/LunaTranslator/myutils/hwnd.py index 6390e74d..9ccd89cd 100644 --- a/LunaTranslator/LunaTranslator/myutils/hwnd.py +++ b/LunaTranslator/LunaTranslator/myutils/hwnd.py @@ -103,7 +103,7 @@ def getscreenp(): # 一些游戏全屏时会修改分辨率,但不会修改 def hwndscalerate(hwnd): dpi = windows.GetDpiForWindow(hwnd) - rate = getScreenRate() * 96 / dpi + rate = QApplication.instance().devicePixelRatio() * 96 / dpi return rate @@ -243,19 +243,6 @@ def getExeIcon(name, icon=True, cache=False): return pixmap -__rate = 0 - - -def getScreenRate(): - global __rate - if __rate == 0: - hDC = windows.GetDC(0) - dpiX = windows.GetDeviceCaps(hDC, windows.LOGPIXELSX) / 96.0 - windows.ReleaseDC(None, hDC) - __rate = round(dpiX, 2) - return __rate - - def injectdll(injectpids, injecter, dll): pid = " ".join([str(_) for _ in injectpids]) if any(map(testprivilege, injectpids)) == False: diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 237db5f7..ba934fa8 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -8,7 +8,9 @@ import ctypes import time import ctypes.wintypes import time -from myutils.hwnd import getScreenRate +from PyQt5.QtWidgets import ( + QApplication, +) from traceback import print_exc from myutils.config import ( globalconfig, @@ -17,7 +19,7 @@ from myutils.config import ( savehook_new_data, getdefaultsavehook, ) -import threading, queue +import threading import re, heapq from myutils.vndb import searchforidimage @@ -410,7 +412,7 @@ def minmaxmoveobservefunc(self): elif event == windows.EVENT_SYSTEM_MOVESIZEEND: # if globalconfig["movefollow"]: if self.lastpos: - rate = getScreenRate() + rate = QApplication.instance().devicePixelRatio() self.hookfollowsignal.emit( 5, (