diff --git a/MBPython/__pycache__/__init__.cpython-36.pyc b/MBPython/__pycache__/__init__.cpython-36.pyc index 51ae5cd..3a0ef08 100644 Binary files a/MBPython/__pycache__/__init__.cpython-36.pyc and b/MBPython/__pycache__/__init__.cpython-36.pyc differ diff --git a/MBPython/__pycache__/bindwebview.cpython-36.pyc b/MBPython/__pycache__/bindwebview.cpython-36.pyc index a3b9238..30a97b0 100644 Binary files a/MBPython/__pycache__/bindwebview.cpython-36.pyc and b/MBPython/__pycache__/bindwebview.cpython-36.pyc differ diff --git a/MBPython/__pycache__/miniblink.cpython-36.pyc b/MBPython/__pycache__/miniblink.cpython-36.pyc index ee7c4ad..caf92c5 100644 Binary files a/MBPython/__pycache__/miniblink.cpython-36.pyc and b/MBPython/__pycache__/miniblink.cpython-36.pyc differ diff --git a/MBPython/__pycache__/timer.cpython-36.pyc b/MBPython/__pycache__/timer.cpython-36.pyc new file mode 100644 index 0000000..36881fd Binary files /dev/null and b/MBPython/__pycache__/timer.cpython-36.pyc differ diff --git a/MBPython/__pycache__/wkeStruct.cpython-36.pyc b/MBPython/__pycache__/wkeStruct.cpython-36.pyc index c48cac4..bc8820e 100644 Binary files a/MBPython/__pycache__/wkeStruct.cpython-36.pyc and b/MBPython/__pycache__/wkeStruct.cpython-36.pyc differ diff --git a/MBPython/__pycache__/wndproc.cpython-36.pyc b/MBPython/__pycache__/wndproc.cpython-36.pyc index 73ee8f7..45f4487 100644 Binary files a/MBPython/__pycache__/wndproc.cpython-36.pyc and b/MBPython/__pycache__/wndproc.cpython-36.pyc differ diff --git a/MBPython/bindwebview.py b/MBPython/bindwebview.py index 48cbc76..cc5fff8 100644 --- a/MBPython/bindwebview.py +++ b/MBPython/bindwebview.py @@ -39,7 +39,7 @@ def bind_webview(self,hwnd=0,isTransparent=False,isZoom=True): self.mb.wkeSetTransparent(self.m_webview,0) - tmp_WndProc=WndProcHook(self.m_webview,hwnd) + tmp_WndProc=WndProcHook(hwnd,self.m_webview) tmp_WndProc.onWndProcCallback=self.__myWndProcCallBack tmp_WndProc.hook_WndProc() diff --git a/MBPython/wkeStruct.py b/MBPython/wkeStruct.py index 6bdc6ae..a30c2db 100644 --- a/MBPython/wkeStruct.py +++ b/MBPython/wkeStruct.py @@ -15,6 +15,7 @@ ) from ctypes.wintypes import ( + LPARAM, DWORD, LONG, WORD, @@ -106,7 +107,10 @@ class BITMAPINFO(Structure): _fields_ = [("bmiHeader", BITMAPINFOHEADER), ("bmiColors", DWORD * 3)] +class COPYDATASTRUCT(Structure): + _fields_ = [('dwData', LPARAM),('cbData', DWORD),('lpData', c_char_p)] + from . import _LRESULT class PAINTSTRUCT(Structure): _fields_=[('hdc',_LRESULT),('fErase',c_int),('rcPaint',Rect),('fRestore',c_int),('fIncUpdate',c_int),('rgbReserved',c_char *32)] diff --git a/MBPython/wndproc.py b/MBPython/wndproc.py index cf35d23..41feead 100644 --- a/MBPython/wndproc.py +++ b/MBPython/wndproc.py @@ -1,11 +1,14 @@ # -*- coding:utf-8 -*- from .winConst import WinConst +from .wkeStruct import COPYDATASTRUCT +from ctypes import (cast,c_char_p,py_object,sizeof,byref,string_at,create_string_buffer,POINTER) import win32gui import win32api +import json - +PCOPYDATASTRUCT = POINTER(COPYDATASTRUCT) class WndProcHook: - def __init__(self,webview,hwnd): + def __init__(self,hwnd,webview=None): self.webview=webview self.hwnd=hwnd self.msg_func_dict = {} @@ -18,7 +21,18 @@ def add_msg_func(self,webview,hwnd,msg,msg_func): def _onWndProcCallback(self, hwnd, msg, wParam, lParam): if msg in self.msg_func_dict: - ret=self.msg_func_dict[msg](self.webview,hwnd,wParam, lParam) + argcount=self.msg_func_dict[msg].__code__.co_argcount + ret=None + if argcount==5: + arg_vals=self.msg_func_dict[msg].__code__.co_varnames + if arg_vals[0]=='self': + ret=self.msg_func_dict[msg](self.webview,hwnd,wParam, lParam) + elif argcount==4: + ret=self.msg_func_dict[msg](self.webview,hwnd,wParam, lParam) + elif argcount==3: + ret=self.msg_func_dict[msg](hwnd,wParam, lParam) + elif argcount==2: + ret=self.msg_func_dict[msg](wParam, lParam) if ret!=None: return ret if hasattr(self,'onWndProcCallback'): @@ -27,4 +41,30 @@ def _onWndProcCallback(self, hwnd, msg, wParam, lParam): return ret if msg == WinConst.WM_DESTROY: self.unhook_WndProc() - return win32gui.CallWindowProc(self.oldWndProc, hwnd, msg, wParam, lParam) \ No newline at end of file + return win32gui.CallWindowProc(self.oldWndProc, hwnd, msg, wParam, lParam) + + @staticmethod + def value_to_msg(value,copydate=False): + if copydate: + cds=COPYDATASTRUCT() + cds.dwData=0 + value=json.dumps(value).encode() + cds.cbData = sizeof(create_string_buffer(value)) + cds.lpData = c_char_p(value) + return byref(cds) + else: + value=json.dumps(value).encode() + return c_char_p(value) + @staticmethod + def msg_to_value(wParam,lParam,copydate=False): + if lParam!=0: + try: + if copydate: + pCDS=cast(lParam, PCOPYDATASTRUCT) + value=string_at(pCDS.contents.lpData).decode() + else: + value=cast(lParam, c_char_p).value.decode() + except: + return + value=json.loads(value) + return value \ No newline at end of file diff --git a/dist/MBPython-0.2.1.tar.gz b/dist/MBPython-0.2.1.tar.gz deleted file mode 100644 index b6bc907..0000000 Binary files a/dist/MBPython-0.2.1.tar.gz and /dev/null differ diff --git a/dist/MBPython-0.2.1-py3-none-any.whl b/dist/MBPython-0.2.2-py3-none-any.whl similarity index 57% rename from dist/MBPython-0.2.1-py3-none-any.whl rename to dist/MBPython-0.2.2-py3-none-any.whl index b3d81b9..07f4b88 100644 Binary files a/dist/MBPython-0.2.1-py3-none-any.whl and b/dist/MBPython-0.2.2-py3-none-any.whl differ diff --git a/dist/MBPython-0.2.2.tar.gz b/dist/MBPython-0.2.2.tar.gz new file mode 100644 index 0000000..8412362 Binary files /dev/null and b/dist/MBPython-0.2.2.tar.gz differ diff --git a/pyproject.toml b/pyproject.toml index 66d5a8d..52686b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "MBPython" -version = "0.2.1" +version = "0.2.2" description = "Miniblink binding for python" authors = ["lochen <1191826896@qq.com>"] license = "MIT"