Dynamically remove rows in an interface

Hello,
I am trying to dynamically remove rows on an interface that have been added also dynamically. The method OnButtonRemoveRow is where I’m trying to remove a row.
Here’s a stripped down version of my code:

class TestPanel(wx.Panel):
def init(self, parent, log):
self.log = log
self.frame = parent
wx.Panel.init(self, parent, -1)

    mainLayout = self.mainLayout = wx.FlexGridSizer(cols=1, hgap=10, vgap=10)
   
    #count variable for the number of rows added by user
    self.countrows = 0
    browsers = self.browsers = ['Internet Explorer 6.0','Firefox 2.0','Safari 3.0']
    iepaths = ['test1','test2']
   
    rowNum = self.rowNum = []
    ieLayout = self.ieLayout = wx.FlexGridSizer(cols=1, hgap=10, vgap=10)
    row0 = self.row0 = wx.FlexGridSizer(cols=8, hgap=10, vgap=10)
    rowNum.append(row0)
    ieLayout.Add(row0)
    mainLayout.Add(ieLayout)
   
    row0.Add(wx.StaticText(self, -1, "Browser:"))
    self.browselect = []
    self.browselect.append(wx.Choice(self, -1, choices=browsers))
    row0.Add(self.browselect[0])
   
    row0.Add(wx.StaticText(self, -1, "User:"))
    self.iecc = []
    self.iecc.append(wx.Choice(self, -1, choices=iepaths))
    row0.Add(self.iecc[0])
   
    b = wx.Button(self, -1, "Add Row", (50,50))
    self.Bind(wx.EVT_BUTTON, self.OnButtonAddRow, b)
    mainLayout.Add(b)
   
    box = wx.BoxSizer()
    box.Add(mainLayout, 1, wx.EXPAND|wx.ALL, 20)
    self.SetSizer(box)
           
    buttonLayout = wx.FlexGridSizer(cols=5, hgap=10, vgap=10)
    mainLayout.Add(buttonLayout)
    b = wx.Button(self, -1, "Run", (50,50))
    self.Bind(wx.EVT_BUTTON, self.OnButtonRun, b)
    buttonLayout.Add(b)
   
    b = wx.Button(self, -1, "Close", (50,50))
    self.Bind(wx.EVT_BUTTON, self.OnButtonClose, b)
    buttonLayout.Add(b)
   
def OnButtonAddRow(self, evt):
    self.countrows += 1
    row1 = wx.FlexGridSizer(cols=8, hgap=10, vgap=10)
    self.rowNum.append(row1)
    row1.Add(wx.StaticText(self, -1, "Browser:"))
    self.browselect.append(wx.Choice(self, -1, choices=self.browsers))
    row1.Add(self.browselect[self.countrows])

    row1.Add(wx.StaticText(self, -1, "User:"))
    iepaths = ['test1','test2']
    self.iecc.append(wx.Choice(self, -1, choices=iepaths))
    row1.Add(self.iecc[self.countrows])

    b = wx.Button(self, -1, "Remove Row", (50,50))
    self.Bind(wx.EVT_BUTTON, self.OnButtonRemoveRow, b)
    row1.Add(b)
    self.ieLayout.Add(row1)
    self.Layout()
           
def OnButtonRun(self, evt):
    pass
   
def OnButtonRemoveRow(self, evt):
    #print self.rowNum[1]
    #d = self.rowNum.pop()
    del self.rowNum[1]
    self.countrows -= 1
    #self.rowNum[1] = ''
    #print self.rowNum[1]
    self.Layout()
   
def OnButtonClose(self, evt):
    dlg = wx.MessageDialog(self, "Are you sure you want to exit?", "Exit", wx.YES_NO | wx.ICON_QUESTION)
    if dlg.ShowModal() == wx.ID_YES:
        self.frame.Close()
    dlg.Destroy()

Any suggestions greatly appreciated.

Dennon McMillan wrote:

Hello,
  I am trying to dynamically remove rows on an interface that have been added also dynamically. The method OnButtonRemoveRow is where I'm trying to remove a row.

You are storing a sizer in your self.rowNum list, so once you get the sizer to be removed you can call its DeleteWindows method, and then remove that sizer from the main sizer it is a member of.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!