Hide/Show sizers using ShowItems method

Hello!
I am trying to use the ShowItems method of wx.Sizers to hide/show
sizers content (running code at the end of the post). I bind a
function (OnAdd) to a button (addButton) to show the contents again.
However, it misplaces the contents. I designed the frame first, so
before hiding the sizers everything was properly placed. I've been
struggling with it most of the day, but I haven't been able to solve
it. Can anyone help?
Cheers!

Dani

import wx, MySQLdb, wx.lib.intctrl, time, datetime, wx.grid
from wx.lib import masked

class SpeciesSightDlg(wx.Dialog):
   def __init__(self):
      EnglishSpeciesHeader = wx.Font(20, wx.DEFAULT, wx.NORMAL,
wx.BOLD, False, u'Times New Roman')
      ScientificSpeciesHeader = wx.Font(20, wx.DEFAULT, wx.ITALIC,
wx.BOLD, False, u'Times New Roman')
      EnglishName = 'Moustached Warbler'
      ScientificName = 'Acrocephalus melanopogon'
      wx.Dialog.__init__(self, None, -1,title = 'Enter species data',
size=(600,700))
      panel = wx.ScrolledWindow(self, -1)
      panel.SetScrollbars(20,20,55,40)
      vbox = wx.BoxSizer(wx.VERTICAL)
   #Define sizers
      #Horizontal sizers
      hbox1 = wx.BoxSizer(wx.HORIZONTAL)
      hbox2 = wx.BoxSizer(wx.HORIZONTAL)
      hbox3 = wx.BoxSizer(wx.HORIZONTAL)
      hbox4 = wx.BoxSizer(wx.HORIZONTAL)
      self.hbox5 = wx.BoxSizer(wx.HORIZONTAL)
      self.hbox6 = wx.BoxSizer(wx.HORIZONTAL)
      self.hbox7 = wx.BoxSizer(wx.HORIZONTAL)
      hbox14 = wx.BoxSizer(wx.HORIZONTAL)
      ScientificName = wx.StaticText(panel, -1, ScientificName)
      ScientificName.SetFont(ScientificSpeciesHeader)
      EnglishName = wx.StaticText(panel, -1, EnglishName)
      EnglishName.SetFont(EnglishSpeciesHeader)
      self.CountKindTXT1 = wx.StaticText(panel, -1, 'Kind of
count',size=(150, -1))
      self.CountKindCombo1 = wx.ComboBox(panel, -1,size=(150, -1),
choices=['Not counted','Exact count','At least','Approximation'],
style = wx.CB_READONLY, value = 'Not counted')
      self.IndividualsTXT1 = wx.StaticText(panel, -1,
'Number',size=(70, -1))
      self.Individuals1 = masked.NumCtrl(panel, integerWidth=5,
allowNegative=False,size=(70, -1))
      self.AgeTXT1 = wx.StaticText(panel, -1, 'Age',size=(125, -1))
      self.AgeCombo1 = wx.ComboBox(panel, -1,size=(125, -1),
choices=['Adult','Nesting','Juvenile', 'Unmature','1st year','2nd
year','3rd year','4th year','5th year', 'Unknown'], style =
wx.CB_READONLY, value = 'Unknown')
      self.SexTXT1 = wx.StaticText(panel, -1, 'Sex',size=(100, -1))
      self.SexCombo1 = wx.ComboBox(panel, -1,size=(100, -1),
choices=['Male', 'Female', 'Unknown'], style = wx.CB_READONLY, value =
'Unknown')
      imageFile = wx.ArtProvider.GetBitmap(wx.ART_ADD_BOOKMARK,
wx.ART_BUTTON, (16, 16))
      self.addBtn1 = wx.BitmapButton(panel, id=-1, bitmap=imageFile,
pos=(10, 20), size = (30,30))
      self.addBtn1.Bind(wx.EVT_BUTTON, self.OnAdd1, self.addBtn1)
      self.Notes1 = wx.TextCtrl(panel, -1,size=(515, 75),
style=wx.TE_MULTILINE, value = '')
      self.CountKindTXT2 = wx.StaticText(panel, -1, 'Kind of
count',size=(150, -1))
      self.CountKindCombo2 = wx.ComboBox(panel, -1,size=(150, -1),
choices=['Not counted','Exact count','At least','Approximation'],
style = wx.CB_READONLY, value = 'Not counted')
      self.IndividualsTXT2 = wx.StaticText(panel, -1,
'Number',size=(70, -1))
      self.Individuals2 = masked.NumCtrl(panel, integerWidth=5,
allowNegative=False,size=(70, -1))
      self.AgeTXT2 = wx.StaticText(panel, -1, 'Age',size=(125, -1))
      self.AgeCombo2 = wx.ComboBox(panel, -1,size=(125, -1),
choices=['Adult','Nesting','Juvenile', 'Unmature','1st year','2nd
year','3rd year','4th year','5th year', 'Unknown'], style =
wx.CB_READONLY, value = 'Unknown')
      self.SexTXT2 = wx.StaticText(panel, -1, 'Sex',size=(100, -1))
      self.SexCombo2 = wx.ComboBox(panel, -1,size=(100, -1),
choices=['Male', 'Female', 'Unknown'], style = wx.CB_READONLY, value =
'Unknown')
      self.addBtn2 = wx.BitmapButton(panel, id=-1, bitmap=imageFile,
pos=(10, 20), size = (30,30))
      self.Notes2 = wx.TextCtrl(panel, -1,size=(515, 75),
style=wx.TE_MULTILINE, value = '')
      submitBtn = wx.Button(panel, -1, 'Submit')
   #Merge sizers
      hbox1.Add(EnglishName, 0, wx.ALL, 5)
      hbox1.Add(ScientificName, 0, wx.ALL, 5)
      hbox2.Add(self.CountKindTXT1, 0, wx.ALL, 5)
      hbox2.Add(self.IndividualsTXT1, 0, wx.ALL, 5)
      hbox2.Add(self.AgeTXT1, 0, wx.ALL, 5)
      hbox2.Add(self.SexTXT1, 0, wx.ALL, 5)
      hbox3.Add(self.CountKindCombo1, 0, wx.ALL, 5)
      hbox3.Add(self.Individuals1, 0, wx.ALL, 5)
      hbox3.Add(self.AgeCombo1, 0, wx.ALL, 5)
      hbox3.Add(self.SexCombo1, 0, wx.ALL, 5)
      hbox3.Add(self.addBtn1, 0, wx.ALL, 5)
      hbox4.Add(self.Notes1, 0, wx.ALL, 5)
      self.hbox5.Add(self.CountKindTXT2, 0, wx.ALL, 5)
      self.hbox5.Add(self.IndividualsTXT2, 0, wx.ALL, 5)
      self.hbox5.Add(self.AgeTXT2, 0, wx.ALL, 5)
      self.hbox5.Add(self.SexTXT2, 0, wx.ALL, 5)
      self.hbox6.Add(self.CountKindCombo2, 0, wx.ALL, 5)
      self.hbox6.Add(self.Individuals2, 0, wx.ALL, 5)
      self.hbox6.Add(self.AgeCombo2, 0, wx.ALL, 5)
      self.hbox6.Add(self.SexCombo2, 0, wx.ALL, 5)
      self.hbox6.Add(self.addBtn2, 0, wx.ALL, 5)
      self.hbox7.Add(self.Notes2, 0, wx.ALL, 5)
      hbox14.Add(submitBtn, 0, wx.ALL, 5)
      vbox.Add(hbox1, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(hbox2, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(hbox3, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(hbox4, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(self.hbox5, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(self.hbox6, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(self.hbox7, 0, wx.ALIGN_LEFT | wx.ALL, 5)
      vbox.Add(hbox14, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
      self.hbox5.ShowItems(False)
      self.hbox6.ShowItems(False)
      self.hbox7.ShowItems(False)
      panel.SetSizer(vbox)
      self.Centre()
      self.Show(True)
   def OnAdd1(self,event):
      self.hbox5.ShowItems(True)
      self.hbox6.ShowItems(True)
      self.hbox7.ShowItems(True)

app = wx.App()
SpeciesSightDlg()
app.MainLoop()

Try calling the Layout() method of either the sizer that owns the ones you are hiding/showing, or the window that is the parent of the items being shown. If that doesn't work then see #7 at MakingSampleApps - wxPyWiki

···

On 9/23/10 9:50 AM, acrocephalus wrote:

Hello!
I am trying to use the ShowItems method of wx.Sizers to hide/show
sizers content (running code at the end of the post). I bind a
function (OnAdd) to a button (addButton) to show the contents again.
However, it misplaces the contents. I designed the frame first, so
before hiding the sizers everything was properly placed. I've been
struggling with it most of the day, but I haven't been able to solve
it. Can anyone help?

--
Robin Dunn
Software Craftsman

Thank you so much! Calling the Layout method of the parent window worked great!
Cheers!

Dani

···

On 09/23/2010 10:11 PM, Robin Dunn wrote:

On 9/23/10 9:50 AM, acrocephalus wrote:

Hello!
I am trying to use the ShowItems method of wx.Sizers to hide/show
sizers content (running code at the end of the post). I bind a
function (OnAdd) to a button (addButton) to show the contents again.
However, it misplaces the contents. I designed the frame first, so
before hiding the sizers everything was properly placed. I've been
struggling with it most of the day, but I haven't been able to solve
it. Can anyone help?

Try calling the Layout() method of either the sizer that owns the ones you are hiding/showing, or the window that is the parent of the items being shown. If that doesn't work then see #7 at MakingSampleApps - wxPyWiki

--
Daniel Valverde Saub�
c/Joan Maragall 37 4 2
17002 Girona
Spain
Tel�fon m�bil: +34651987662
e-mail: dani.valverde@gmail.com
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no �s del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudar�s a estalviar aigua, energia i recursos forestals. GR�CIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!