Skip to content

Commit 36c0759

Browse files
committed
wxPython example is working, binaries updated. To make it
work with wxPython on Linux it was required to make changes in CEF C++ sources, a patch is in the linux directory.
1 parent 78b5f8d commit 36c0759

File tree

4 files changed

+93
-46
lines changed

4 files changed

+93
-46
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
See this topic on CEF C++ forum for more details about this CEF
2+
patch to make it work with wxPython on Linux:
3+
http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10641
4+
5+
Do the following changes in CEF C++ sources:
6+
7+
1. CefBrowserImpl::UIT_CreateBrowser() in `libcef/browser_impl_gtk.cc`
8+
9+
Add this code at the end of the function:
10+
11+
gtk_widget_show_all(GTK_WIDGET(window_info_.m_Widget));
12+
13+
2. WebWidgetHostGtkWidget::CreateNewWidget() in `libcef/webwidget_host_gtk.cc`
14+
15+
Replace this line:
16+
17+
gtk_box_pack_start(GTK_BOX(parent_view), widget, TRUE, TRUE, 0);
18+
19+
With this code:
20+
21+
if (GTK_IS_BOX(parent_view)) {
22+
gtk_box_pack_start(GTK_BOX(parent_view), widget, TRUE, TRUE, 0);
23+
} else {
24+
// Parent view shouldn't contain any children, but in wxWidgets library
25+
// there will be GtkPizza widget for Panel or any other control.
26+
GList *children, *iter;
27+
children = gtk_container_get_children(GTK_CONTAINER(parent_view));
28+
GtkWidget* child = NULL;
29+
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
30+
for (iter = children; iter != NULL; iter = g_list_next(iter)) {
31+
child = GTK_WIDGET(iter->data);
32+
// We will have to keep a reference to that child that we remove,
33+
// otherwise we will get lots of warnings like "invalid unclassed
34+
// pointer in cast to `GtkPizza'". First we increase a reference,
35+
// we need to do this for a moment before we add this child to the
36+
// vbox, then we will decrease that reference.
37+
g_object_ref(G_OBJECT(child));
38+
gtk_container_remove(GTK_CONTAINER(parent_view), child);
39+
}
40+
g_list_free(children);
41+
gtk_box_pack_start(GTK_BOX(vbox), widget, TRUE, TRUE, 0);
42+
if (child != NULL) {
43+
// This child is packed to the box only so that its reference lives,
44+
// as it might be referenced from other code thus resulting in errors.
45+
gtk_box_pack_end(GTK_BOX(vbox), child, FALSE, FALSE, 0);
46+
gtk_widget_hide(GTK_WIDGET(child));
47+
g_object_unref(G_OBJECT(child));
48+
}
49+
gtk_widget_show(GTK_WIDGET(vbox));
50+
if (GTK_IS_SCROLLED_WINDOW(parent_view))
51+
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(parent_view), vbox);
52+
else
53+
gtk_container_add(GTK_CONTAINER(parent_view), vbox);
54+
}

cefpython/cef1/linux/binaries/pygtk_.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
# An example of embedding CEF in PyGTK application.
1+
# An example of embedding CEF browser in PyGTK on Linux.
22

33
import platform
44
if platform.architecture()[0] != "32bit":
55
raise Exception("Only 32bit architecture is supported")
66

7-
import ctypes, os
8-
ctypes.CDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so'), ctypes.RTLD_GLOBAL)
9-
import cefpython_py27 as cefpython
10-
11-
import sys
12-
13-
"""
14-
try:
15-
# Import local PYD file (portable zip).
7+
import ctypes, os, sys
8+
libcef_so = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so')
9+
if os.path.exists(libcef_so):
10+
# Import local module
11+
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1612
if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
1713
import cefpython_py27 as cefpython
18-
elif sys.hexversion >= 0x03000000 and sys.hexversion < 0x04000000:
19-
import cefpython_py32 as cefpython
2014
else:
2115
raise Exception("Unsupported python version: %s" % sys.version)
22-
except ImportError:
23-
# Import from package (installer).
16+
else:
17+
# Import from package
2418
from cefpython1 import cefpython
25-
"""
2619

2720
import pygtk
2821
pygtk.require('2.0')
2922
import gtk
3023
import gobject
31-
import ctypes
3224
import re
3325

3426
def GetApplicationPath(file=None):
@@ -101,9 +93,9 @@ def __init__(self):
10193

10294
# Must be show_all() for VBox otherwise browser doesn't
10395
# appear when you just call show().
104-
self.vbox.show_all()
96+
self.vbox.show()
10597

106-
self.mainWindow.show()
98+
self.mainWindow.show()
10799
gobject.timeout_add(10, self.OnTimer)
108100

