Robbert 0 Newbie Poster

Hi,

I could do with some help with how to clear a panel(self.panel1) so the new buttons load in a new/clean panel(self.panel1) in the following code when either "Button One" or "Button Two" has been selected at the top of the frame.

I have tried everything I could think of and searched for but i just can't sort it. Thanks very much for any help offered - cheers.

import wx
from wx.lib.buttons import GenBitmapTextButton

DFN_MAIN_WINDOW_DEFAULT_SIZE = (920, 600)
DFN_MAIN_WINDOW_DEFAULT_TITLE = "Title"

class MyFrame(wx.Frame):
    def __init__(self, parent, id, frameTitle, frameSize):
        wx.Frame.__init__(self, parent, -1, frameTitle, size=frameSize)
        self.Center()

        self.CreateLayout()
        self.CreateButtons()


    def CreateButtons(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        myList = ([(GenBitmapTextButton(self.panel3, 10, wx.Bitmap('image.png'), 'Button One', (0, 0), (150, 30))),
                    (GenBitmapTextButton(self.panel3, 11, wx.Bitmap('image.png'), 'Button Two', (150, 0), (150, 30)))])
 
        gs = wx.GridSizer(2, 1, 3, 3)
        gs.AddMany(myList)

        countArray = myList.count('')
        print countArray
        self.panel3.buttons = wx.Panel(self.panel3, -1, size=(20, int(countArray*150)))

        sizer.Add(gs, 1, wx.EXPAND)

        self.panel3.buttons.SetSizer(sizer)

        self.Bind(wx.EVT_BUTTON, self.OnOne, id=10)
        self.Bind(wx.EVT_BUTTON, self.OnTwo, id=11)


    def OnOne(self, event):
        if self.panelMain.text:
            self.panelMain.text.Destroy()
        if self.panel1.buttons:
            self.panel1.buttons.Destroy()

        self.panelMain.text = wx.StaticText(self.panelMain, -1, "Default text 1", pos=(50, 50))

        sizer = wx.BoxSizer(wx.VERTICAL)

        myList = ([(GenBitmapTextButton(self.panel1, 20, wx.Bitmap('image.png'), 'One A', (0, 100), (150, 30))),
                    (GenBitmapTextButton(self.panel1, 21, wx.Bitmap('image.png'), 'One B', (0, 130), (150, 30)))])

        self.Bind(wx.EVT_BUTTON, self.OnOneA, id=20)
        self.Bind(wx.EVT_BUTTON, self.OnOneB, id=21)

        gs = wx.GridSizer(1, 2, 3, 3)
        gs.AddMany(myList)

        self.panel1.buttons = wx.Panel(self.panel1, -1)

        sizer.Add(gs, 1, wx.EXPAND)

        self.panel1.buttons.SetSizer(sizer)


    def OnTwo(self, event):
        if self.panelMain.text:
            self.panelMain.text.Destroy()
        if self.panel1.buttons:
            self.panel1.buttons.Destroy()

        self.panelMain.text = wx.StaticText(self.panelMain, -1, "Default text 2", pos=(50, 50))

        sizer = wx.BoxSizer(wx.VERTICAL)

        myList = ([(GenBitmapTextButton(self.panel1, 30, wx.Bitmap('image.png'), 'Two A', (0, 200), (150, 30))),
                    (GenBitmapTextButton(self.panel1, 31, wx.Bitmap('image.png'), 'Two B', (0, 230), (150, 30)))])

        self.Bind(wx.EVT_BUTTON, self.OnTwoA, id=30)
        self.Bind(wx.EVT_BUTTON, self.OnTwoB, id=31)

        gs = wx.GridSizer(1, 2, 3, 3)
        gs.AddMany(myList)

        self.panel1.buttons = wx.Panel(self.panel1, -1)

        sizer.Add(gs, 1, wx.EXPAND)

        self.panel1.buttons.SetSizer(sizer)



    def OnOneA(self, event):
        pass
    def OnOneB(self, event):
        pass
    def OnTwoA(self, event):
        pass
    def OnTwoB(self, event):
        pass
    
    def CreateLayout(self):
        self.panel1 = wx.Panel(self, -1, size=(160, 0))
        self.panel2 = wx.Panel(self, -1)
        self.panel3 = wx.Panel(self, -1, size=(0,20))

        self.panel1.SetBackgroundColour("#ffaaaa")
        self.panel2.SetBackgroundColour("#eeeeee")
        self.panel3.SetBackgroundColour("#cccccc")

        self.sizer_v = wx.BoxSizer(wx.VERTICAL)
        self.sizer_h = wx.BoxSizer(wx.HORIZONTAL)

        self.sizer_h.Add(self.panel1, proportion=0, flag=wx.EXPAND)
        self.sizer_h.Add(self.panel2, proportion=1, flag=wx.EXPAND)
        self.sizer_v.Add(self.panel3, proportion=0, flag=wx.EXPAND)
        self.sizer_v.Add(self.sizer_h, proportion=3, flag=wx.EXPAND)

        self.panelMain = wx.Panel(self.panel2, -1, size=(800,800))
        self.panelMain.text = wx.StaticText(self.panelMain, -1, "Default text 0", pos=(20,20))

        sizer = wx.BoxSizer(wx.VERTICAL)

        myList = ([(GenBitmapTextButton(self.panel1, 110, wx.Bitmap('image.png'), 'Default A', (0, 0), (150, 30))),
                    (GenBitmapTextButton(self.panel1, 111, wx.Bitmap('image.png'), 'Default B', (0, 30), (150, 30)))])
        self.Bind(wx.EVT_BUTTON, self.OnOne, id=110)
        self.Bind(wx.EVT_BUTTON, self.OnTwo, id=111)
        gs = wx.GridSizer(1, 3, 3, 3)
        gs.AddMany(myList)

        self.panel1.buttons = wx.Panel(self.panel1, -1)

        sizer.Add(gs, 1, wx.EXPAND)

        self.panel1.buttons.SetSizer(sizer)
        self.SetSizer(self.sizer_v)


class MyApp(wx.App):
    def OnInit(self):
        DisplayFrame = MyFrame(None, -1, frameTitle=DFN_MAIN_WINDOW_DEFAULT_TITLE, frameSize=DFN_MAIN_WINDOW_DEFAULT_SIZE)
        DisplayFrame.Show()
        return True

app = MyApp(redirect=False)
app.MainLoop()