Error in deleting page from Notebook in wxPython

Hi,

I am using wxPython 2.6.3.2 on my Fedora Core 6 and has a problem in delete page from a Notebook. Here’s the code:

#!/usr/bin/env python
import wx, wx.grid
app = wx.App()
frame = wx.Frame(None)
notebook = wx.Notebook(frame, -1, size=(450, 300) )
page = wx.grid.Grid(notebook, -1)
page.CreateGrid(5,3)
notebook.AddPage(page, ‘table1’)
page = wx.grid.Grid(notebook, -1)
page.CreateGrid(5,3)
notebook.AddPage(page, ‘table2’)
print ‘Current page is %d ("%s") before deleting’ % (notebook.GetSelection(), notebook.GetPageText(notebook.GetSelection()))
notebook.DeletePage(0)
print ‘Current page is %d ("%s") after deleting’ % (notebook.GetSelection(), notebook.GetPageText(notebook.GetSelection()))
frame.Show(True)
app.MainLoop()

The output is:

Current page is 0 (“table1”) before deleting
(python:19198): Gtk-CRITICAL **: gtk_container_remove: assertion `GTK_IS_TOOLBAR (container) || widget->parent == GTK_WIDGET (container)’ failed
Current page is 1 ("") after deleting

But the output is correct on windows with wxPython 2.8.9.2:

Current page is 0 (“table1”) before deleting

Current page is 0 (“table2”) after deleting

Does that mean a bug in wxPython 2.6.3.2? Or anybody know a solution for this?
I want to try it with wxPython 2.8.9.2 on Linux, but so far I failed to install it.

Thanks,

York.

York Lee wrote:

Hi,

I am using wxPython 2.6.3.2 on my Fedora Core 6 and has a problem in delete page from a Notebook. Here's the code:

#!/usr/bin/env python
import wx, wx.grid
app = wx.App()
frame = wx.Frame(None)
notebook = wx.Notebook(frame, -1, size=(450, 300) )
page = wx.grid.Grid(notebook, -1)
page.CreateGrid(5,3)
notebook.AddPage(page, 'table1')
page = wx.grid.Grid(notebook, -1)
page.CreateGrid(5,3)
notebook.AddPage(page, 'table2')
print 'Current page is %d ("%s") before deleting' % (notebook.GetSelection(), notebook.GetPageText(notebook.GetSelection()))
notebook.DeletePage(0)
print 'Current page is %d ("%s") after deleting' % (notebook.GetSelection(), notebook.GetPageText(notebook.GetSelection()))
frame.Show(True)
app.MainLoop()

The output is:

Current page is 0 ("table1") before deleting
(python:19198): Gtk-CRITICAL **: gtk_container_remove: assertion `GTK_IS_TOOLBAR (container) || widget->parent == GTK_WIDGET (container)' failed
Current page is 1 ("") after deleting

But the output is correct on windows with wxPython 2.8.9.2 <http://2.8.9.2>:

Current page is 0 ("table1") before deleting
Current page is 0 ("table2") after deleting

Does that mean a bug in wxPython 2.6.3.2?

It's possible, but more likely it's because the MainLoop hasn't started at the time that you are are removing pages. Some things in wxGTK are not fully initialized until the next iteration of the main event loop.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!