Skip to content

Commit 10a988b

Browse files
committed
Add tkinter_.py example (#255) among others.
Update examples and unit tests, minor fixes. Add FocusHandler interface, see API docs and Tkinter example. Update documentation for cefpython.ExceptHook. Fix cefpython Shutdown internals. Refactor client_handler/. Rename src/cython_includes/ to src/extern/, and create src/extern_cef/.
1 parent 3d7670e commit 10a988b

File tree

109 files changed

+1655
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1655
-938
lines changed

api/API-categories.md

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

4141
* [DisplayHandler](DisplayHandler.md)
4242
* [DownloadHandler](DownloadHandler.md)
43+
* [FocusHandler](FocusHandler.md)
4344
* [JavascriptContextHandler](JavascriptContextHandler.md)
4445
* [JavascriptDialogHandler](JavascriptDialogHandler.md)
4546
* [KeyboardHandler](KeyboardHandler.md)

api/API-index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* [OnKeyEvent](KeyboardHandler.md#onkeyevent)
4646
* [StringVisitor (interface)](StringVisitor.md)
4747
* [Visit](StringVisitor.md#visit)
48-
* [Frame (object)](Image.md)
48+
* [Image (object)](Image.md)
4949
* [GetAsBitmap](Image.md#getasbitmap)
5050
* [GetAsPng](Image.md#getaspng)
5151
* [GetHeight](Image.md#getheight)
@@ -56,6 +56,10 @@
5656
* [OnBeforeUnloadJavascriptDialog](JavascriptDialogHandler.md#onbeforeunloadjavascriptdialog)
5757
* [OnResetJavascriptDialogState](JavascriptDialogHandler.md#onresetjavascriptdialogstate)
5858
* [OnJavascriptDialogClosed](JavascriptDialogHandler.md#onjavascriptdialogclosed)
59+
* [FocusHandler (interface)](FocusHandler.md)
60+
* [OnTakeFocus](FocusHandler.md#ontakefocus)
61+
* [OnSetFocus](FocusHandler.md#onsetfocus)
62+
* [OnGotFocus](FocusHandler.md#ongotfocus)
5963
* [DisplayHandler (interface)](DisplayHandler.md)
6064
* [OnAddressChange](DisplayHandler.md#onaddresschange)
6165
* [OnTitleChange](DisplayHandler.md#ontitlechange)

api/FocusHandler.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[API categories](API-categories.md) | [API index](API-index.md)
2+
3+
4+
# FocusHandler (interface)
5+
6+
Implement this interface to handle events related to focus. The methods of
7+
this class will be called on the UI thread.
8+
9+
10+
Table of contents:
11+
* [Callbacks](#callbacks)
12+
* [OnTakeFocus](#ontakefocus)
13+
* [OnSetFocus](#onsetfocus)
14+
* [OnGotFocus](#ongotfocus)
15+
16+
17+
## Callbacks
18+
19+
20+
### OnTakeFocus
21+
22+
| Parameter | Type |
23+
| --- | --- |
24+
| browser | [Browser](Browser.md) |
25+
| next | bool |
26+
| __Return__ | void |
27+
28+
Description from upstream CEF:
29+
> Called when the browser component is about to loose focus. For instance, if
30+
> focus was on the last HTML element and the user pressed the TAB key. |next|
31+
> will be true if the browser is giving focus to the next component and false
32+
> if the browser is giving focus to the previous component.
33+
34+
35+
### OnSetFocus
36+
37+
| Parameter | Type |
38+
| --- | --- |
39+
| browser | [Browser](Browser.md) |
40+
| source | cef_focus_source_t |
41+
| __Return__ | bool |
42+
43+
Description from upstream CEF:
44+
> Called when the browser component is requesting focus. |source| indicates
45+
> where the focus request is originating from. Return false to allow the
46+
> focus to be set or true to cancel setting the focus.
47+
48+
The `cef_focus_source_t` enum constants in the cefpython module:
49+
* FOCUS_SOURCE_NAVIGATION (The source is explicit navigation
50+
via the API (LoadURL(), etc))
51+
* FOCUS_SOURCE_SYSTEM (The source is a system-generated focus event)
52+
53+
54+
### OnGotFocus
55+
56+
| Parameter | Type |
57+
| --- | --- |
58+
| browser | [Browser](Browser.md) |
59+
| __Return__ | void |
60+
61+
Description from upstream CEF:
62+
> Called when the browser component has received focus.

api/cefpython.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ browser.SetClientCallback("OnLoadEnd", OnLoadEnd)
7474
| traceObject | - |
7575
| __Return__ | string |
7676

77-
Global except hook to exit app cleanly on error.
78-
77+
Global except hook to exit app cleanly on error. CEF has a multiprocess
78+
architecture and when exiting you need to close all processes (main Browser
79+
process, Renderer process, GPU process, etc.) by calling Shutdown().
7980
This hook does the following: in case of exception write it to
8081
the "error.log" file, display it to the console, shutdown CEF
8182
and exit application immediately by ignoring "finally" (_exit()).

examples/gtk.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
from gi.repository import GdkX11, Gtk, GObject, GdkPixbuf
77
import sys
88
import os
9-
import time
109

1110

1211
def main():
13-
version_info()
12+
print("CEF Python {ver}".format(ver=cef.__version__))
13+
print("Python {ver}".format(ver=sys.version[:6]))
14+
print("GTK {major}.{minor}".format(
15+
major=Gtk.get_major_version(),
16+
minor=Gtk.get_minor_version()))
17+
assert cef.__version__ >= "53.1", "CEF Python v53.1+ required to run this"
18+
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
19+
cef.Initialize()
1420
app = GtkExample()
1521
SystemExit(app.run(sys.argv))
1622

1723

18-
def version_info():
19-
print("CEF Python "+cef.__version__)
20-
print("Python "+sys.version[:6])
21-
print("GTK %s.%s" % (Gtk.get_major_version(), Gtk.get_minor_version()))
22-
23-
2424
class GtkExample(Gtk.Application):
2525

2626
def __init__(self):
@@ -29,7 +29,6 @@ def __init__(self):
2929
self.window = None
3030

3131
def run(self, argv):
32-
cef.Initialize()
3332
GObject.threads_init()
3433
GObject.timeout_add(10, self.on_timer)
3534
self.connect("activate", self.on_activate)
@@ -54,7 +53,6 @@ def on_activate(self, *_):
5453
window_info.SetAsChild(self.window.get_property("window").get_xid())
5554
self.browser = cef.CreateBrowserSync(window_info,
5655
url="https://www.google.com/")
57-
self.window.get_property("window").focus(False)
5856
self.window.show_all()
5957

6058
def on_configure(self, *_):
@@ -73,13 +71,9 @@ def on_focus_in(self, *_):
7371
return False
7472

7573
def on_window_close(self, *_):
76-
# Close browser and free reference
74+
# Close browser and free reference by setting to None
7775
self.browser.CloseBrowser(True)
78-
del self.browser
79-
# Give the browser some time to close before calling cef.Shutdown()
80-
for i in range(10):
81-
cef.MessageLoopWork()
82-
time.sleep(0.01)
76+
self.browser = None
8377

8478
def on_shutdown(self, *_):
8579
cef.Shutdown()

examples/hello_world.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55

66

77
def main():
8-
"""Main entry point."""
9-
version_info()
10-
sys.excepthook = cef.ExceptHook
8+
print("CEF Python {ver}".format(ver=cef.__version__))
9+
print("Python {ver}".format(ver=sys.version[:6]))
10+
assert cef.__version__ >= "53.1", "CEF Python v53.1+ required to run this"
11+
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
1112
cef.Initialize()
1213
browser = cef.CreateBrowserSync(url="https://www.google.com/")
1314
browser.SetClientHandler(ClientHandler())
1415
cef.MessageLoop()
1516
cef.Shutdown()
1617

1718

18-
def version_info():
19-
print("CEF Python "+cef.__version__)
20-
print("Python "+sys.version[:6])
21-
22-
23-
class ClientHandler:
19+
class ClientHandler(object):
2420

2521
def OnBeforeClose(self, browser):
2622
"""Called just before a browser is destroyed."""

examples/resources/back.png

1.32 KB
Loading

examples/resources/forward.png

1.28 KB
Loading

examples/resources/reload.png

1.39 KB
Loading

examples/resources/tkinter.png

6.12 KB
Loading

0 commit comments

Comments
 (0)