wxPython Reload a grid in a panel
Question: I've got several classes so I prefer not to paste any code here (if that's
possible :P)

The problem: I've created a class which creates a frame, and this frame
contains a panel. In another class I've stored all my settings.

On the panel are several sizers and among other attributes, it has a grid.
This grid is build from sequence 1 on the x axis and sequence y on the y axis.

To create my panel, I've divided my code into sections (like buildLeft()
buildRight() buildTopRight() and so on which are linked to a main sizer in the
buildFrame() method).

My grid is created in the buildTopRight() section of this class. It creates
the grid by retrieving the values for sequence1 and sequence2 from the
settings object and creates a grid of the length of this sequence accordingly.
After this is done, the grid is bound to the sizer for the topRight section.

I also have a dropdown list (wx.Choice). If i select another option from this
list, I want to remove an item from my sequence 1 and sequence 2. The code to
do this already works, and the data in my settings object changes accordingly.

However, I'm not able to reload the matrix, since if i call the
buildTopRight() method again, the matrix is recreated and cropped to the
topleft side of my screen, while leaving the old matrix in place.

Please help.

On request, this is the code for building my panel:

    
    
    # import modules
    import wx
    import wx.grid
    import matrixSettings as ms
    
    # Panel class
    class ResultatenPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
    
        # link settings object
        self.matSet = self.GetGrandParent().ms
    
        # build the main sizers
        self.sizerMain = wx.BoxSizer(wx.HORIZONTAL)
        self.sizerMenu = wx.BoxSizer(wx.VERTICAL)
        self.sizerRight = wx.BoxSizer(wx.VERTICAL)
        self.sizerTopRight = wx.BoxSizer(wx.HORIZONTAL)
        self.sizerBotRight = wx.BoxSizer(wx.HORIZONTAL)
    
        # make individual parts
        self.buildMenu()
        self.buildTopRight()
        self.buildBotRight()
        self.buildRight()
    
        # build total frame
        self.buildFrame()
    

build right code (includes top and bottom right bits):

    
    
    def buildRight(self):
        self.sizerRight.Add(self.sizerTopRight, 5)
        self.sizerRight.Add(self.sizerBotRight, 2)
    

the code to build the frame:

    
    
    def buildFrame(self):
        self.sizerMain.Add(self.sizerMenu, 1)
        self.sizerMain.Add(self.sizerRight, 5, wx.EXPAND)
        self.SetSizer(self.sizerMain)
    

top right code:

    
    
    def buildTopRight(self):
        self.grid = wx.grid.Grid(self)
    
        print "buildTopRight called"
        if self.matSet.getAlgoritme() == "Needleman-Wunsch":
            self.matSet.setSeq1("-" + self.matSet.getSeq1())
            self.matSet.setSeq2("-" + self.matSet.getSeq2())
    
        # set grid
        self.grid.CreateGrid(len(self.matSet.getSeq2()), len(self.matSet.getSeq1()))
        self.grid.SetRowLabelSize(25)
        self.grid.DisableDragColSize()
        self.grid.DisableDragRowSize()
    
        # set the grid proportions accurately
        for x in range(0, len(self.matSet.getSeq1())):
            # set the grid proportions accurately
            for y in range(0, len(self.matSet.getSeq2())):
                self.grid.SetRowSize(y, 25)
                self.grid.SetRowLabelValue(y, self.matSet.getSeq2()[y].upper())
    
                self.grid.SetCellValue(y, x, "0")
                self.grid.SetReadOnly(y, x, True)
    
            self.grid.SetColSize(x, 25)
            self.grid.SetColLabelValue(x, self.matSet.getSeq1()[x].upper())
    

newly added:

    
    
        self.sizerTopRight.Clear()    
        self.sizerTopRight.Add(self.grid, 1)
    
        self.Update()
        self.Layout()
    


Answer: I know this is a not very memory friendly solution. You should hide the
current grid and create a new one:

    
    
    self.sizerTopRight.Hide(self.grid)
    self.sizerTopRight.Add(self.new_grid, 1)
    self.sizerTopRight.Show(self.new_grid)
    self.Layout()
    

