Layout() method enforced partially only

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()

Calling someWindow.Layout() does not change the size of someWindow, only the position and/or size of the children of the someWindow. If you want the frame to be resized when the content within the frame changes then you need to tell it to do so. An easy way with your sample code is to put the Mainpanel in a sizer and then call self.Fit() when the content changes.

layout.py (2.52 KB)

···

On 2/2/11 5:53 AM, Madhu Subramaniam wrote:

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.

--
Robin Dunn
Software Craftsman

The work around which i am found today is to give the size (biggest
that can be) manually to the toplevel window/Frame. Can the same be
enforced using a wx statement?

Thanks
Madhu

···

On Feb 2, 6:53 pm, Madhu Subramaniam <madhu.subraman...@gmail.com> wrote:

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 = &#39;&#39;
    for keys in self\.ButtonList\.keys\(\):
            if self\.ButtonList\[keys\] == event\.GetEventObject\(\):
                    temp = keys
    self\.panel2Label = wx\.StaticText\(self\.panel2,wx\.ID\_ANY,&quot;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()

Can what be enforced? Setting the size? Calculating the size? Not letting the user change the size?

···

On 2/2/11 9:33 PM, ARMS wrote:

The work around which i am found today is to give the size (biggest
that can be) manually to the toplevel window/Frame. Can the same be
enforced using a wx statement?

--
Robin Dunn
Software Craftsman

Calculating and setting the size of the toplevel window/frame is what
i meant.
thanks for your input.
I will also be coding samples with each sizer in wxpython so that i
understand them better.

···

On Feb 3, 4:29 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 2/2/11 9:33 PM, ARMS wrote:

> The work around which i am found today is to give the size (biggest
> that can be) manually to the toplevel window/Frame. Can the same be
> enforced using a wx statement?

Can what be enforced? Setting the size? Calculating the size? Not
letting the user change the size?

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

If the frame has a sizer then you can use frame.Fit(). Or doing something like this would work too if the frame contains just one panel:

  frame.SetClientSize(panel.GetBestSize())

···

On 2/4/11 9:22 AM, ARMS wrote:

Calculating and setting the size of the toplevel window/frame is what
i meant.

--
Robin Dunn
Software Craftsman