How to change panels/windows

Martin, you are recreating a new panel each time you select an item.
I've modified you code such that the StaticText control is placed on the
right panel in __init__ and set the label to "". Then all you have to do
is update the label in your OnSelected method. I didn't notice any
flicker on my end, try the attached sample and see if it works for you.

-Kyle Rickey

wxtest.py (1.68 KB)

···

-----Original Message-----
From: martin-schmitz@web.de [mailto:martin-schmitz@web.de]
Sent: Wednesday, February 27, 2008 8:20 AM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] How to change panels/windows

Hello list,

I want to have a wx.SplitterWindow with a wx.ListCtrl on the left and a
panel on the right where details about the selected entry in the list
on the left are displayed. Every time a new item is selected in the
list, the details display on the right should be exchanged.

What I tried is basically this:

    # sp = SplitterWindow, rp = right Panel, lp = left Panel
    def OnSelected(self, event):
        self.item = event.GetItem().GetData()
        oldPanel = self.rp
        newPanel = wx.Panel(self.sp)
        newPanel.SetBackgroundColour('#ffffdd')
        self.rsizer = wx.BoxSizer(wx.VERTICAL)
        self.text = wx.StaticText(newPanel, -1, "Selected: %s" % \
            self.item) self.rsizer.Add(self.text, 1, wx.EXPAND)
        self.sp.ReplaceWindow(self.rp, newPanel)
        newPanel.SetSizer(self.rsizer)
        self.rp.Destroy()
        self.rp = newPanel

It works perfectly well, despite the fact that everytime the new Panel
is created (everytime a new entry is selected), I see the new Panel
flickering in sight at the top left corner of my frame. This doesn't
look well and is quite annoying to me.

I tried various ways to update the right panel, removing and adding it
from/to the sizer for example. But everytime a line like
"spam = wx.Panel(parent)" is called, the new panel immediatly appears
on the top left corner of the frame.

So, how am I supposed to update/exchange a wx.Panel/wx.Window without
flickering on screen?

Attached is a full minimal version of my program which shows the
problem.

TIA,
Martin

Yes, that way seem's more appropriate. The problem that I see is that
the elements displayed in the right panel aren't the same for every
list entry. It seems to be not that easy with wx.Bitmaps for example,
especially when there is no bitmap attached to the entry (SetValue
raises an error if the value to be displayed as bitmap is empty).

For that reason I thought it would be best to create an invisible
panel, exchange it with the displayed one and destroy the old one. I
grabed the idea from the wxPython book, which says on site 253 about
wx.SplitterWindow:

    Since there isn’t a direct setter, to change a sub-window, use
    the method ReplaceWindow(winOld, winNew), where winOld is the
    wx.Window object you are replacing, and winNew is the new window to
    display.

However - although there seems to be no way to create a panel invisibly
- setting the initial size to (0,0) does the trick (later on
SetSizerAndFit gives the right size to it).

I really don't know - this is my first wxPython application...

Does this approach look somehow obscure to others who have more
experience in writing and reading wxPython? Should I try to avoid
creating new panels and exchanging them with the old ones?

Thanks a lot for your attention,
Martin

···

Am 27.02.08 schrieb "Rickey, Kyle W" <Kyle.Rickey@bakerhughes.com>:

Martin, you are recreating a new panel each time you select an item.
I've modified you code such that the StaticText control is placed on
the right panel in __init__ and set the label to "". Then all you
have to do is update the label in your OnSelected method. I didn't
notice any flicker on my end, try the attached sample and see if it
works for you.