[wxPython] Navigating between panels

Thanks for the help. I was sort of conflicted between keeping track of the panels, or creating them on the fly. I think I may give this a chance. Thanks for the quick response! :slight_smile:

-Lori

Raul Cota <cota@ucalgary.ca> 01/11/02 03:59PM >>>

I do that a lot in the application I'm working on.
In few lines, this is basically how I do it

#self.paramPanel is the currently displayed panel
oldPanel = self.paramPanel
oldPanel.Destroy()

#Create the new panel according to the tree node
self.paramPanel = createTheNewPanel(self.splitter)
self.splitter.ReplaceWindow(oldPanel, self.paramPanel)

As you can see, I don't keep alive the panels that I don't display. I
crete them and destroy them all the time. This process is pretty fast
and avoids keeping alive many panels in case you have a lot of nodes in
the tree.
Works for me

Raul

Lori Hongach wrote:

···

     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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users