|
1 | | -# An example of embedding CEF in wxPython application. |
| 1 | +# An example of embedding CEF browser in wxPython on Linux. |
2 | 2 |
|
3 | 3 | import platform |
4 | 4 | if platform.architecture()[0] != "32bit": |
5 | 5 | raise Exception("Only 32bit architecture is supported") |
6 | 6 |
|
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) |
15 | 12 | if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000: |
16 | 13 | import cefpython_py27 as cefpython |
17 | | - elif sys.hexversion >= 0x03000000 and sys.hexversion < 0x04000000: |
18 | | - import cefpython_py32 as cefpython |
19 | 14 | else: |
20 | 15 | raise Exception("Unsupported python version: %s" % sys.version) |
21 | | -except ImportError: |
22 | | - # Import from package (installer). |
| 16 | +else: |
| 17 | + # Import from package |
23 | 18 | from cefpython1 import cefpython |
24 | | -""" |
25 | 19 |
|
26 | 20 | import wx |
27 | 21 | import time |
28 | 22 |
|
29 | 23 | # Which method to use for message loop processing. |
30 | 24 | # EVT_IDLE - wx application has priority (default) |
31 | 25 | # 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. |
36 | 31 | USE_EVT_IDLE = False |
37 | 32 |
|
38 | 33 | def GetApplicationPath(file=None): |
@@ -73,35 +68,33 @@ class MainFrame(wx.Frame): |
73 | 68 | browser = None |
74 | 69 | initialized = False |
75 | 70 | idleCount = 0 |
| 71 | + box = None |
76 | 72 |
|
77 | 73 | def __init__(self): |
78 | 74 | wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, |
79 | 75 | title='wxPython example', size=(600,400)) |
80 | 76 | self.CreateMenu() |
81 | 77 |
|
82 | 78 | windowInfo = cefpython.WindowInfo() |
83 | | - windowInfo.SetAsChild(self.GetWindowHandle()) |
| 79 | + windowInfo.SetAsChild(self.GetGtkWidget()) |
84 | 80 | print("wxpython.py: creating browser in a moment") |
85 | 81 | # Linux requires adding "file://" for local files, |
86 | 82 | # otherwise /home/some will be replaced as http://home/some |
87 | 83 | self.browser = cefpython.CreateBrowserSync( |
88 | 84 | windowInfo, |
89 | 85 | 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") |
92 | 88 |
|
93 | | - # Remains of windows code: |
| 89 | + # Remains of OS_WIN code: |
94 | 90 | #self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) |
95 | 91 | #self.Bind(wx.EVT_SIZE, self.OnSize) |
96 | | - |
| 92 | + |
97 | 93 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
98 | 94 | if USE_EVT_IDLE: |
99 | 95 | # Bind EVT_IDLE only for the main application frame. |
100 | 96 | self.Bind(wx.EVT_IDLE, self.OnIdle) |
101 | 97 |
|
102 | | - def GetWindowHandle(self): |
103 | | - return self.GetGtkWidget() |
104 | | - |
105 | 98 | def CreateMenu(self): |
106 | 99 | filemenu = wx.Menu() |
107 | 100 | filemenu.Append(1, "Open") |
|
0 commit comments