Skip to content

Commit cea737c

Browse files
committed
Fixed browser cleanup in the OnClose event in the wxpython examples on Linux (Issue 107).
1 parent ee978b6 commit cea737c

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

cefpython/cef3/linux/binaries_32bit/wxpython-response.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,17 @@ def CreateMenu(self):
373373
self.SetMenuBar(menubar)
374374

375375
def OnClose(self, event):
376-
self.browser.CloseBrowser()
377-
self.Destroy()
376+
# In wx.chromectrl calling browser.CloseBrowser() and/or
377+
# self.Destroy() in OnClose is causing crashes when embedding
378+
# multiple browser tabs. The solution is to call only
379+
# browser.ParentWindowWillClose. Behavior of this example
380+
# seems different as it extends wx.Frame, while ChromeWindow
381+
# from chromectrl extends wx.Window. Calling CloseBrowser
382+
# and Destroy does not cause crashes, but is not recommended.
383+
# Call ParentWindowWillClose and event.Skip() instead. See
384+
# also Issue 107.
385+
self.browser.ParentWindowWillClose()
386+
event.Skip()
378387

379388
def OnIdle(self, event):
380389
cefpython.MessageLoopWork()
@@ -415,7 +424,7 @@ def OnExit(self):
415424
if __name__ == '__main__':
416425
sys.excepthook = ExceptHook
417426
settings = {
418-
"debug": False # cefpython debug messages in console and in log_file
427+
"debug": False, # cefpython debug messages in console and in log_file
419428
"log_severity": cefpython.LOGSEVERITY_INFO, # LOGSEVERITY_VERBOSE
420429
"log_file": GetApplicationPath("debug.log"), # Set to "" to disable.
421430
"release_dcheck_enabled": True, # Enable only when debugging.

cefpython/cef3/linux/binaries_32bit/wxpython.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,17 @@ def CreateMenu(self):
158158
self.SetMenuBar(menubar)
159159

160160
def OnClose(self, event):
161-
self.browser.CloseBrowser()
162-
self.Destroy()
161+
# In wx.chromectrl calling browser.CloseBrowser() and/or
162+
# self.Destroy() in OnClose is causing crashes when embedding
163+
# multiple browser tabs. The solution is to call only
164+
# browser.ParentWindowWillClose. Behavior of this example
165+
# seems different as it extends wx.Frame, while ChromeWindow
166+
# from chromectrl extends wx.Window. Calling CloseBrowser
167+
# and Destroy does not cause crashes, but is not recommended.
168+
# Call ParentWindowWillClose and event.Skip() instead. See
169+
# also Issue 107.
170+
self.browser.ParentWindowWillClose()
171+
event.Skip()
163172

164173
def OnIdle(self, event):
165174
cefpython.MessageLoopWork()
@@ -181,6 +190,13 @@ def GoForward(self):
181190
self.mainBrowser.GoForward()
182191

183192
def CreateAnotherBrowser(self, url=None):
193+
"""
194+
TODO: There are errors in the console when closing the window:
195+
>> Check failed: window
196+
>> Gdk: _gdk_window_destroy_hierarchy: assertion `GDK_IS_WINDOW\
197+
>> (window)' failed
198+
>> GLib-GObject: g_object_unref: assertion `G_IS_OBJECT (object)' failed
199+
"""
184200
frame = MainFrame(url=url)
185201
frame.Show()
186202

cefpython/cef3/linux/binaries_64bit/wxpython-response.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,17 @@ def CreateMenu(self):
373373
self.SetMenuBar(menubar)
374374

375375
def OnClose(self, event):
376-
self.browser.CloseBrowser()
377-
self.Destroy()
376+
# In wx.chromectrl calling browser.CloseBrowser() and/or
377+
# self.Destroy() in OnClose is causing crashes when embedding
378+
# multiple browser tabs. The solution is to call only
379+
# browser.ParentWindowWillClose. Behavior of this example
380+
# seems different as it extends wx.Frame, while ChromeWindow
381+
# from chromectrl extends wx.Window. Calling CloseBrowser
382+
# and Destroy does not cause crashes, but is not recommended.
383+
# Call ParentWindowWillClose and event.Skip() instead. See
384+
# also Issue 107.
385+
self.browser.ParentWindowWillClose()
386+
event.Skip()
378387

379388
def OnIdle(self, event):
380389
cefpython.MessageLoopWork()

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,17 @@ def CreateMenu(self):
158158
self.SetMenuBar(menubar)
159159

160160
def OnClose(self, event):
161-
self.browser.CloseBrowser()
162-
self.Destroy()
161+
# In wx.chromectrl calling browser.CloseBrowser() and/or
162+
# self.Destroy() in OnClose is causing crashes when embedding
163+
# multiple browser tabs. The solution is to call only
164+
# browser.ParentWindowWillClose. Behavior of this example
165+
# seems different as it extends wx.Frame, while ChromeWindow
166+
# from chromectrl extends wx.Window. Calling CloseBrowser
167+
# and Destroy does not cause crashes, but is not recommended.
168+
# Call ParentWindowWillClose and event.Skip() instead. See
169+
# also Issue 107.
170+
self.browser.ParentWindowWillClose()
171+
event.Skip()
163172

164173
def OnIdle(self, event):
165174
cefpython.MessageLoopWork()
@@ -181,6 +190,13 @@ def GoForward(self):
181190
self.mainBrowser.GoForward()
182191

183192
def CreateAnotherBrowser(self, url=None):
193+
"""
194+
TODO: There are errors in the console when closing the window:
195+
>> Check failed: window
196+
>> Gdk: _gdk_window_destroy_hierarchy: assertion `GDK_IS_WINDOW\
197+
>> (window)' failed
198+
>> GLib-GObject: g_object_unref: assertion `G_IS_OBJECT (object)' failed
199+
"""
184200
frame = MainFrame(url=url)
185201
frame.Show()
186202

0 commit comments

Comments
 (0)