Hi. I am fairly new to wxPython, so please forgive me if I am overlooking something simple. I am trying to write an application which is similiar in look to the demo. (I do not use a notebook on the right.) On the left, I have a tree, which the user can traverse, and there is a wxPanel on the right hand side. Here is what I am trying to accomplish:
(1) The user starts up the app
(2) The app creates a wxPanel object for every leaf of the tree
(3) When the user click a different leaf in the tree, I was attempting to replace the right side of the splitter window with the appropriate panel.
Here is a snippet of my code from the main app.
<snip>
.......
···
#---------------------------------------------
# Set up a splitter for the main window
#---------------------------------------------
self.splitter = wxSplitterWindow(self, -1, style=wxSP_3D)
def EmptyHandler(evt): pass
EVT_ERASE_BACKGROUND(self.splitter, EmptyHandler)
#---------------------------------------------
# Prevent TreeCtrl from displaying all items after destruction
#---------------------------------------------
self.dying = false
#---------------------------------------------
# Set up the initial right side of the app
#---------------------------------------------
self.rPanel = wxPanel(self.splitter, -1)
self.rPanel.SetBackgroundColour(wxWHITE)
#---------------------------------------------
# Create our panels
#---------------------------------------------
self.one = wxPanel(self.splitter, -1)
self.one.SetBackgroundColour(wxBLACK)
self.two = wxPanel(self.splitter, -1)
self.two.SetBackgroundColour(wxRED)
#---------------------------------------------
# Create a TreeCtrl
#---------------------------------------------
tID = wxNewId()
self.treeMap = {}
self.tree = wxTreeCtrl(self.splitter, tID, style=wxTR_HAS_BUTTONS |
wxTR_EDIT_LABELS |
wxTR_HAS_VARIABLE_ROW_HEIGHT | wxSUNKEN_BORDER)
self.tree.SetBackgroundColour(wxNamedColour("AQUAMARINE"))
root = self.tree.AddRoot("Main Process")
firstChild = None
self.releaseTreeItems = {}
for item in _treeList:
child = self.tree.AppendItem(root, item[0])
if not firstChild: firstChild = child
for childItem in item[1]:
theTool = self.tree.AppendItem(child, childItem)
self.treeMap[childItem] = theTool
self.releaseTreeItems[childItem] = theTool
self.tree.Expand(child)
self.tree.Expand(root)
#---------------------------------------------
# Catch tree events
#---------------------------------------------
EVT_TREE_SEL_CHANGED (self.tree, tID, self.OnSelChanged)
#---------------------------------------------
# Select initial items
#---------------------------------------------
self.tree.SelectItem(root)
#---------------------------------------------
# Set up the splitter to have the tree on the left, and the panel
# on the right
#---------------------------------------------
self.splitter.SplitVertically(self.tree, self.rPanel)
self.splitter.SetSashPosition(195, true)
self.splitter.SetMinimumPaneSize(20)
....
</snip>
The following function will get called when the user clicks on a leaf:
<snip>
def OnSelChanged(self, event):
if self.dying:
return
#---------------------------------------------
# Grab the item id, and use it to retrieve the text
#---------------------------------------------
item = event.GetItem()
itemText = self.tree.GetItemText(item)
#---------------------------------------------
# Call the appropriate object
#---------------------------------------------
self.rightWindow = self.mysplitter.GetWindow2()
if itemText == 'One':
self.mysplitter.ReplaceWindow(self.rightWindow, self.onePanel)
if itemText == 'Two':
self.mysplitter.ReplaceWindow(self.rightWindow, self.twoPanel)
</snip>
If I click on the "One" tree leaf, I see the black screen. Then if I click on the "Two" tree leaf, I see the red screen (like I would expect to see). After that, no matter what I click on, the second (red) panel always seems to be on top, and I will never see the first panel again.
Any insight/help would be greatly appreciated.
Thanks in advance,
Lori