@@ -89,9 +89,14 @@ class ChromeWindow(wx.Window):
8989 Standalone CEF component. The class provides facilites for interacting
9090 with wx message loop
9191 """
92- def __init__ (self , parent , url = "" , useTimer = False ,
93- timerMillis = DEFAULT_TIMER_MILLIS , size = (- 1 , - 1 ),
94- * args , ** kwargs ):
92+ def __init__ (self , parent , url = "" , useTimer = None ,
93+ timerMillis = DEFAULT_TIMER_MILLIS , browserSettings = None ,
94+ size = (- 1 , - 1 ), * args , ** kwargs ):
95+ if platform .system () == "Linux" and useTimer == None :
96+ # On Linux OnIdle does not work correctly, must use timer.
97+ useTimer = True
98+ useTimer = bool (useTimer )
99+
95100 wx .Window .__init__ (self , parent , id = wx .ID_ANY , size = size ,
96101 * args , ** kwargs )
97102 # On Linux absolute file urls need to start with "file://"
@@ -109,8 +114,8 @@ def __init__(self, parent, url="", useTimer=False,
109114 else :
110115 raise Exception ("Unsupported OS" )
111116
112- # TODO: allow for custom browser settings for the ChromeWindow
113- browserSettings = {}
117+ if not browserSettings :
118+ browserSettings = {}
114119
115120 # Disable plugins:
116121 # | browserSettings["plugins_disabled"] = True
@@ -170,18 +175,37 @@ def LoadUrl(self, url, onLoadStart=None, onLoadEnd=None):
170175 if onLoadStart or onLoadEnd :
171176 self .GetBrowser ().SetClientHandler (
172177 CallbackClientHandler (onLoadStart , onLoadEnd ))
178+
179+ browser = self .GetBrowser ()
180+ if cefpython .g_debug :
181+ print ("***** ChromeCtrl: LoadUrl() self: %s" % self )
182+ print ("***** ChromeCtrl: browser: %s" % browser )
183+ print ("***** ChromeCtrl: browser id: %s" % browser .GetIdentifier ())
184+ print ("***** ChromeCtrl: mainframe: %s" % browser .GetMainFrame ())
185+ print ("***** ChromeCtrl: mainframe id: %s" % \
186+ browser .GetMainFrame ().GetIdentifier ())
173187 self .GetBrowser ().GetMainFrame ().LoadUrl (url )
174188
189+ #wx.CallLater(100, browser.ReloadIgnoreCache)
190+ #wx.CallLater(200, browser.GetMainFrame().LoadUrl, url)
191+
175192
176193class ChromeCtrl (wx .Panel ):
177- def __init__ (self , parent , url = "" , useTimer = False ,
178- timerMillis = DEFAULT_TIMER_MILLIS , hasNavBar = True ,
194+ def __init__ (self , parent , url = "" , useTimer = None ,
195+ timerMillis = DEFAULT_TIMER_MILLIS ,
196+ browserSettings = None , hasNavBar = True ,
179197 * args , ** kwargs ):
198+ if platform .system () == "Linux" and useTimer == None :
199+ # On Linux OnIdle does not work correctly, must use timer.
200+ useTimer = True
201+ useTimer = bool (useTimer )
202+
180203 # You also have to set the wx.WANTS_CHARS style for
181204 # all parent panels/controls, if it's deeply embedded.
182205 wx .Panel .__init__ (self , parent , style = wx .WANTS_CHARS , * args , ** kwargs )
183206
184- self .chromeWindow = ChromeWindow (self , url = str (url ), useTimer = useTimer )
207+ self .chromeWindow = ChromeWindow (self , url = str (url ), useTimer = useTimer ,
208+ browserSettings = browserSettings )
185209 sizer = wx .BoxSizer (wx .VERTICAL )
186210 self .navigationBar = None
187211 if hasNavBar :
@@ -280,30 +304,30 @@ def OnLoadStart(self, browser, frame):
280304 def OnLoadEnd (self , browser , frame , httpStatusCode ):
281305 self .parentCtrl .OnLoadEnd (browser , frame , httpStatusCode )
282306
283- def OnLoadError (self , browser , frame , errorCode , failedUrl , errorText ):
307+ def OnLoadError (self , browser , frame , errorCode , errorText , failedUrl ):
284308 # TODO
285- print ("ERROR LOADING URL : %s" % failedUrl )
309+ print ("***** ChromeCtrl: ERROR LOADING URL : %s" % failedUrl )
286310
287311class CallbackClientHandler (object ):
288312 def __init__ (self , onLoadStart = None , onLoadEnd = None ):
289- self .onLoadStart = onLoadStart
290- self .onLoadEnd = onLoadEnd
313+ self ._onLoadStart = onLoadStart
314+ self ._onLoadEnd = onLoadEnd
291315
292316 def OnLoadStart (self , browser , frame ):
293- if self .onLoadStart and frame .GetUrl () != "about:blank" :
294- self .onLoadStart (browser , frame )
317+ if self ._onLoadStart and frame .GetUrl () != "about:blank" :
318+ self ._onLoadStart (browser , frame )
295319
296320 def OnLoadEnd (self , browser , frame , httpStatusCode ):
297- if self .onLoadEnd and frame .GetUrl () != "about:blank" :
298- self .onLoadEnd (browser , frame , httpStatusCode )
321+ if self ._onLoadEnd and frame .GetUrl () != "about:blank" :
322+ self ._onLoadEnd (browser , frame , httpStatusCode )
299323
300- def OnLoadError (self , browser , frame , errorCode , failedUrl , errorText ):
324+ def OnLoadError (self , browser , frame , errorCode , errorText , failedUrl ):
301325 # TODO
302- print ("ERROR LOADING URL : %s" % failedUrl )
326+ print ("***** ChromeCtrl: ERROR LOADING URL : %s, %s " % ( failedUrl , frame . GetUrl ()) )
303327
304328#-------------------------------------------------------------------------------
305329
306- def Initialize (settings = None ):
330+ def Initialize (settings = None , debug = False ):
307331 """Initializes CEF, We should do it before initializing wx
308332 If no settings passed a default is used
309333 """
@@ -327,11 +351,14 @@ def Initialize(settings=None):
327351
328352 # DEBUGGING options:
329353 # ------------------
330- # cefpython.g_debug = True
331- # cefpython.g_debugFile = "debug.log"
332- # settings["log_severity"] = cefpython.LOGSEVERITY_VERBOSE
333- # settings["log_file"] = "debug.log" # Set to "" to disable.
334- # settings["release_dcheck_enabled"] = True
354+ if debug :
355+ cefpython .g_debug = True
356+ cefpython .g_debugFile = "debug.log"
357+ settings ["log_severity" ] = cefpython .LOGSEVERITY_VERBOSE
358+ settings ["log_file" ] = "debug.log" # Set to "" to disable.
359+ settings ["release_dcheck_enabled" ] = True
360+ else :
361+ cefpython .g_debug = False
335362
336363 cefpython .Initialize (settings )
337364
0 commit comments