Skip to content

Commit 25f327c

Browse files
committed
Version 0.26:
* Implemented KeyboardHandler * cefadvanced.py: example of binding F12 key to open Developer tools, and F5 to refresh page.
1 parent ac438e1 commit 25f327c

19 files changed

+406
-215
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44

55
# If you want to ignore an already commited directory run:
66
# git rm --cached -r .idea
7-
/.idea/
7+
/.idea/
8+
9+
# WingIDE project files
10+
/wingide.wpr
11+
/wingide.wpu

browser.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class PyBrowser:
6464

6565
# CefLoadHandler.
6666
allowedHandlers += ["OnLoadEnd", "OnLoadError", "OnLoadStart"]
67+
# CefKeyboardHandler.
68+
allowedHandlers += ["OnKeyEvent"]
6769

6870
for key in handlers:
6971
if key not in allowedHandlers:

cefexample/README.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ icon.ico
4343

4444
CHANGELOG.
4545

46+
Version 0.26 released on 2012-07-08.
47+
* Implemented KeyboardHandler
48+
* cefadvanced.py: example of binding F12 key to open Developer tools, and F5 to refresh page.
49+
4650
Version 0.25 released on 2012-07-07.
4751
* Browser object is almost ready, Frame still needs some work.
4852
* Client handlers are starting to work, implemented LoadHandler.

cefexample/cefadvanced.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
Project's website: <a href="http://code.google.com/p/cefpython/">http://code.google.com/p/cefpython/</a><br>
1515
Programming API: <a href="http://code.google.com/p/cefpython/wiki/API">http://code.google.com/p/cefpython/wiki/API</a><br>
16+
Support forum: <a href="https://groups.google.com/group/cefpython?hl=en">https://groups.google.com/group/cefpython?hl=en</a><br>
1617

1718
<br>
1819

@@ -22,16 +23,14 @@
2223

2324
Features coming next:
2425
<ul>
25-
<li>javascript execution</li>
2626
<li>javascript bindings
2727
<li>javascript callbacks
2828
<li>popup and modal windows
2929
<li>loading content from zip (optionally encrypted)
30-
<li>F12 devtools
3130
</ul>
3231

33-
<iframe src="cefsimple.html"></iframe>
34-
<iframe src="cefsimple_onloaderror.html"></iframe>
32+
<!--<iframe src="cefsimple.html"></iframe>-->
33+
<!--<iframe src="cefsimple_onloaderror.html"></iframe>-->
3534

3635
<script>
3736
//frames["simple"].focus()

cefexample/cefadvanced.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,20 @@
88
import win32gui
99
import sys
1010

11-
12-
#noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
1311
def CloseApplication(windowID, msg, wparam, lparam):
14-
1512
browser = cefpython.GetBrowserByWindowID(windowID)
1613
browser.CloseBrowser()
1714
cefwindow.DestroyWindow(windowID)
1815
return 0 # If an application processes this message, it should return zero.
1916

20-
21-
#noinspection PyUnusedLocal
2217
def QuitApplication(windowID, msg, wparam, lparam):
23-
2418
# If you put PostQuitMessage() in WM_CLOSE event (CloseApplication)
2519
# you will get memory errors when closing application.
2620
win32gui.PostQuitMessage(0)
2721
return 0
2822

29-
3023
def CefAdvanced():
31-
32-
# Programming API:
33-
# http://code.google.com/p/cefpython/wiki/API
34-
24+
# Programming API: http://code.google.com/p/cefpython/wiki/API
3525
sys.excepthook = cefpython.ExceptHook # In case of exception display it, write to error.log, shutdown CEF and exit application.
3626
cefwindow.__debug = True # Whether to print debug output to console.
3727
cefpython.__debug = True
@@ -51,13 +41,14 @@ def CefAdvanced():
5141
windowID = cefwindow.CreateWindow("CefAdvanced", "cefadvanced", 800, 600, None, None, "icon.ico", wndproc)
5242

5343
browserSettings = dict() # See: http://code.google.com/p/cefpython/wiki/BrowserSettings
54-
browserSettings["history_disabled"] = False
44+
browserSettings["history_disabled"] = False # Backspace key will act as "History back" action in browser.
5545
browserSettings["universal_access_from_file_urls_allowed"] = True
5646
browserSettings["file_access_from_file_urls_allowed"] = True
5747

5848
handlers = dict()
5949
handlers["OnLoadStart"] = DocumentReady
6050
handlers["OnLoadError"] = OnLoadError
51+
handlers["OnKeyEvent"] = OnKeyEvent
6152

6253
browser = cefpython.CreateBrowser(windowID, browserSettings, "cefadvanced.html", handlers)
6354

@@ -66,64 +57,62 @@ def CefAdvanced():
6657

6758

