How Can I Generate Right Panels in Real Time While Getting TreeCtrl Select Change EVT?

Hi everyone,

I split the window and the left panel is a treectrl. I hope the right
panel is generated according to the item value selected by
EVT_TREE_SEL_CHANGED. So I wrote a LoadRightPanel() whose main
content includes:

    self.rightpanel = wx.Panel(self.splitter, -1)
    sizer = wx.BoxSizer(wx.VERTICAL)

    LabelTitle = wx.StaticText(self.rightpanel, -1, title,
style=wx.ALIGN_CENTRE)
    LabelTitle.SetFont(wx.Font(18, wx.FONTFAMILY_DEFAULT,
wx.FONTSTYLE_NORMAL,
      wx.FONTWEIGHT_BOLD, False, 'Arial'))

    sizer.Add(LabelTitle, 0, wx.EXPAND)

    self.rightpanel.SetSizer(sizer)
    sizer.FitInside(self)

But it didn't work. The right panel showed still and the console
window warned me "Adding a window to the same sizer twice?"

I need some example/help, thanks!

Is that the only place you have this line?

Why don’t you just use wxTreebook–it seems like that is what you want. See the wxPython Demo.

Che

···

On Tue, Apr 19, 2011 at 10:32 PM, Gagiel gagielz@gmail.com wrote:

Hi everyone,

I split the window and the left panel is a treectrl. I hope the right

panel is generated according to the item value selected by

EVT_TREE_SEL_CHANGED. So I wrote a LoadRightPanel() whose main

content includes:

            self.rightpanel = wx.Panel(self.splitter, -1)

            sizer = wx.BoxSizer(wx.VERTICAL)



            LabelTitle = wx.StaticText(self.rightpanel, -1, title,

style=wx.ALIGN_CENTRE)

            LabelTitle.SetFont(wx.Font(18, wx.FONTFAMILY_DEFAULT,

wx.FONTSTYLE_NORMAL,

                    wx.FONTWEIGHT_BOLD, False, 'Arial'))





            sizer.Add(LabelTitle, 0, wx.EXPAND)

Not only one line, it just was an short example.

Actually I want to generate the right panel depending on the item-
related data (labels, radios, text input, etc).

Maybe wxListBook is a better choice, but I still prefer the TreeCtrl
looking and also I'm wondering why the function I wrote cannot work.
Any further suggestion?

···

On 4月20日, 下午1时11分, C M <cmpyt...@gmail.com> wrote:

On Tue, Apr 19, 2011 at 10:32 PM, Gagiel <gagi...@gmail.com> wrote:
> Hi everyone,

> I split the window and the left panel is a treectrl. I hope the right
> panel is generated according to the item value selected by
> EVT_TREE_SEL_CHANGED. So I wrote a LoadRightPanel() whose main
> content includes:

> self.rightpanel = wx.Panel(self.splitter, -1)
> sizer = wx.BoxSizer(wx.VERTICAL)

> LabelTitle = wx.StaticText(self.rightpanel, -1, title,
> style=wx.ALIGN_CENTRE)
> LabelTitle.SetFont(wx.Font(18, wx.FONTFAMILY_DEFAULT,
> wx.FONTSTYLE_NORMAL,
> wx.FONTWEIGHT_BOLD, False, 'Arial'))

> sizer.Add(LabelTitle, 0, wx.EXPAND)

Is that the only place you have this line?

Why don't you just use wxTreebook--it seems like that is what you want. See
the wxPython Demo.

Che

Not only one line, it just was an short example.

What I meant is, if you have the following line:

sizer.Add(LabelTitle, 0, wx.EXPAND)

two places in your code, you will get the error you see. Because you are trying to add the same window (the LabelTitle) to the sizer twice.

Actually I want to generate the right panel depending on the item-

related data (labels, radios, text input, etc).

Maybe wxListBook is a better choice, but I still prefer the TreeCtrl

Then just use Treebook. Have you looked at Treebook? It does exactly what you are wanting (as I understand you). See the demo.

looking and also I’m wondering why the function I wrote cannot work.

Without seeing all the code, who knows for sure (though I think it’s because of what I wrote above). If you write a small runnable sample, people can help you.

But just use Treebook and you’re done.

Che

···

2011/4/20 Gagiel gagielz@gmail.com