Hi
To give a summary of the issue:
In this app there is Frame containing a Mainpanel which in turn
contains - panel1 and panel2.
panel1 (a scrollable one) is populated with 'n' number of buttons.
On clicking each of the above button information shows up in panel 2
with widgets on it
The problem is after the widgets are placed on panel 2, the latter is redrawn
But the Frame or the toplevel window does not redraw inspite of
enforcing Layout() method on it and therefore does not display the
panels at its new size.
Please find the code below
Thanks
#!/usr/bin/python
import pdb
import wx.lib.scrolledpanel as scrolled
import wx.lib.inspection
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, - 1, "My Frame")
self.buildPage2Panel1()
def buildPage2Panel1(self):
self.i = 20
self.ButtonList = {}
self.j = 0
self.Mainpanel = wx.Panel(self, - 1)
self.Mainpanel.SetBackgroundColour("black")
self.panel1 = scrolled.ScrolledPanel(self.Mainpanel, - 1)
self.panel1.SetBackgroundColour("green")
self.panelbuttonSizer = wx.GridSizer(rows= self.i,cols = 1)
for self.j in xrange(0,self.i):
self.ButtonList[self.j] = self.j
self.ButtonList[self.j]=(wx.Button(self.panel1,-1,"button " + str(self.j)))
self.panelbuttonSizer.Add(self.ButtonList[self.j])
self.Bind(wx.EVT_BUTTON, self.printbuttontext, self.ButtonList[self.j])
self.panel1.SetSizer(self.panelbuttonSizer)
self.panel1.SetupScrolling()
self.panel2 = wx.Panel(self.Mainpanel, - 1)
self.panel2.SetBackgroundColour("light blue")
#self.sizer holds panel 1 and panel 2
self.sizer = wx.GridSizer(rows=1, cols=2)
self.sizer.Add(self.panel1,2,wx.EXPAND)
self.sizer.Add(self.panel2,2,wx.EXPAND)
#self.MainSizer holds self.sizer
self.Mainsizer = wx.BoxSizer(wx.HORIZONTAL)
self.Mainsizer.Add(self.sizer,2,wx.EXPAND)
self.Mainpanel.SetSizer(self.Mainsizer)# Tell self.panel1
which sizer to use!
def printbuttontext(self,event):
for widget in self.panel2.GetChildren():
try:
widget.Destroy()
except:
pass
temp = ''
for keys in self.ButtonList.keys():
if self.ButtonList[keys] == event.GetEventObject():
temp = keys
self.panel2Label = wx.StaticText(self.panel2,wx.ID_ANY,"Button
"+str(temp), style=wx.ALIGN_CENTRE)
self.panel2Text = wx.TextCtrl(self.panel2,wx.ID_ANY,size = (300,-1))
self.p2wSizer = wx.BoxSizer( wx.HORIZONTAL)
self.p2wSizer.Add(self.panel2Label,0,wx.ALL,20)
self.p2wSizer.Add(self.panel2Text,0,wx.ALL,20)
self.panel2.SetSizer(self.p2wSizer)
# self.p2wSizer.Fit(self.panel2)
self.panel1.Layout()
self.panel2.Layout()
self.Mainpanel.Layout()
self.Layout()
if __name__ == '__main__':
print wx.version()
app = wx.App(False)
frame = MyFrame()
frame.Show(True)
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()