6859
def DocumentReady(browser, frame):
69-
7060
print "OnLoadStart(): frame URL: %s" % frame.GetURL()
71-
#browser.GetMainFrame().ExecuteJavascript("window.open('about:blank', '', 'width=500,height=500')")
7261
if frame.IsMain():
7362
return
63+
#browser.GetMainFrame().ExecuteJavascript("window.open('about:blank', '', 'width=500,height=500')")
7464
#print "HidePopup(): %s" % browser.HidePopup()
7565

7666
def OnLoadError(browser, frame, errorCode, failedURL, errorText):
77-
7867
print "OnLoadError() failedURL: %s, frame = %s" % (failedURL, frame)
7968

69+
def OnKeyEvent(browser, eventType, keyCode, modifiers, isSystemKey, isAfterJavascript):
70+
# Let's bind developer tools to F12 key.
71+
if cefpython.VK_F12 == keyCode and 0 == eventType and 1024 == modifiers and not isSystemKey:
72+
browser.ShowDevTools()
73+
return True
74+
# Bind F5 to refresh browser window.
75+
elif cefpython.VK_F5 == keyCode and 0 == eventType and 1024 == modifiers and not isSystemKey:
76+
browser.ReloadIgnoreCache()
77+
return True
78+
return False
8079

8180
def JavascriptBindings():
8281
# http://code.google.com/p/chromiumembedded/wiki/JavaScriptIntegration
8382
pass
8483

85-
8684
def JavascriptCallbacks():
8785
pass
8886

89-
9087
def PopupWindow():
9188
pass
9289

93-
9490
def ModalWindow():
9591
pass
9692

97-
9893
def ResizeWindow():
9994
#cefwindow.MoveWindow(windowID, width=500, height=500)
10095
pass
10196

102-
10397
def MoveWindow():
10498
#cefwindow.MoveWindow(windowID, xpos=0, ypos=0)
10599
pass
106100

107-
108101
def DeveloperTools():
109102
#browser.ShowDevTools()
110103
pass
111104

112-
113105
def LoadContentFromZip():
114106
# Allow to pack html/css/images to a zip and run content from this file.
115107
# Optionally allow to password protect this zip file.
116108
pass
117109

118-
119110
def LoadContentFromEncryptedZip():
120111
# This will be useful only if you protect your python sources by compiling them
121112
# to exe by using for example "pyinstaller", or even better you could compile sources
122113
# to a dll-like file called "pyd" by using cython extension, or you could combine them both.
123114
# See WBEA for implementation.
124115
pass
125116

126-
127117
if __name__ == "__main__":
128-
129118
CefAdvanced()

cefexample/cefsimple.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
Project's website: <a href="http://code.google.com/p/cefpython/">http://code.google.com/p/cefpython/</a><br>
1515
Programming API: <a href="http://code.google.com/p/cefpython/wiki/API">http://code.google.com/p/cefpython/wiki/API</a><br>
16+
Support forum: <a href="https://groups.google.com/group/cefpython?hl=en">https://groups.google.com/group/cefpython?hl=en</a><br>
1617

1718
<br>
1819

cefexample/cefsimple.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@
77
import win32gui
88
import sys
99

10-
#noinspection PyUnusedLocal
1110
def CloseApplication(windowID, msg, wparam, lparam):
12-
1311
browser = cefpython.GetBrowserByWindowID(windowID)
1412
browser.CloseBrowser()
1513
cefwindow.DestroyWindow(windowID)
14+
return 0
1615

17-
#noinspection PyUnusedLocal
1816
def QuitApplication(windowID, msg, wparam, lparam):
19-
2017
win32gui.PostQuitMessage(0)
2118
return 0
2219

2320
def CefSimple():
24-
2521
sys.excepthook = cefpython.ExceptHook
2622
cefpython.Initialize({"multi_threaded_message_loop": False})
2723
wndproc = {
@@ -31,11 +27,10 @@ def CefSimple():
3127
win32con.WM_SETFOCUS: cefpython.wm_SetFocus,
3228
win32con.WM_ERASEBKGND: cefpython.wm_EraseBkgnd
3329
}
34-
windowID = cefwindow.CreateWindow("CefSimple", "cefsimple", 800, 600, None, None, "icon.ico", wndproc)
35-
browser = cefpython.CreateBrowser(windowID, {}, "cefsimple.html")
30+
windowID = cefwindow.CreateWindow(title="CefSimple", className="cefsimple", width=800, height=600, icon="icon.ico", windowProc=wndproc)
31+
browser = cefpython.CreateBrowser(windowID, browserSettings={}, navigateURL="cefsimple.html")
3632
cefpython.MessageLoop()
3733
cefpython.Shutdown()
3834

3935
if __name__ == "__main__":
40-
4136
CefSimple()

cefexample/cefwindow.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
import os
1111

1212
__debug = False
13-
__windows = {} # windowID(int): classname
13+
__windows = {} # windowID(int): className
1414

1515

16-
def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=None, wndproc=None):
16+
def CreateWindow(title, className, width, height, xpos=None, ypos=None, icon=None, windowProc=None):
1717

