Hello!
I have a frame with some sizers in it (see code at th end for a running example). I would like to know how to repeat the sizers 2, 3 and 4 when pressing the add button. The sizers should be added before the submit button, and the control objects should have a different name because they have to be send to a MySQL database. 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 = 'Great Tit'
		ScientificName = 'Parus major'
		wx.Dialog.__init__(self, None, -1,title = 'Enter species data', size=(700,650))
		panel = wx.Panel(self, -1)
		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)
		hbox5 = wx.BoxSizer(wx.HORIZONTAL)
		ScientificName = wx.StaticText(panel, -1, ScientificName)
		ScientificName.SetFont(ScientificSpeciesHeader)
		EnglishName = wx.StaticText(panel, -1, EnglishName)
		EnglishName.SetFont(EnglishSpeciesHeader)
		CountKindTXT = wx.StaticText(panel, -1, 'Kind of count',size=(150, -1))
		CountKindCombo1 = wx.ComboBox(panel, -1,size=(150, -1), choices=['Not counted','Exact count','At least','Approximation'], style = wx.CB_READONLY, value = 'Not counted')
		IndividualsTXT = wx.StaticText(panel, -1, 'Number',size=(70, -1))
		Individuals1 = masked.NumCtrl(panel, integerWidth=5, allowNegative=False,size=(70, -1))
		AgeTXT = wx.StaticText(panel, -1, 'Age',size=(125, -1))
		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')
		SexTXT = wx.StaticText(panel, -1, 'Sex',size=(100, -1))
		SexCombo1 = wx.ComboBox(panel, -1,size=(100, -1), choices=['Male', 'Female', 'Unknown'], style = wx.CB_READONLY, value = 'Unknown')
		addBtn1 = wx.Button(panel, -1, 'Add', size = (50,-1))
		Notes1 = wx.TextCtrl(panel, -1,size=(500, 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(CountKindTXT, 0, wx.ALL, 5)
		hbox2.Add(IndividualsTXT, 0, wx.ALL, 5)
		hbox2.Add(AgeTXT, 0, wx.ALL, 5)
		hbox2.Add(SexTXT, 0, wx.ALL, 5)
		hbox3.Add(CountKindCombo1, 0, wx.ALL, 5)
		hbox3.Add(Individuals1, 0, wx.ALL, 5)
		hbox3.Add(AgeCombo1, 0, wx.ALL, 5)
		hbox3.Add(SexCombo1, 0, wx.ALL, 5)
		hbox3.Add(addBtn1, 0, wx.ALL, 5)
		hbox4.Add(Notes1, 0, wx.ALL, 5)
		hbox5.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(hbox5, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
		panel.SetSizer(vbox)
		self.Centre()
		self.Show(True)

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

Hello!
I have found a nice way to hide and then frame contents, however it is not working properly (see code at the end). I am using the ShowItems method of wx.Sizers to hide the contents in a sizer and then I bind a button to a function to show them back. However, it misplaces the controls. I've been struggling all the day with it but I haven't been able to solve it. Can anyone help?

Cheers!

Dani

#! /usr/bin/env python
# SpeciesSightDlg.py

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

Solved! I called the Layout() method of the parent window (panel) and it worked like a charm!
Cheers!

Dani

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.