diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 85b06804..0b4bf7e7 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -935,7 +935,7 @@ class MAINUI: elif "once" not in dir(self.textsource): self.textsource.once = True setandrefresh(True) - if len(self.textsource.pids): + if self.textsource.pids: _mute = winsharedutils.GetProcessMute(self.textsource.pids[0]) if self.translation_ui.processismuteed != _mute: self.translation_ui.processismuteed = _mute diff --git a/LunaTranslator/LunaTranslator/gui/rangeselect.py b/LunaTranslator/LunaTranslator/gui/rangeselect.py index 87586509..8bc238b2 100644 --- a/LunaTranslator/LunaTranslator/gui/rangeselect.py +++ b/LunaTranslator/LunaTranslator/gui/rangeselect.py @@ -6,12 +6,33 @@ from gui.dynalang import LAction class rangeadjust(Mainw): + traceoffsetsignal = pyqtSignal(QPoint) + + def starttrace(self, pos): + self.tracepos = self.geometry().topLeft() + self.traceposstart = pos + + def traceoffset(self, curr): + if self._isTracking: + return + _geo = self.geometry() + if self.tracepos.isNull(): + self.tracepos = _geo.topLeft() + self.traceposstart = curr + target = self.tracepos + (curr - self.traceposstart) * self.devicePixelRatioF() + self.setGeometry( + target.x(), + target.y(), + _geo.width(), + _geo.height(), + ) def __init__(self, parent): - super(rangeadjust, self).__init__(parent) + self.traceoffsetsignal.connect(self.traceoffset) self.label = QLabel(self) self.setstyle() + self.tracepos = QPoint() self.drag_label = QLabel(self) self.drag_label.setGeometry(0, 0, 4000, 2000) self._isTracking = False @@ -43,9 +64,12 @@ class rangeadjust(Mainw): ) def mouseMoveEvent(self, e): + self.tracepos = QPoint() if self._isTracking: self._endPos = e.pos() - self._startPos - self.move(self.pos() + self._endPos) + _geo = self.geometry() + _geo.translate(self._endPos) + self.setGeometry(*_geo.getRect()) def mousePressEvent(self, e): if e.button() == Qt.MouseButton.LeftButton: @@ -100,6 +124,7 @@ class rangeadjust(Mainw): return self._rect def setrect(self, rect): + self.tracepos = QPoint() if rect: (x1, y1), (x2, y2) = rect self.show() diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 9b88a8b2..f21b46f1 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -247,9 +247,17 @@ class QUnFrameWindow(resizableframeless): @threader def tracewindowposthread(self): lastpos = None + tracepos = None + tracehwnd = None + + def _castqp(rect): + return QPoint( + int(rect[0] / self.devicePixelRatioF()), + int(rect[1] / self.devicePixelRatioF()), + ) + while True: - time.sleep(0.05) - # 不能太快了,不然有int取整累计误差。其实应该记录起始窗口位置,然后计算与起始的dxdy,而不是与上一次的dxdy,但这太麻烦了 + time.sleep(0.01) if self._move_drag: lastpos = None continue @@ -258,29 +266,33 @@ class QUnFrameWindow(resizableframeless): continue try: hwnd = gobject.baseobject.textsource.hwnd + if hwnd != tracehwnd: + lastpos = None except: lastpos = None continue rect = windows.GetWindowRect(hwnd) + tracehwnd = hwnd if not rect: lastpos = None continue + rect = _castqp(rect) if not lastpos: lastpos = rect + tracepos = self.pos() + try: + gobject.baseobject.textsource.starttrace(rect) + except: + pass continue - rate = self.devicePixelRatioF() - dx, dy = int((rect[0] - lastpos[0]) / rate), int( - (rect[1] - lastpos[1]) / rate - ) - if dx == 0 and dy == 0: + if rect == QPoint(0, 0): continue try: - gobject.baseobject.textsource.moveui(dx, dy) + gobject.baseobject.textsource.traceoffset(rect) except: - pass - self.move_signal.emit(QPoint(self.x() + dx, self.y() + dy)) - lastpos = rect + print_exc() + self.move_signal.emit(tracepos - lastpos + rect) def showres(self, kwargs): # name,color,res,onlytrans,iter_context): try: diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index efff6b11..e0ce469d 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -423,12 +423,15 @@ def minmaxmoveobservefunc(self): def win_event_callback( hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ): + try: if gobject.baseobject.textsource is None: return - if gobject.baseobject.textsource.hwnd == 0: + if not gobject.baseobject.textsource.hwnd: return - + if not gobject.baseobject.textsource.pids: + return + p_pids = gobject.baseobject.textsource.pids _focusp = windows.GetWindowThreadProcessId(hwnd) if event != windows.EVENT_SYSTEM_FOREGROUND: return @@ -441,10 +444,7 @@ def minmaxmoveobservefunc(self): "Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None ): return - if ( - len(gobject.baseobject.textsource.pids) == 0 - or _focusp in gobject.baseobject.textsource.pids - ): + if _focusp in p_pids: gobject.baseobject.translation_ui.thistimenotsetop = False gobject.baseobject.translation_ui.settop() else: diff --git a/LunaTranslator/LunaTranslator/textsource/ocrtext.py b/LunaTranslator/LunaTranslator/textsource/ocrtext.py index 095660dd..ad17511e 100644 --- a/LunaTranslator/LunaTranslator/textsource/ocrtext.py +++ b/LunaTranslator/LunaTranslator/textsource/ocrtext.py @@ -56,9 +56,13 @@ class ocrtext(basetext): self.lastocrtime.append(0) self.savelasttext.append(None) - def moveui(self, x, y): + def starttrace(self, pos): for _r in self.range_ui: - _r.move(_r.pos().x() + x, _r.pos().y() + y) + _r.starttrace(pos) + + def traceoffset(self, curr): + for _r in self.range_ui: + _r.traceoffsetsignal.emit(curr) def setrect(self, rect): self.range_ui[-1].setrect(rect) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 46c7eda0..834903db 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 23) -set(VERSION_PATCH 5) +set(VERSION_PATCH 6) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h)