1818
for key in __windows:
19-
if __windows[key] == classname:
20-
raise Exception("There was already created a window with that classname: %s."
21-
"Each created window must have an unique classname." % classname)
19+
if __windows[key] == className:
20+
raise Exception("There was already created a window with that className: %s."
21+
"Each created window must have an unique className." % className)
2222

23-
if not wndproc:
24-
wndproc = {win32con.WM_CLOSE: WM_CLOSE}
23+
if not windowProc:
24+
windowProc = {win32con.WM_CLOSE: WM_CLOSE}
2525

2626
bigIcon = ""
2727
smallIcon = ""
@@ -46,11 +46,11 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
4646

4747
wndclass = win32gui.WNDCLASS()
4848
wndclass.hInstance = win32api.GetModuleHandle(None)
49-
wndclass.lpszClassName = classname
49+
wndclass.lpszClassName = className
5050
wndclass.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
5151
wndclass.hbrBackground = win32con.COLOR_WINDOW
5252
wndclass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
53-
wndclass.lpfnWndProc = wndproc
53+
wndclass.lpfnWndProc = windowProc
5454

5555
#noinspection PyUnusedLocal
5656
atomclass = win32gui.RegisterClass(wndclass)
@@ -70,11 +70,11 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
7070
if xpos < 0: xpos = 0
7171
if ypos < 0: ypos = 0
7272

73-
windowID = win32gui.CreateWindow(classname, title,
73+
windowID = win32gui.CreateWindow(className, title,
7474
win32con.WS_OVERLAPPEDWINDOW | win32con.WS_CLIPCHILDREN | win32con.WS_VISIBLE,
7575
xpos, ypos, width, height, # xpos, ypos, width, height
7676
0, 0, wndclass.hInstance, None)
77-
__windows[windowID] = classname
77+
__windows[windowID] = className
7878

7979
if icon:
8080
if bigIcon:
@@ -94,12 +94,12 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
9494
def DestroyWindow(windowID):
9595

9696
win32gui.DestroyWindow(windowID)
97-
classname = GetWindowClassname(windowID)
98-
win32gui.UnregisterClass(classname, None)
99-
del __windows[windowID] # Let window with this classname be created again.
97+
className = GetWindowClassName(windowID)
98+
win32gui.UnregisterClass(className, None)
99+
del __windows[windowID] # Let window with this className be created again.
100100

101101

102-
def GetWindowClassname(windowID):
102+
def GetWindowClassName(windowID):
103103

104104
for key in __windows:
105105
if key == windowID:
@@ -147,7 +147,7 @@ def GetLastError():
147147
return "(%d) %s" % (code, win32api.FormatMessage(code))
148148

149149
#noinspection PyUnusedLocal
150-
def MessageLoop(classname):
150+
def MessageLoop(className):
151151

152152
while not win32gui.PumpWaitingMessages():
153153
time.sleep(0.001)

cefexample/debug.log

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,2 @@
1-
[0707/093114:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
2-
[0707/093120:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
3-
[0707/093125:INFO:CONSOLE(0)] "Refused to display document because display forbidden by X-Frame-Options.
4-
," source: (0)
5-
[0707/093133:VERBOSE1:ssl_host_info.cc(113)] Kicking off verification for plusone.google.com
6-
[0707/093133:VERBOSE1:ssl_host_info.cc(193)] Verification took 0ms
7-
[0707/094216:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
8-
[0707/094219:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
9-
[0707/094222:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
10-
[0707/101022:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
11-
[0707/101036:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
12-
[0707/101046:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
13-
[0707/101128:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
14-
[0707/101241:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
15-
[0707/101246:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
16-
[0707/101443:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
17-
[0707/101451:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
18-
[0707/101500:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
19-
[0707/101504:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
20-
[0707/111824:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
21-
[0707/111845:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
22-
[0707/112203:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
23-
[0707/112237:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
24-
[0707/112416:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
25-
[0707/112644:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
26-
[0707/135335:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
27-
[0707/142644:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
28-
[0708/062540:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
29-
[0708/063400:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
30-
[0708/063620:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
31-
[0708/065257:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
32-
[0708/065425:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
33-
[0708/080641:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
34-
[0708/081116:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
35-
[0708/081131:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
36-
[0708/081205:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
37-
[0708/081405:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
38-
[0708/081433:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
39-
[0708/081458:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
40-
[0708/081920:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
41-
[0708/105327:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
42-
[0708/105800:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
43-
[0708/114617:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
44-
[0708/114800:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
45-
[0708/120146:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
46-
[0708/122430:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
47-
[0708/122618:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
48-
[0708/122652:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
49-
[0708/123137:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
50-
[0708/123414:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
51-
[0708/124025:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
52-
[0708/134004:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
53-
[0708/134543:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
1+
[0708/203505:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
2+
[0708/203510:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091

cefexample/error.log

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)