Notebook image bug on win32, working on GNU/Linux and Mac OSX
Frank Aune
frank.aune at broadpark.no
Wed Sep 19 09:02:46 PDT 2007
Hello,
This is probably far-fetched without a minimal runable example, but
here goes ... I have a fairly large program, which lets the users
enable and disable notebook tabs dynamically in any order they see
fit. (Think of tabbed browsing using a web browser - The first
notebook tab can never be disabled though. It is always present) The
notebook and imagelist is created like this in the application:
self.il = wx.ImageList(32,32)
self.il.Add(wx.Bitmap('img%simg1.png' % os.sep, wx.BITMAP_TYPE_PNG))
self.nb = xrc.XRCCTRL(self.frame, 'main_notebook')
self.nb.SetImageList(self.il)
self.nb.SetPageImage(0,0) # (page, image)
Then I have some additional tabs which hooks themselves up during
launch. Each tab is defined inside a python class, so they get the
reference to the main app in their constructor, here called parent:
# self.panel is this class' notebook panel
# self.title is the title for this tab
tabOrder = self.parent.nb.GetPageCount() # Get the first available
tab index
self.parent.il.Add(wx.Bitmap('img%simgname.png' % os.sep,
wx.BITMAP_TYPE_PNG) # Add my image to imagelist
self.parent.nb.InsertPage(tabOrder, self.panel, self.title) # Add
myself to the notebook
self.parent.nb.SetPageImage(tabOrder, tabOrder) # Set my image from
imagelist
self.parent.nb.Refresh() # fix win32 redraw bug?
For removing tabs, I use the following code, also present inside the
python class defining the tab:
for i in range(self.parent.nb.GetPageCount()):
if self.parent.nb.GetPageText(i) == self.title:
self.parent.il.Remove(i)
self.parent.nb.DeletePage(i)
self.parent.nb.Refresh() # fix win32 redraw bug
Both code blocks above exist in a tab superclass which each tab class
inherrit.
This is where it gets interesting. The above works 100% on both GNU/
Linux Kubuntu Feisty Fawn using wx-2.8 and python2.5 from the default
repositories, and Mac OSX 10.4 using python2.5 and the latest wx as
of this date.
But on Win32 otoh, using also python2.5 and the latest wx, I get very
strange behavior. Most of the time the second tab shows up without an
image, while the rest have images. But adding and removing tabs in
random order will eventually trigger a new effect where random tabs
might loose their image also. And the effect is "contagious" because
if you keep adding/removing tabs in random order, they will all but
the first one eventually end up without an image.
(On an interesting (but probably unrelated) note: If I delete the
page from the notebook before removing the image from the imagelist
(that is; the reverse of what I do above in the last code section),
the application will misbehave on all plattforms in another way: Then
the wrong image will be mapped to different tabs when removing tabs etc)
Could anyone theorize or think out aloud what might be making these
rather strange effects Im experiencing on Win32, based on the
provided info?
Best regards,
Frank
More information about the wxpython-users
mailing list