Adding page dynamically to listbook

I’m on 3.0.1 on windows 7, and I am having a devil of a time adding pages to a listbook.

I have the listbook populated on construction just fine, icons and all.

But when I try to dynamically add pages to the Listbook in a function callback, I get the error

Traceback (most recent call last):
File “C:\Users\Belli\Documents\Code\XXX\plugin\plugin.py”, line 632, in activate
ITB.AddPage(self.XXXMTB, “XXX”, False, imageId = self.image_index)

File “c:\python27\lib\site-packages\wx-3.0-msw\wx_core.py”, line 13623, in AddPage
return core.BookCtrlBase_AddPage(*args, **kwargs)
wx._core.PyAssertionError:
C++ assertion “Assert failure” failed at …\src\msw\toolbar.cpp(795)
in wxToolBar::Realize(): invalid tool button bitmap

even though I have added the image file to the ImageList,
I have checked that it is an ok image (using IsOk()) , I have checked that the length of the ImageList is appropriate. This feels like a bug in wxpython.

A snip of the code used to add the new page

if os.path.exists(ico_path):
ico = wx.Bitmap(ico_path, wx.BITMAP_TYPE_PNG)
self.image_index = ITB.il.Add(ico)

else:
print ‘The image file’,ico_path,‘was not found’
self.image_index = ITB.il.Add(wx.EmptyBitmap(32,32))

#Add the panel to the inputs panel
self.NewMTB = NewToolBook(ITB)

ITB.AddPage(self.NewMTB, “New”, False, imageId = self.image_index)

Any help appreciated!

Ian Bell wrote:

I'm on 3.0.1 on windows 7, and I am having a devil of a time adding
pages to a listbook.

I have the listbook populated on construction just fine, icons and all.

But when I try to dynamically add pages to the Listbook in a function
callback, I get the error

Traceback (most recent call last):
File "C:\Users\Belli\Documents\Code\XXX\plugin\plugin.py", line 632, in
activate
ITB.AddPage(self.XXXMTB, "XXX", False, imageId = self.image_index)
File "c:\python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 13623,
in AddPage
return _core_.BookCtrlBase_AddPage(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "Assert failure" failed at
..\..\src\msw\toolbar.cpp(795) in wxToolBar::Realize(): invalid tool
button bitmap

even though I have added the image file to the ImageList, I have checked
that it is an ok image (using IsOk()) , I have checked that the length
of the ImageList is appropriate. This feels like a bug in wxpython.

Is it a listbook or a toolbook? You say the former but it looks like an error from the latter. You need to double-check that all of the images in the image list are valid. The wxToolBar::Realize method will traverse all of the tools and grab their bitmaps to add to the native toolbar.

If this doesn't point you in the direction of a fix then please create a small runnable sample application that demonstrates the problem. MakingSampleApps - wxPyWiki

···

--
Robin Dunn
Software Craftsman