wxTreeCtrl on wxPanel has black background

Hi,

I'm trying to show a wxTreeCtrl on a wxPanel in a wxNotebook. Pages
inserted when the app is starting have a black background. After a
dialog has been opened, they all get their white backgrounds back.

I'm using 2.4.2.4 on Python 2.3.2 on Debian unstable.

Here are the relevant parts of the code:

def new_page(self, series):
  ip = SeriesPanel(self.notebook, series)
  self.notebook.InsertPage(0, p, series.title, select=1)

def __init__(self, parent, series):
  self.parent = parent
  self.series = series
  wxPanel.__init__(self, parent, -1)
  sizer = wxBoxSizer(wxVERTICAL)
  ID_TREE = wxNewId()
  # images
  sz = (16, 16)
  self.imagelist = wxImageList(sz[0],sz[1])
  self.bmptick = self.imagelist.Add(wxArtProvider_GetBitmap(wxART_TICK_MARK,
    wxART_OTHER, sz))
  self.bmpcross = self.imagelist.Add(wxArtProvider_GetBitmap(wxART_CROSS_MARK,
      wxART_OTHER, sz))
  self.status_images = [self.bmpcross, self.bmptick]
  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)

Can anyone offer any pointers?

Cheers,

Dave

Dave Richards wrote:

Hi,

I'm trying to show a wxTreeCtrl on a wxPanel in a wxNotebook. Pages
inserted when the app is starting have a black background. After a
dialog has been opened, they all get their white backgrounds back.

I'm using 2.4.2.4 on Python 2.3.2 on Debian unstable.

Here are the relevant parts of the code:

[...]

Can anyone offer any pointers?

Nothing looks wrong. Please distil the problem into a small runnable sample and I'll take a closer look.

···

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

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).

listctrl.py

···

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())

Dave Richards wrote:

···

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.

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).

"""
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.
"""

It behaves fine for me. Have you tried it after having removed your .gtkrc file so no themes are used?

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

That fixed it. Strange that I should have this problem, but the demo
doesn't. I can't tell the difference...

Thanks a lot for your help.

Regards

Dave

···

On (15/01/04 10:22), Robin Dunn wrote:

>"""
>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.
>"""

It behaves fine for me. Have you tried it after having removed your
.gtkrc file so no themes are used?