109101
def CreateMenu(self):

cefpython/cef1/linux/binaries/wxpython.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
# An example of embedding CEF in wxPython application.
1+
# An example of embedding CEF browser in wxPython on Linux.
22

33
import platform
44
if platform.architecture()[0] != "32bit":
55
raise Exception("Only 32bit architecture is supported")
66

7-
import ctypes, os
8-
ctypes.CDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so'), ctypes.RTLD_GLOBAL)
9-
import cefpython_py27 as cefpython
10-
11-
import sys
12-
"""
13-
try:
14-
# Import local PYD file (portable zip).
7+
import ctypes, os, sys
8+
libcef_so = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so')
9+
if os.path.exists(libcef_so):
10+
# Import local module
11+
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1512
if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
1613
import cefpython_py27 as cefpython
17-
elif sys.hexversion >= 0x03000000 and sys.hexversion < 0x04000000:
18-
import cefpython_py32 as cefpython
1914
else:
2015
raise Exception("Unsupported python version: %s" % sys.version)
21-
except ImportError:
22-
# Import from package (installer).
16+
else:
17+
# Import from package
2318
from cefpython1 import cefpython
24-
"""
2519

2620
import wx
2721
import time
2822

2923
# Which method to use for message loop processing.
3024
# EVT_IDLE - wx application has priority (default)
3125
# EVT_TIMER - cef browser has priority
32-
# From the tests it seems that Flash content behaves
33-
# better when using a timer.
34-
35-
# IMPORTANT! On Linux CPU goes 100% when using EVT_IDLE, why?
26+
# It seems that Flash content behaves better when using a timer.
27+
# IMPORTANT! On Linux EVT_IDLE does not work, the events seems to
28+
# be propagated only when you move your mouse, which is not the
29+
# expected behavior, it is recommended to use EVT_TIMER on Linux,
30+
# so set this value to False.
3631
USE_EVT_IDLE = False
3732

3833
def GetApplicationPath(file=None):
@@ -73,35 +68,33 @@ class MainFrame(wx.Frame):
7368
browser = None
7469
initialized = False
7570
idleCount = 0
71+
box = None
7672

7773
def __init__(self):
7874
wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
7975
title='wxPython example', size=(600,400))
8076
self.CreateMenu()
8177

8278
windowInfo = cefpython.WindowInfo()
83-
windowInfo.SetAsChild(self.GetWindowHandle())
79+
windowInfo.SetAsChild(self.GetGtkWidget())
8480
print("wxpython.py: creating browser in a moment")
8581
# Linux requires adding "file://" for local files,
8682
# otherwise /home/some will be replaced as http://home/some
8783
self.browser = cefpython.CreateBrowserSync(
8884
windowInfo,
8985
browserSettings={},
90-
navigateUrl="file://"+GetApplicationPath("cefsimple.html")))
91-
print("wxpython.py: browser created, handle = %s" % self.GetWindowHandle())
86+
navigateUrl="file://"+GetApplicationPath("cefsimple.html"))
87+
print("wxpython.py: browser created")
9288

93-
# Remains of windows code:
89+
# Remains of OS_WIN code:
9490
#self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
9591
#self.Bind(wx.EVT_SIZE, self.OnSize)
96-
92+
9793
self.Bind(wx.EVT_CLOSE, self.OnClose)
9894
if USE_EVT_IDLE:
9995
# Bind EVT_IDLE only for the main application frame.
10096
self.Bind(wx.EVT_IDLE, self.OnIdle)
10197

102-
def GetWindowHandle(self):
103-
return self.GetGtkWidget()
104-
10598
def CreateMenu(self):
10699
filemenu = wx.Menu()
107100
filemenu.Append(1, "Open")

cefpython/cef1/linux/setup/setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,24 @@ def CompileTimeConstants():
5050
r'./',
5151
r'./../../v8function_handler/',
5252
r'./../../client_handler/',
53-
r'./../../../cpp_utils/',
53+
r'./../../../cpp_utils/'
5454
],
5555

5656
libraries=[
5757
'cef_dll_wrapper',
5858
'v8function_handler',
5959
'client_handler',
60-
'cpp_utils'
60+
'cpp_utils'
6161
],
6262

63+
"""
64+
Loading libcef.so will only work when running scripts from the same
65+
directory that libcef.so resides in when you put "./" in here.
66+
runtime_library_dirs=[
67+
'./'
68+
],
69+
"""
70+
6371
# /EHsc - using STL string, multimap and others that use C++ exceptions.
6472
extra_compile_args=[],
6573

0 commit comments

Comments
 (0)