Search code examples
wxpython

Completely remove GridBagSizer in wx.Python


Good morning,

I am coding a result table using a wx.GridBagSizer inside a wx.BoxSizer. Once I update new data, I want to completely remove the GridBagSizer, create a new GridBagsizer and show the new results on the new one. However, when I update the data, the values are correctly updated but the new GridBagSizer is moved to a position as if the previous GridBagSizer still exist....

Could you help me? Thanks

    def actualiza_res(self, presas_sel):
    self.presas_sel = presas_sel
    esquema = self.link_principal.esquema
    if esquema["modelos"] and esquema["res_prio"]==False:
        self.gbsint.Clear(True)
        self.gbsint.Layout()
        self.Refresh()
        self.Update()

        self.gbsint=wx.GridBagSizer(vgap=10, hgap=10)
        self.gbsint.Layout()
        self.Refresh()
        self.Update()
        text11=wx.StaticText(self, -1,_('Current situation'))
        font11 = wx.Font(12, wx.ROMAN, wx.NORMAL, wx.BOLD)
        text11.SetFont(font11)
        self.gbsint.Add(text11, (3, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)
        self.ct=['-']*(len(self.resct))
        self.ec=['-']*len(self.resec)
        self.ps=['-']*len(self.resps)
        self.dpa=['-']*len(self.resdpa)
        j=4
        for res in range(len(self.ct)):
            self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["CRIDPA"][2][res])),(j, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)
            j += 1
        j=11
        for res in range(len(self.ec)):
            self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["CRIDPA"][2][res])),(j, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)
            j += 1
        j=18
        for res in range(len(self.ps)):
            self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["CRIDPA"][2][res])),(j, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)
            j += 1
        #self.totalcri=wx.StaticText(self, -1, _('-'), style=wx.ALIGN_CENTER)
        self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["riesgo"][0])),(27, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40) #Total CRI
        j=29
        for res in range(len(self.dpa)):
            self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["CRIDPA"][2][res])),(j, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)
            j += 1

        #self.totaldpa=wx.StaticText(self, -1, _('-'), style=wx.ALIGN_CENTER)
        self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["riesgo"][2])),(33, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40) #TOTalDPA
        #self.totalr=wx.StaticText(self, -1, _('-'), style=wx.ALIGN_CENTER)
        self.gbsint.Add(wx.StaticText(self, -1,str(esquema["modelos"][presas_sel[-1]]["riesgo"][4])),(34, 1), flag=wx.LEFT|wx.ALIGN_CENTER, border=40)#Clase

       #Datos actuales de la presa
        self.textos["presas"].SetLabel(str(esquema["modelos"][presas_sel[-1]]["presas"])) #Nombre de la presa
        self.textos["Fecha ultima inspeccion"].SetLabel(str(esquema["modelos"][presas_sel[-1]]["Fecha ultima inspeccion"]))#ultima inspeccion
        self.textos["riesgo"].SetLabel(str(esquema["modelos"][presas_sel[-1]]["riesgo"][-1])) #Classe        
        self.sizer_hor.Add(self.gbsint,flag=wx.ALIGN_LEFT)
        self.SetupScrolling()

        self.Refresh()
        self.Layout()
        self.Update()

Solution

  • I found my self that it was missing a line "self.gbsint.SetEmptyCellSize((0,0))" when creating the new GridBagSizer to effectively not consider the existence of the previous columns and rows.