88
99from cefpython3 import cefpython as cef
1010
11- import pygtk
12- import gtk
1311import sys
1412import os
1513import time
14+ if sys .platform == 'linux' :
15+ import pygtk
16+ import gtk
17+ pygtk .require ('2.0' )
18+ elif sys .platform == 'darwin' :
19+ import gi
20+ gi .require_version ("Gtk" , "3.0" )
21+ from gi .repository import Gtk
22+ elif sys .platform == 'win32' :
23+ # no gtk needed on Windows
24+ pass
1625
1726from kivy .app import App
1827from kivy .uix .button import Button
2837# Global variables
2938g_switches = None
3039
31- # PyGTK required
32- pygtk .require ('2.0' )
33-
3440
3541class BrowserLayout (BoxLayout ):
3642
@@ -150,9 +156,6 @@ def start_cef(self):
150156
151157 # Configure CEF
152158 settings = {
153- # This directories must be set on Linux
154- "locales_dir_path" : cef .GetModuleDirectory ()+ "/locales" ,
155- "resources_dir_path" : cef .GetModuleDirectory (),
156159 "browser_subprocess_path" : "%s/%s" % (
157160 cef .GetModuleDirectory (), "subprocess" ),
158161 "windowless_rendering_enabled" : True ,
@@ -161,7 +164,15 @@ def start_cef(self):
161164 "enabled" : False ,
162165 },
163166 "external_message_pump" : False , # See Issue #246
167+ "multi_threaded_message_loop" : False ,
164168 }
169+ if sys .platform == 'linux' :
170+ # This directories must be set on Linux
171+ settings ["locales_dir_path" ] = cef .GetModuleDirectory () + "/locales"
172+ settings ["resources_dir_path" ] = cef .GetModuleDirectory ()
173+ if sys .platform == 'darwin' :
174+ settings ["external_message_pump" ] = True # Temporary fix for Issue #246
175+
165176 switches = {
166177 # Tweaking OSR performance by setting the same Chromium flags
167178 # as in upstream cefclient (# Issue #240).
@@ -190,18 +201,21 @@ def start_cef(self):
190201 # Start idle - CEF message loop work.
191202 Clock .schedule_once (self ._message_loop_work , 0 )
192203
204+ windowInfo = cef .WindowInfo ()
205+
193206 # TODO: For printing to work in off-screen-rendering mode
194207 # it is enough to call gtk_init(). It is not required
195208 # to provide window handle when calling SetAsOffscreen().
196209 # However it still needs to be tested whether providing
197210 # window handle is required for mouse context menu and
198211 # popup widgets to work.
199- gtkwin = gtk .Window ()
200- gtkwin .realize ()
201-
202212 # WindowInfo offscreen flag
203- windowInfo = cef .WindowInfo ()
204- windowInfo .SetAsOffscreen (gtkwin .window .xid )
213+ if sys .platform == 'linux' :
214+ gtkwin = gtk .Window ()
215+ gtkwin .realize ()
216+ windowInfo .SetAsOffscreen (gtkwin .window .xid )
217+ elif sys .platform == 'darwin' or sys .platform == 'win32' :
218+ windowInfo .SetAsOffscreen (0 )
205219
206220 # Create Broswer and naviagte to empty page <= OnPaint won't get
207221 # called yet
@@ -519,12 +533,12 @@ def get_windows_key_code(self, kivycode):
519533
520534 def go_forward (self , * _ ):
521535 """Going to forward in browser history."""
522- print "go forward"
536+ print ( "go forward" )
523537 self .browser .GoForward ()
524538
525539 def go_back (self , * _ ):
526540 """Going back in browser history."""
527- print "go back"
541+ print ( "go back" )
528542 self .browser .GoBack ()
529543
530544 def reload (self , * _ ):
@@ -864,7 +878,7 @@ def OnLoadingStateChange(self, is_loading, **_):
864878 def OnPaint (self , element_type , paint_buffer , ** _ ):
865879 # print "OnPaint()"
866880 if element_type != cef .PET_VIEW :
867- print "Popups aren't implemented yet"
881+ print ( "Popups aren't implemented yet" )
868882 return
869883
870884 # FPS meter ("fps" arg)
0 commit comments