import wx

ID_MENU_REFRESH = wx.NewId()
#dummy description of image
imglist =['One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten']

class Example(wx.Frame):
    
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 
        mb = wx.MenuBar()
        fMenu = wx.Menu()
        fMenu.Append(ID_MENU_REFRESH, 'Refresh')
        mb.Append(fMenu, '&Action')
        self.SetMenuBar(mb)
        self.Bind(wx.EVT_MENU, self.refreshApps, id=ID_MENU_REFRESH) 

        #storing the thumb image in memory
        self.bmp=wx.Image('img/myimg.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.panelOne = wx.Panel(self)        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.panelOne.SetSizer(sizer)
        self.panelOne.Layout()
        self.myimg_holder={}
        self.showThumb(imglist)
        self.SetTitle('Example')
        self.Centre()
        self.Show(True)
        
    def refreshApps(self,event=None):
        #remove 
        self.showThumb()
        #repaint
        self.showThumb(imglist)
        
    def showThumb(self,thumblist=None):
    
        
        if not thumblist:
            for child in self.panelOne.GetChildren(): 
                child.Destroy() 
            self.myimg_holder.clear()
            self.panelOne.Layout()
            return 
        
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer()
        gs = wx.FlexGridSizer(8, 6, 10, 20)
        gs.Add(wx.StaticText(self.panelOne),flag=wx.ALL|wx.EXPAND, border=2)
        vzis = []
        for num,app in enumerate(thumblist):
            vzis.append(wx.BoxSizer(wx.VERTICAL))
            appid = wx.StaticBitmap(self.panelOne,wx.ID_ANY, self.bmp, (5,5), (self.bmp.GetWidth()+5, self.bmp.GetHeight()),name=app.strip())
            vzis[num].Add(appid,0, wx.ALIGN_CENTER)
            self.myimg_holder[appid]=app
            vzis[num].Add(wx.StaticText(self.panelOne,-1,app),0, wx.ALIGN_CENTER,border=1)
        for i in range(len(thumblist)):
            if i in [4,8,12]:
                gs.Add(wx.StaticText(self.panelOne),flag=wx.ALL, border=2)
                gs.Add(wx.StaticText(self.panelOne),flag=wx.ALL, border=2)
                gs.Add(vzis[i],flag=wx.ALL, border=1)
            else:
                gs.Add(vzis[i],flag=wx.ALL, border=1)
        vbox.Add(wx.StaticText(self.panelOne),flag=wx.ALL, border=4)
        vbox.Add(gs, proportion=1, flag=wx.ALL)
        vbox.Add(wx.StaticText(self.panelOne),flag=wx.ALL, border=4)
        self.panelOne.SetSizer(vbox)
        self.panelOne.Layout()
            
def main():
    
    ex = wx.App()
    frame = Example(None)
    frame.Show()
    ex.MainLoop()    


if __name__ == '__main__':
    main()