Think have now, hopefully, got it sorted with regards to implementing 4 columns across FlexGridSizer, sizing, fitting, binding, etc. etc. - if you would like to tell me if there’s anything else am missing out on…?
Also implemented it reporting positioning/dimensions of text controls into status bar for testing, FWIW.
#start code
import wx
#from accessible_output import speech
class Example(wx.Frame):
spk = None
def __init__(self, *args, **kwargs):
#self.spk = speech.Speaker()
#self.spk.output("init")
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
self.Centre()
self.CreateStatusBar()
self.SetStatusText("")
self.Fit() #* modified
self.Show()
#self.spk.output("shown")
def InitUI(self):
#self.spk.output("initUI")
try:
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
exitItem = fileMenu.Append(wx.ID_EXIT, "&Quit\tCtrl+Q", "Close the program")
menuBar.Append(fileMenu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.quitProgram, exitItem)
sizer = wx.BoxSizer() #* modified
panel = wx.Panel(self)
sizer.Add(panel, 1, wx.EXPAND) #* modified
vBox = wx.BoxSizer(wx.VERTICAL)
lStatics = []
lControls = []
#normal textboxes
for I in range(10):
lStatics.append(wx.StaticText(panel, label="text " + str(I)))
lControls.append(wx.TextCtrl(panel))
lControls[I].Bind(wx.EVT_SET_FOCUS, self.tellPos, lControls[I])
#multiline text boxes, with label above them
for I in range(5):
lStatics.append(wx.StaticText(panel, label="Multi-line " + str(I)))
lControls.append(wx.TextCtrl(panel, style=wx.TE_MULTILINE))
#radio buttons
lRBHorizontals = []
for I in range(5):
lRBHorizontals.append(wx.BoxSizer(wx.HORIZONTAL))
lRBHorizontals[I].Add(wx.RadioButton(parent=panel, id=wx.ID_ANY, label=str(I)+"1", style=wx.RB_GROUP), flag=wx.LEFT, border=10)
lRBHorizontals[I].Add(wx.RadioButton(parent=panel, id=wx.ID_ANY, label=str(I)+"2"), flag=wx.CENTER, border=10)
lRBHorizontals[I].Add(wx.RadioButton(parent=panel, id=wx.ID_ANY, label=str(I)+"3"), flag=wx.RIGHT, border=10)
lStatics.append(wx.StaticText(panel, label="radio button grouping " + str(I)))
lControls.append(lRBHorizontals[I])
#more text boxes
for I in range(11, 16):
lStatics.append(wx.StaticText(panel, label="text " + str(I)))
lControls.append(wx.TextCtrl(panel))
lControls[len(lControls)-1].Bind(wx.EVT_SET_FOCUS, self.tellPos, lControls[len(lControls)-1])
#add all statics and controls to fgs
iRows = 1
if (len(lStatics)/2) != (float(len(lStatics))/2):
iRows = len(lStatics) / 2 + 1
sOut = str(len(lStatics)) + " statics / 2 = " + str(iRows)
else:
iRows = len(lStatics) / 2
sOut = str(len(lStatics)) + " statics / 2 = " + str(iRows)
#dlg = wx.MessageDialog(parent=self, message=sOut, caption="iRows", style=wx.OK)
#dlg.ShowModal()
#dlg.Destroy()
fgs = wx.FlexGridSizer(rows=iRows, cols=4, vgap=9, hgap=25)
for I in range(len(lStatics)):
fgs.AddMany([(lStatics[I]), (lControls[I], 1, wx.EXPAND)])
#add fgs to vBox
vBox.Add(fgs, flag=wx.ALIGN_CENTER|wx.CENTER|wx.ALL, border=10) #* modified
#buttons at bottom
hBoxButtons = wx.BoxSizer(wx.HORIZONTAL)
btn1 = wx.Button(panel, label=’&Ok’, size=(70, 30))
btn1.Bind(wx.EVT_SET_FOCUS, self.tellPos, btn1)
hBoxButtons.Add(btn1)
btn2 = wx.Button(panel, label=’&Close’, size=(70, 30))
btn2.Bind(wx.EVT_SET_FOCUS, self.tellPos, btn2)
hBoxButtons.Add(btn2, flag=wx.LEFT|wx.BOTTOM, border=5)
vBox.Add(hBoxButtons, flag=wx.ALIGN_CENTER|wx.CENTER|wx.ALL, border=10) #* modified
panel.SetSizer(vBox)
self.SetSizer(sizer) #* modified
self.Bind(wx.EVT_BUTTON, self.nothingHappening, btn1)
self.Bind(wx.EVT_BUTTON, self.quitProgram, btn2)
except Exception as exc:
dlg = wx.MessageDialog(parent=self, message=str(exc.args), caption="Error message", style=wx.OK)
dlg.ShowModal()
dlg.Destroy()
#self.spk.output("exception occurred - " + str(exc))
finally:
sNada = ""
#self.spk.output("initUI done?")
#end of initUI
def nothingHappening(self, evt):
dlg = wx.MessageDialog(parent=self, message="You clicked a button", caption="Button clicked", style=wx.OK)
dlg.ShowModal()
dlg.Destroy()
#end of nothingHappening
def quitProgram(self, evt):
self.Close()
#end of quitProgram
def tellPos(self, event):
sOut = "position " + str(event.GetEventObject().Position)
sOut += " dimensions " + str(event.GetEventObject().Size)
#self.spk.output(sOut, interrupt=True)
if self.StatusBar != None: self.SetStatusText(sOut)
#end of tellPos
#end of class Example
import wx.lib.inspection
if name == ‘main’:
app = wx.App()
Example(None, title=“Lots of fields/controls”)
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()
#end code
Jacob Kruger
Blind Biker
Skype: BlindZA
‘…fate had broken his body, but not his spirit…’