Skip to content

Commit f70263a

Browse files
committed
Version 0.22
* Object oriented model for the Browser api * Removed cefwindow as a dependency of cefpython module. * Fixed bug: browser's client area did not get keyboard focus.
1 parent 366041f commit f70263a

17 files changed

Lines changed: 439 additions & 334 deletions

browser.pyx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
class Browser:
6+
7+
windowID = 0
8+
9+
# This is required for weakref.ref() to work.
10+
__slots__ = ["GetWindowID", "CloseBrowser"]
11+
12+
def __init__(self, inWindowID):
13+
14+
self.windowID = inWindowID
15+
16+
def GetWindowID(self):
17+
18+
# Call this function to see whether Browser object is still valid, if windowID == 0 then invalid.
19+
return self.windowID
20+
21+
def CloseBrowser(self):
22+
23+
# weakref.proxy() or checks like this in every method?
24+
if not self.windowID:
25+
raise Exception("Browser.CloseBrowser(): browser is already closed")
26+
27+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(self.windowID)
28+
if <void*>cefBrowser == NULL:
29+
return
30+
31+
if __debug: print "CefBrowser.ParentWindowWillClose()"
32+
(<CefBrowser*>(cefBrowser.get())).ParentWindowWillClose()
33+
34+
if __debug: print "CefBrowser.CloseBrowser()"
35+
(<CefBrowser*>(cefBrowser.get())).CloseBrowser()
36+
37+
__cefBrowsers.erase(<int>self.windowID)
38+
del __pyBrowsers[self.windowID]
39+
self.windowID = 0

cefexample/!README.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ icon.ico
4141

4242
CHANGELOG.
4343

44+
Version 0.22
45+
* Object oriented model for the Browser api
46+
* Removed cefwindow as a dependency of cefpython module.
47+
* Fixed bug: browser's client area did not get keyboard focus.
48+
4449
Version 0.21 released on 2012-07-02.
4550
* Fixed bug: browser's client area wasn't resized when window size changed.
4651

cefexample/cefadvanced.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
def QuitApplication(windowID, msg, wparam, lparam):
1212

13-
browserID = cefpython.GetBrowserByWindowID(windowID)
14-
cefpython.CloseBrowser(browserID)
13+
browser = cefpython.GetBrowserByWindowID(windowID)
14+
browser.CloseBrowser()
15+
print "after CloseBrowser, browser = %s" % browser
1516
cefwindow.DestroyWindow(windowID)
1617
win32gui.PostQuitMessage(0)
1718

@@ -29,12 +30,17 @@ def CefAdvanced():
2930
appSettings["log_severity"] = cefpython.LOGSEVERITY_VERBOSE # LOGSEVERITY_DISABLE - will not create "debug.log" file.
3031
cefpython.Initialize(appSettings)
3132

32-
wndproc = {win32con.WM_CLOSE: QuitApplication, win32con.WM_SIZE: cefpython.WM_SIZE}
33+
wndproc = {
34+
win32con.WM_CLOSE: QuitApplication,
35+
win32con.WM_SIZE: cefpython.wm_Size,
36+
win32con.WM_SETFOCUS: cefpython.wm_SetFocus,
37+
win32con.WM_ERASEBKGND: cefpython.wm_EraseBkgnd
38+
}
3339
windowID = cefwindow.CreateWindow("CefAdvanced", "cefadvanced", 800, 600, None, None, "icon.ico", wndproc)
3440

3541
browserSettings = {} # See: http://code.google.com/p/cefpython/wiki/BrowserSettings
3642
browserSettings["history_disabled"] = False
37-
browserID = cefpython.CreateBrowser(windowID, browserSettings, "cefadvanced.html")
43+
browser = cefpython.CreateBrowser(windowID, browserSettings, "cefadvanced.html")
3844

3945
cefpython.MessageLoop()
4046
cefpython.Shutdown()

cefexample/cefsimple.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88

99
def QuitApplication(windowID, msg, wparam, lparam):
1010

11-
cefpython.CloseBrowser(cefpython.GetBrowserByWindowID(windowID))
11+
browser = cefpython.GetBrowserByWindowID(windowID)
12+
browser.CloseBrowser()
1213
cefwindow.DestroyWindow(windowID)
1314
win32gui.PostQuitMessage(0)
1415

1516
def CefSimple():
1617

1718
cefpython.Initialize({"multi_threaded_message_loop": False})
18-
wndproc = {win32con.WM_CLOSE: QuitApplication, win32con.WM_SIZE: cefpython.WM_SIZE}
19+
wndproc = {
20+
win32con.WM_CLOSE: QuitApplication,
21+
win32con.WM_SIZE: cefpython.wm_Size,
22+
win32con.WM_SETFOCUS: cefpython.wm_SetFocus,
23+
win32con.WM_ERASEBKGND: cefpython.wm_EraseBkgnd
24+
}
1925
windowID = cefwindow.CreateWindow("CefSimple", "cefsimple", 800, 600, None, None, "icon.ico", wndproc)
20-
browserID = cefpython.CreateBrowser(windowID, {}, "cefsimple.html")
26+
browser = cefpython.CreateBrowser(windowID, {}, "cefsimple.html")
2127
cefpython.MessageLoop()
2228
cefpython.Shutdown()
2329

cefexample/cefwindow.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
import os
1111

1212
__debug = False
13-
14-
# We need to keep track of windows classname as when creating browser we need
15-
# to get real HWND and win32gui does not provide a way to get this, so we're using
16-
# FindWindowA(classname) to fetch HWND.
17-
1813
__windows = {} # windowID(int): classname
1914

2015

@@ -91,6 +86,7 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
9186

9287
# Memory error when calling win32gui.DestroyWindow()
9388
# after we called cefpython.CloseBrowser()
89+
9490
def DestroyWindow(windowID):
9591

9692
win32gui.DestroyWindow(windowID)
@@ -99,7 +95,6 @@ def DestroyWindow(windowID):
9995
del __windows[windowID] # Let window with this classname be created again.
10096

10197

102-
10398
def GetWindowClassname(windowID):
10499

105100
for key in __windows:

cefexample/debug.log

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[0702/193718:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
2+
[0702/193953:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
3+
[0702/194026:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
4+
[0702/195137:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
5+
[0702/195147:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
6+
[0702/195211:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
7+
[0702/195230:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
8+
[0702/195445:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
9+
[0702/195703:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
10+
[0702/195828:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
11+
[0702/211416:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
12+
[0702/211435:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
13+
[0702/211442:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
14+
[0702/212207:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
15+
[0702/212228:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
16+
[0702/212448:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
17+
[0702/212541:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
18+
[0702/212839:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
19+
[0702/212912:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
20+
[0702/213037:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
21+
[0702/213150:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
22+
[0702/213250:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
23+
[0702/213321:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
24+
[0702/213546:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
25+
[0702/213643:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
26+
[0702/213735:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
27+
[0702/213818:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
28+
[0702/214050:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
29+
[0702/214137:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
30+
[0702/214143:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
31+
[0702/214355:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
32+
[0702/214441:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
33+
[0702/214445:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
34+
[0702/215505:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
35+
[0702/215859:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091

0 commit comments

Comments
 (0)