Problem with Dynamic Content Layout of a Dialog Box

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)

Hello,

When you Add or Remove from your sizer, I think you have to call Layout()
after that. Maybe you just want to Show() or Show(False)...

M. Vernier

···

-----Original Message-----
From: Wayne Ellis [mailto:we1@jennic.com]
Sent: Thursday, June 03, 2004 7:04 PM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] Problem with Dynamic Content Layout of a Dialog
Box

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)

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hello,

Thanks for the tip - I tried this and it doesn't seem to make
any difference to the problem. My removal process for taking
the dynamic grid sizer out of the main dialog is now

if(self.oBitFieldsGridBox) :
          self.oOuterBoxSizer.Remove(self.oBitFieldsGridBox)
          self.oOuterBoxSizer.Layout()

I've also tried adding the same calls when I add the GridSizer to the
window,
if(self.oBitFieldsGridBox) :
  self.oOuterBoxSizer.Remove(self.oBitFieldsGridBox)
  self.oOuterBoxSizer.Fit(self)
  self.oOuterBoxSizer.Layout()
  self.oOuterBoxSizer.SetSizeHints(self)

this doesn't fix the problem either

I think this may have been asked before when I was scanning through the
posts on the list - but is there any documentation, tutorials or examples
for this kind of dynamic sizing process. I've looked in wxPython demo
application and that contains alot of material but I couldn't find much
that related to this problem. Have I missed something in there which I could
use as a template ?

thanks

Wayne

···

-----Original Message-----
From: M. Vernier [mailto:vernie_m@epita.fr]
Sent: Thursday, June 03, 2004 7:02 PM
To: wxPython-users@lists.wxwidgets.org; we1@jennic.com
Subject: RE: [wxPython-users] Problem with Dynamic Content Layout of a
Dialog Box

  Hello,

When you Add or Remove from your sizer, I think you have to
call Layout()
after that. Maybe you just want to Show() or Show(False)...

M. Vernier