Would some of you mind telling me if I’m missing out on anything important relating to layout, sizer implementation, etc. in following bit of test code - just using this to try figure out if it will actually render something like a data capture UI as I want it to - readable, clean, in order/sequence, etc. etc. - and, yes, this is just test code thus far, based on tutorial material, so, no, won’t all make sense - for example, the accessible_output.speech.Speaker implementation is my form of spoken debug information rendering, and I am sort of dynamically rendering lots of test controls just for test purposes thus far:
#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.Maximize()
self.Show()
self.SetWindowStyle(self.GetWindowStyle() + wx.VSCROLL)
#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)
panel = wx.Panel(self)
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, 15):
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])
#add all statics and controls to fgs
sOut = str(len(lStatics)) + " statics " + str(len(lControls)) + " controls"
#self.spk.output(sOut)
fgs = wx.FlexGridSizer(rows=len(lStatics), cols=2, 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, border=10)
#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_RIGHT|wx.RIGHT, border=10)
panel.SetSizer(vBox)
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), 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)
#end of tellPos
#end of class Example
if name == ‘main’:
app = wx.App()
Example(None, title=“Lots of fields/controls”)
app.MainLoop()
#end code
And, part of why am asking here is that current, sighted test user isn’t terribly technical, so not easiest to ask/get answers for questions ask them about interface etc.
(lastly, while normally work with tab character for indentation, since that operates bit better along with my screenreader software, I did a search/replace to use 4 space characters in above code sample - hope worked alright)
TIA
Jacob Kruger
Blind Biker
Skype: BlindZA
‘…fate had broken his body, but not his spirit…’