This commit is contained in:
恍兮惚兮 2024-07-15 06:53:49 +08:00
parent b982598fc0
commit 44e3ff5ec0
6 changed files with 61 additions and 10 deletions

View File

@ -3,6 +3,7 @@ from myutils.config import globalconfig, _TR
import importlib
from webviewpy import webview_exception
from gui.usefulwidget import getQMessageBox
from traceback import print_exc
class Textbrowser(QLabel):
@ -34,6 +35,8 @@ class Textbrowser(QLabel):
_TR("错误"),
"can't find QWebEngine!",
)
else:
print_exc()
globalconfig["rendertext_using"] = "textbrowser"
tb = importlib.import_module(f"rendertext.textbrowser").TextBrowser
self.textbrowser = tb(self)

View File

@ -44,6 +44,7 @@ class QUnFrameWindow(resizableframeless):
muteprocessignal = pyqtSignal()
ocr_once_signal = pyqtSignal()
resizesignal = pyqtSignal(QSize)
move_signal=pyqtSignal(QPoint)
def hookfollowsignalsolve(self, code, other):
if self._move_drag:
@ -565,6 +566,7 @@ class QUnFrameWindow(resizableframeless):
self.muteprocessignal.connect(self.muteprocessfuntion)
self.toolbarhidedelaysignal.connect(self.toolbarhidedelay)
self.resizesignal.connect(self.resize)
self.move_signal.connect(self.move)
def __init__(self):

View File

@ -962,6 +962,11 @@ class WebivewWidget(abstractwebview):
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER
)
def get_hwnd(self):
return self.webview.get_native_handle(
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_UI_WIDGET
)
def __init__(self, parent=None, debug=True) -> None:
super().__init__(parent)
declare_library_path(
@ -1013,9 +1018,7 @@ class WebivewWidget(abstractwebview):
def resizeEvent(self, a0: QResizeEvent) -> None:
if self.webview:
hwnd = self.webview.get_native_handle(
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_UI_WIDGET
)
hwnd = self.get_hwnd()
size = a0.size() * self.devicePixelRatioF()
windows.MoveWindow(hwnd, 0, 0, size.width(), size.height(), True)

View File

@ -213,9 +213,8 @@ def mouseselectwindow(callback):
def _loop():
while True:
keystate = windows.GetKeyState(
windows.VK_LBUTTON
) # 必须使用GetKeyState, GetAsyncKeyState或SetWindowHookEx都无法检测到高权限应用上的点击事件。
keystate = windows.GetKeyState(windows.VK_LBUTTON)
# 必须使用GetKeyState, GetAsyncKeyState或SetWindowHookEx都无法检测到高权限应用上的点击事件。
if keystate < 0:
break
time.sleep(0.01)

View File

@ -1,9 +1,9 @@
from qtsymbols import *
from rendertext.somefunctions import dataget
import gobject, uuid, json, os, functools
import gobject, uuid, json, os, functools, windows, time
from urllib.parse import quote
from myutils.config import globalconfig, static_data
from myutils.wrapper import tryprint
from myutils.wrapper import tryprint, threader
from gui.usefulwidget import WebivewWidget, QWebWrap
testsavejs = False
@ -48,6 +48,15 @@ class TextBrowser(QWidget, dataget):
# webview2当会执行alert之类的弹窗js时若qt窗口不可视会卡住
self.webivewwidget = WebivewWidget(self)
# webview2无法接收qt事件。
webviewhwnd = self.webivewwidget.get_hwnd()
self.wndproc = windows.WNDPROCTYPE(
functools.partial(
self.extrahandle,
windows.GetWindowLongPtr(webviewhwnd, windows.GWLP_WNDPROC),
)
)
windows.SetWindowLongPtr(webviewhwnd, windows.GWLP_WNDPROC, self.wndproc)
self.masklabel_left = QLabel(self)
self.masklabel_left.setMouseTracking(True)
# self.masklabel_left.setStyleSheet('background-color:red')
@ -72,6 +81,27 @@ class TextBrowser(QWidget, dataget):
self.isfirst = True
self._qweb_query_word()
@threader
def trackingthread(self):
pos = gobject.baseobject.translation_ui.pos()
cus = QCursor.pos()
while True:
keystate = windows.GetKeyState(windows.VK_LBUTTON)
if keystate >= 0:
break
gobject.baseobject.translation_ui.move_signal.emit(
pos + QCursor.pos() - cus
)
time.sleep(0.01)
def extrahandle(self, orig, hwnd, msg, wp, lp):
if wp == windows.WM_LBUTTONDOWN:
# 因为有父窗口所以msg是WM_PARENTNOTIFYwp才是WM_LBUTTONDOWN
# 而且SetCapture后会立即被父窗口把capture夺走无法后面的释放&移动,所以只能开个线程来弄
if self.masklabel.isVisible():
self.trackingthread()
return windows.WNDPROCTYPE(orig)(hwnd, msg, wp, lp)
@tryprint
def showEvent(self, e):
if not self.isfirst:

View File

@ -21,7 +21,6 @@ from ctypes import (
cast,
)
import os
from traceback import print_exc
from ctypes.wintypes import (
RECT,
POINT,
@ -30,10 +29,12 @@ from ctypes.wintypes import (
WORD,
DWORD,
PHKEY,
BYTE,
HKEY,
LPDWORD,
LPBYTE,
WPARAM,
LPARAM,
INT,
LPCWSTR,
HANDLE,
UINT,
@ -1022,3 +1023,16 @@ def MapViewOfFile(hfmap, acc, high, low, size):
IsZoomed = _user32.IsZoomed
IsZoomed.argtypes = (HWND,)
IsZoomed.restype = BOOL
WNDPROCTYPE = WINFUNCTYPE(INT, HWND, INT, WPARAM, LPARAM)
GWLP_WNDPROC = -4
SetWindowLongPtr = _user32.SetWindowLongPtrW
SetWindowLongPtr.argtypes = HWND, INT, c_void_p
SetWindowLongPtr.restype = c_void_p
GetWindowLongPtr = _user32.GetWindowLongPtrW
GetWindowLongPtr.argtypes = HWND, INT
GetWindowLongPtr.restype = c_void_p
WM_LBUTTONDOWN = 0x0201
WM_LBUTTONUP = 0x0202
WM_MOUSEMOVE = 0x0200