Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lochen88 committed Oct 30, 2020
1 parent 1c4b55a commit 69c9247
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 6 deletions.
Binary file modified MBPython/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified MBPython/__pycache__/bindwebview.cpython-36.pyc
Binary file not shown.
Binary file modified MBPython/__pycache__/miniblink.cpython-36.pyc
Binary file not shown.
Binary file added MBPython/__pycache__/timer.cpython-36.pyc
Binary file not shown.
Binary file modified MBPython/__pycache__/wkeStruct.cpython-36.pyc
Binary file not shown.
Binary file modified MBPython/__pycache__/wndproc.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion MBPython/bindwebview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 4 additions & 0 deletions MBPython/wkeStruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)

from ctypes.wintypes import (
LPARAM,
DWORD,
LONG,
WORD,
Expand Down Expand Up @@ -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)]
48 changes: 44 additions & 4 deletions MBPython/wndproc.py
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand All @@ -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'):
Expand All @@ -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)
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
Binary file removed dist/MBPython-0.2.1.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/MBPython-0.2.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 69c9247

Please sign in to comment.