diff --git a/src/LunaTranslator/gui/rangeselect.py b/src/LunaTranslator/gui/rangeselect.py index 1fd64875..26f07dd8 100644 --- a/src/LunaTranslator/gui/rangeselect.py +++ b/src/LunaTranslator/gui/rangeselect.py @@ -1,5 +1,5 @@ from qtsymbols import * -import windows, winsharedutils +import windows, winsharedutils, gobject from myutils.config import globalconfig from gui.resizeablemainwindow import Mainw from gui.dynalang import LAction @@ -15,6 +15,15 @@ class rangeadjust(Mainw): self.traceposstart = pos def traceoffset(self, curr): + hwnd = gobject.baseobject.hwnd + if not hwnd: + self.tracepos = QPoint() + return + if windows.MonitorFromWindow(hwnd) != windows.MonitorFromWindow( + int(self.winId()) + ): + self.tracepos = QPoint() + return keystate = windows.GetKeyState(windows.VK_LBUTTON) if keystate < 0 and windows.GetForegroundWindow() == int(self.winId()): self.tracepos = QPoint() diff --git a/src/LunaTranslator/gui/translatorUI.py b/src/LunaTranslator/gui/translatorUI.py index 56836f12..be4ef9dd 100644 --- a/src/LunaTranslator/gui/translatorUI.py +++ b/src/LunaTranslator/gui/translatorUI.py @@ -290,7 +290,7 @@ class TranslatorWindow(resizableframeless): if not rect: lastpos = None continue - rate = hwndratex(hwnd) + rate = self.devicePixelRatioF() rect = QRect( int(rect[0] / rate), int(rect[1] / rate), @@ -305,7 +305,6 @@ class TranslatorWindow(resizableframeless): except: pass continue - if (rect.topLeft() == QPoint(0, 0)) or (rect.size() != lastpos.size()): lastpos = rect continue @@ -313,6 +312,9 @@ class TranslatorWindow(resizableframeless): gobject.baseobject.textsource.traceoffset(rect.topLeft()) except: pass + if windows.MonitorFromWindow(hwnd) != windows.MonitorFromWindow(self.winid): + lastpos = None + return self.move_signal.emit(tracepos - lastpos.topLeft() + rect.topLeft()) def showres(self, kwargs): diff --git a/src/LunaTranslator/textsource/texthook.py b/src/LunaTranslator/textsource/texthook.py index 5a9146b6..8fdca362 100644 --- a/src/LunaTranslator/textsource/texthook.py +++ b/src/LunaTranslator/textsource/texthook.py @@ -457,14 +457,14 @@ class texthook(basetext): else None ) if self.safeembedcheck(text): + trans = self.waitfortranslation(text, engine) + else: collect = [] for _ in text.split("\n"): if _ and self.safeembedcheck(_): _ = self.waitfortranslation(_, engine) collect.append(_) trans = "\n".join(collect) - else: - trans = self.waitfortranslation(text, engine) if not trans: trans = "" if globalconfig["embedded"]["trans_kanji"]: @@ -525,7 +525,9 @@ class texthook(basetext): self.selectinghook = key select = True break - gobject.baseobject.hookselectdialog.addnewhooksignal.emit(key, select, isembedable) + gobject.baseobject.hookselectdialog.addnewhooksignal.emit( + key, select, isembedable + ) return True def setsettings(self): diff --git a/src/LunaTranslator/textsource/textsourcebase.py b/src/LunaTranslator/textsource/textsourcebase.py index 6f2df98a..7355c1bf 100644 --- a/src/LunaTranslator/textsource/textsourcebase.py +++ b/src/LunaTranslator/textsource/textsourcebase.py @@ -118,7 +118,10 @@ class basetext: "SELECT machineTrans FROM artificialtrans WHERE source = ?", (src,), ).fetchone() - ret = json.loads((ret[0])) + try: + ret = json.loads((ret[0])) + except: + ret = {} ret[clsname] = trans ret = json.dumps(ret, ensure_ascii=False) self.sqlwrite2.execute( diff --git a/src/LunaTranslator/windows.py b/src/LunaTranslator/windows.py index aac508f9..a3dd456b 100644 --- a/src/LunaTranslator/windows.py +++ b/src/LunaTranslator/windows.py @@ -33,6 +33,7 @@ from ctypes.wintypes import ( HKEY, LPDWORD, LPBYTE, + HMONITOR, LPCVOID, LPWSTR, WPARAM, @@ -1020,3 +1021,13 @@ def FormatMessage(code, module=None): if length: LocalFree(mess) return res.strip() + + +MONITOR_DEFAULTTONEAREST = 0x00000002 +_MonitorFromWindow = _user32.MonitorFromWindow +_MonitorFromWindow.argtypes = HWND, DWORD +_MonitorFromWindow.restype = HMONITOR + + +def MonitorFromWindow(hwnd, dwFlags=MONITOR_DEFAULTTONEAREST): + return _MonitorFromWindow(hwnd, dwFlags) diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 670db548..763bca78 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 45) -set(VERSION_PATCH 1) +set(VERSION_PATCH 2) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)