mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
trace
This commit is contained in:
parent
aeb551e360
commit
835b63a250
@ -935,7 +935,7 @@ class MAINUI:
|
|||||||
elif "once" not in dir(self.textsource):
|
elif "once" not in dir(self.textsource):
|
||||||
self.textsource.once = True
|
self.textsource.once = True
|
||||||
setandrefresh(True)
|
setandrefresh(True)
|
||||||
if len(self.textsource.pids):
|
if self.textsource.pids:
|
||||||
_mute = winsharedutils.GetProcessMute(self.textsource.pids[0])
|
_mute = winsharedutils.GetProcessMute(self.textsource.pids[0])
|
||||||
if self.translation_ui.processismuteed != _mute:
|
if self.translation_ui.processismuteed != _mute:
|
||||||
self.translation_ui.processismuteed = _mute
|
self.translation_ui.processismuteed = _mute
|
||||||
|
@ -6,12 +6,33 @@ from gui.dynalang import LAction
|
|||||||
|
|
||||||
|
|
||||||
class rangeadjust(Mainw):
|
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):
|
def __init__(self, parent):
|
||||||
|
|
||||||
super(rangeadjust, self).__init__(parent)
|
super(rangeadjust, self).__init__(parent)
|
||||||
|
self.traceoffsetsignal.connect(self.traceoffset)
|
||||||
self.label = QLabel(self)
|
self.label = QLabel(self)
|
||||||
self.setstyle()
|
self.setstyle()
|
||||||
|
self.tracepos = QPoint()
|
||||||
self.drag_label = QLabel(self)
|
self.drag_label = QLabel(self)
|
||||||
self.drag_label.setGeometry(0, 0, 4000, 2000)
|
self.drag_label.setGeometry(0, 0, 4000, 2000)
|
||||||
self._isTracking = False
|
self._isTracking = False
|
||||||
@ -43,9 +64,12 @@ class rangeadjust(Mainw):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def mouseMoveEvent(self, e):
|
def mouseMoveEvent(self, e):
|
||||||
|
self.tracepos = QPoint()
|
||||||
if self._isTracking:
|
if self._isTracking:
|
||||||
self._endPos = e.pos() - self._startPos
|
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):
|
def mousePressEvent(self, e):
|
||||||
if e.button() == Qt.MouseButton.LeftButton:
|
if e.button() == Qt.MouseButton.LeftButton:
|
||||||
@ -100,6 +124,7 @@ class rangeadjust(Mainw):
|
|||||||
return self._rect
|
return self._rect
|
||||||
|
|
||||||
def setrect(self, rect):
|
def setrect(self, rect):
|
||||||
|
self.tracepos = QPoint()
|
||||||
if rect:
|
if rect:
|
||||||
(x1, y1), (x2, y2) = rect
|
(x1, y1), (x2, y2) = rect
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -247,9 +247,17 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
@threader
|
@threader
|
||||||
def tracewindowposthread(self):
|
def tracewindowposthread(self):
|
||||||
lastpos = None
|
lastpos = None
|
||||||
|
tracepos = None
|
||||||
|
tracehwnd = None
|
||||||
|
|
||||||
|
def _castqp(rect):
|
||||||
|
return QPoint(
|
||||||
|
int(rect[0] / self.devicePixelRatioF()),
|
||||||
|
int(rect[1] / self.devicePixelRatioF()),
|
||||||
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.05)
|
time.sleep(0.01)
|
||||||
# 不能太快了,不然有int取整累计误差。其实应该记录起始窗口位置,然后计算与起始的dxdy,而不是与上一次的dxdy,但这太麻烦了
|
|
||||||
if self._move_drag:
|
if self._move_drag:
|
||||||
lastpos = None
|
lastpos = None
|
||||||
continue
|
continue
|
||||||
@ -258,29 +266,33 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
hwnd = gobject.baseobject.textsource.hwnd
|
hwnd = gobject.baseobject.textsource.hwnd
|
||||||
|
if hwnd != tracehwnd:
|
||||||
|
lastpos = None
|
||||||
except:
|
except:
|
||||||
lastpos = None
|
lastpos = None
|
||||||
continue
|
continue
|
||||||
rect = windows.GetWindowRect(hwnd)
|
rect = windows.GetWindowRect(hwnd)
|
||||||
|
tracehwnd = hwnd
|
||||||
if not rect:
|
if not rect:
|
||||||
lastpos = None
|
lastpos = None
|
||||||
continue
|
continue
|
||||||
|
rect = _castqp(rect)
|
||||||
if not lastpos:
|
if not lastpos:
|
||||||
lastpos = rect
|
lastpos = rect
|
||||||
|
tracepos = self.pos()
|
||||||
|
try:
|
||||||
|
gobject.baseobject.textsource.starttrace(rect)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
continue
|
continue
|
||||||
rate = self.devicePixelRatioF()
|
|
||||||
|
|
||||||
dx, dy = int((rect[0] - lastpos[0]) / rate), int(
|
if rect == QPoint(0, 0):
|
||||||
(rect[1] - lastpos[1]) / rate
|
|
||||||
)
|
|
||||||
if dx == 0 and dy == 0:
|
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
gobject.baseobject.textsource.moveui(dx, dy)
|
gobject.baseobject.textsource.traceoffset(rect)
|
||||||
except:
|
except:
|
||||||
pass
|
print_exc()
|
||||||
self.move_signal.emit(QPoint(self.x() + dx, self.y() + dy))
|
self.move_signal.emit(tracepos - lastpos + rect)
|
||||||
lastpos = rect
|
|
||||||
|
|
||||||
def showres(self, kwargs): # name,color,res,onlytrans,iter_context):
|
def showres(self, kwargs): # name,color,res,onlytrans,iter_context):
|
||||||
try:
|
try:
|
||||||
|
@ -423,12 +423,15 @@ def minmaxmoveobservefunc(self):
|
|||||||
def win_event_callback(
|
def win_event_callback(
|
||||||
hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime
|
hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime
|
||||||
):
|
):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if gobject.baseobject.textsource is None:
|
if gobject.baseobject.textsource is None:
|
||||||
return
|
return
|
||||||
if gobject.baseobject.textsource.hwnd == 0:
|
if not gobject.baseobject.textsource.hwnd:
|
||||||
return
|
return
|
||||||
|
if not gobject.baseobject.textsource.pids:
|
||||||
|
return
|
||||||
|
p_pids = gobject.baseobject.textsource.pids
|
||||||
_focusp = windows.GetWindowThreadProcessId(hwnd)
|
_focusp = windows.GetWindowThreadProcessId(hwnd)
|
||||||
if event != windows.EVENT_SYSTEM_FOREGROUND:
|
if event != windows.EVENT_SYSTEM_FOREGROUND:
|
||||||
return
|
return
|
||||||
@ -441,10 +444,7 @@ def minmaxmoveobservefunc(self):
|
|||||||
"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None
|
"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
if (
|
if _focusp in p_pids:
|
||||||
len(gobject.baseobject.textsource.pids) == 0
|
|
||||||
or _focusp in gobject.baseobject.textsource.pids
|
|
||||||
):
|
|
||||||
gobject.baseobject.translation_ui.thistimenotsetop = False
|
gobject.baseobject.translation_ui.thistimenotsetop = False
|
||||||
gobject.baseobject.translation_ui.settop()
|
gobject.baseobject.translation_ui.settop()
|
||||||
else:
|
else:
|
||||||
|
@ -56,9 +56,13 @@ class ocrtext(basetext):
|
|||||||
self.lastocrtime.append(0)
|
self.lastocrtime.append(0)
|
||||||
self.savelasttext.append(None)
|
self.savelasttext.append(None)
|
||||||
|
|
||||||
def moveui(self, x, y):
|
def starttrace(self, pos):
|
||||||
for _r in self.range_ui:
|
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):
|
def setrect(self, rect):
|
||||||
self.range_ui[-1].setrect(rect)
|
self.range_ui[-1].setrect(rect)
|
||||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 5)
|
set(VERSION_MAJOR 5)
|
||||||
set(VERSION_MINOR 23)
|
set(VERSION_MINOR 23)
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user