I am trying to build a dialog box which dynamically modifies
(adds to) itself by adding a varying number of Static Text And wxTextCntrl
boxes to itself, depending on a choice made from a wxChoice box
in the Dialog box.
The mechanics of the dynamic building process work fine but I'm
having a problem with the layout of the dynamic part of the dialog
box. I've tried to provide some pseudo code below to outline my method.
What I'm trying to do is build the dynamic control button set in a
wxFlexGridSizer and adding this to the oOuterBoxSizer wxBoxSizer in
the original Dialog box
The basic process works but the problem is :
I make a choice from the wxChoice box and build the first dynamic
button set - this in itself works fine
Now, if I make another choice in wxChoice straight afterwards (without
closing the whole dialog box) the new configuration of the dymnamic part
of the Diaglog box is constructed ok, but the first choice I made is still
visible (partially) underneath the new choice. (by putting the cursor into
the corrupted wxTextCtrl box reveals the old version and its value is
still in the main Dialog box, but underneath).
Any help appreciated as theres been a fair bit of head scratching going off
over it
many thanks
Wayne
class myDialogBox(wxDialog)
# outer dialog sizer
self.oOuterBoxSizer = wxBoxSizer(wxVERTICAL)
# Instatiate Grid Box Sizer
# 1 row other items to be added later
oGridBox = wxFlexGridSizer(1, 2, 2, 2) # rows, cols, hgap, vgap
# build wxChoice Dialog
self.ch = wxChoice(self, self.iId+1, (80, 50), choices = myChoices)
# highlight the first selection
self.ch.SetSelection(0)
# add and event mapper
EVT_CHOICE(self, self.iId+1, self.mEvtChoice)
oGridBox.AddMany([(label,0, wxEXPAND | wxALL, 5), (self.ch, 0, wxEXPAND |
wxALL, 5)])
# Add Grid to Outer Box Sizer
self.oOuterBoxSizer.Add(oGridBox, 0, wxALIGN_LEFT)
# sizer use to add dynamic controls in mEvtChoice
self.oBitFieldsGridBox = None
# do other stuff and show dialog
def mEvtChoice(self, event):
# get choice box selection
# create new window id
self.iFieldId = NewId()
# a choice has been made already remove the oBitFieldsGridBox from the
dialog
if(self.oBitFieldsGridBox) :
self.oOuterBoxSizer.Remove(self.oBitFieldsGridBox)
# dynamically build the contents of oBitFieldsGridBox
if("dialog box requires more than one control box") :
# Instatiate Grid Box Sizer
self.oBitFieldsGridBox = wxFlexGridSizer(bitNumberOfControls, 2, 2, 2)
# build bit field windows
for i in range(bitNumberOfControls):
self.iFieldId = NewId()
label = StaticText(self, -1, "this control text description")
# create a text contrl box with default value in it
self.tc = wxTextCtrl(self, self.iFieldId+i, "this control default
value")
EVT_TEXT(self, self.iFieldId+i, self.mBitFieldSettings)
self.oBitFieldsGridBox.AddMany([(label,0, wxEXPAND | wxALL, 5),
(self.tc, 0, wxEXPAND | wxALL, 5)])
# add completed bit fields definitions to the outer sizer
self.oOuterBoxSizer.Add(self.oBitFieldsGridBox, 0, wxALIGN_LEFT)
# one control box required
else : #if(bitDescriptionsLength==0) :
self.oBitFieldsGridBox = wxFlexGridSizer(1, 2, 2, 2)
label = StaticText(self, -1, "this control default value")
# create a text contrl box with default value in it
self.tc = wxTextCtrl(self, self.iFieldId, "0x0000")
EVT_TEXT(self, self.iId+2, self.mBitFieldSettings)
self.oBitFieldsGridBox.AddMany([(label,0, wxEXPAND | wxALL, 5), (self.tc,
0, wxEXPAND | wxALL, 5)])
# Add Grid to Outer Box Sizer
self.oOuterBoxSizer.Add(self.oBitFieldsGridBox, 0, wxALIGN_LEFT)
self.oOuterBoxSizer.Fit(self)
self.oOuterBoxSizer.Layout()
self.oOuterBoxSizer.SetSizeHints(self)