Sorry it took so long. Busy bee. Here's a short script which suffers the
same problem on my machine (black background on a wxTreeCtrl until a
dialog is opened).
···
On (12/01/04 15:46), Robin Dunn wrote:
Nothing looks wrong. Please distil the problem into a small runnable
sample and I'll take a closer look.
===================================================================
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
"""
Demonstration of wxTreeCtrl problem.
On my machine (python 2.3.3, wxPython 2.4.2.4), the background
of the wxTreeCtrl in MyPanel is black, not white. Opening a child
dialog and closing it solves the problem: the wxTreeCtrl background
changes to white.
The wxPython demo doesn't have this problem.
"""
import sys
import os
from wxPython.wx import *
from random import choice, seed, randint
seed()
class MyPanel(wxPanel):
"""View for each file. Inserted as pages into panel"""
def __init__(self, parent):
self.parent = parent
wxPanel.__init__(self, parent, -1)
sizer = wxBoxSizer(wxVERTICAL)
ID_TREE = wxNewId()
# images
sz = (16, 16)
self.imagelist = wxImageList(sz[0],sz[1])
self.bmp_tick = self.imagelist.Add(wxArtProvider_GetBitmap(
wxART_TICK_MARK, wxART_OTHER, sz))
self.bmp_cross = self.imagelist.Add(wxArtProvider_GetBitmap(
wxART_CROSS_MARK, wxART_OTHER, sz))
self.tree = wxTreeCtrl(self, ID_TREE,
style=wxTR_EDIT_LABELS|wxTR_HAS_BUTTONS)
self.tree.SetImageList(self.imagelist)
self.populate_tree()
sizer.Add(self.tree, 1, wxEXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(1)
self.Layout()
EVT_SIZE(self, self.on_size)
def on_size(self, evt):
w,h = self.GetClientSizeTuple()
self.tree.SetDimensions(0,0,w,h)
def populate_tree(self):
"""Add something to the tree. Anything."""
words = ['woo','yay','foo','bar','monkey',
'badger','jawohl','achtung','spanner','moon']
self.root = self.tree.AddRoot(choice(words))
self.tree.SetItemImage(self.root, self.bmp_tick)
self.tree.SelectItem(self.root)
for x in range(5):
child = self.tree.AppendItem(self.root, choice(words))
self.tree.SetItemImage(child, self.bmp_tick)
for i in range(randint(2,5)):
node = self.tree.AppendItem(child, choice(words))
self.tree.SetItemImage(node, self.bmp_cross)
self.tree.Expand(child)
self.tree.Expand(self.root)
class MyFrame(wxFrame):
"""Main application window"""
def __init__(self):
wxFrame.__init__(self, None, -1, "Series Manager",
size=(500, 600), name="Series Manager")
# menu
ID_OPEN = wxNewId()
menubar = wxMenuBar()
menu = wxMenu()
menu.Append(ID_OPEN, "&Open...\tCtrl+O",
"Open an existing file")
menubar.Append(menu, "&File")
self.SetMenuBar(menubar)
EVT_MENU(self, ID_OPEN, self.on_open)
# sizer setup
sizer = wxBoxSizer(wxVERTICAL)
# notebook
ID_NOTEBOOK = wxNewId()
self.notebook = wxNotebook(self, ID_NOTEBOOK)
self.panel = MyPanel(self.notebook)
self.notebook.AddPage(self.panel, "Panel 1")
# finish off setting up sizer
sizer.Add(self.notebook, 1, wxEXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(1)
self.Layout()
def on_open(self, evt):
"""I added this because opening a child dialog causes the
wxTreeCtrl to be the right colour again, i.e. white."""
wildcard = "XML Files (*.xml)|*.xml|"\
"All files (*.*)|*.*|"
dlg = wxFileDialog(self, "Choose a file to open",
os.getcwd(), "", wildcard, style=wxOPEN)
dlg.ShowModal()
dlg.Destroy()
class MyApp(wxApp):
def OnInit(self):
return 1
def main(argv=None):
if not argv:
argv = sys.argv[1:]
app = MyApp()
win = MyFrame()
win.Show(1)
app.SetTopWindow(win)
app.MainLoop()
if __name__ == '__main__':
sys.exit(main())