0

I am trying a add around 1,500 bitmaps to a ScrolledWindow, inside a GridSizer. They are loaded successfully (but a bit slow).

My issue is: whenever I scroll a bit faster, the whole thing freezes for 8-10 seconds.

Here is the relevant code:

class EmojiDBTab(wx.ScrolledWindow):
    def __init__(self, parent):
        wx.ScrolledWindow.__init__(self, parent)
        self.SetScrollbars(1, 10, 1, 10)

        dbtab_sizer = wx.GridSizer(len(TEST_UNICODE_EMOJI) / 10 + 1, 10, 0, 0)
        for unicode in TEST_UNICODE_EMOJI:
            emoji_symbol = EmojiBitmap(wx.Bitmap(unicode_to_pngfilename(unicode)),
                                   TEST_UNICODE_EMOJI[unicode])
        dbtab_sizer.Add(wx.StaticBitmap(self, -1, emoji_symbol.bitmap))

        self.SetSizer(dbtab_sizer) 

Is there a way to avoid the big delay after scrolling?

Thanks!

CostiS
  • 3
  • 1

1 Answers1

1

There are a couple of options. You can load up the number of images that you can see onscreen and then load more when the user scrolls. This would probably work pretty well. If you don't want the user to see them loading, then load two pages worth and just load on the scroll event.

Another option to consider is to create thumbnails of the images in the folder and show those instead. That should load considerably faster and might resolve the freezing issue.

The other option that comes to mind is to use a different widget, like wx.lib.imagebrowser, which is made for this sort of thing.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Thanks. Thumbnails are quite faster, but how do you use a ImagePanel? Is it just like a normal Panel, but optimised for bitmaps? Ideally, I'd like to easily load images from files into it. – CostiS Oct 21 '18 at 16:59
  • Looking at the class hierarchy in the docs (https://wxpython.org/Phoenix/docs/html/wx.lib.imagebrowser.ImagePanel.html), it appears that you would use the `ImagePanel` in much the same way as you would a regular panel. I would need to look at the source to be sure though – Mike Driscoll Oct 22 '18 at 21:01
  • Thanks for your answers! Everything you suggested works great for me, but my issue is with StaticBitmaps into a sizer. I have opened a new thread: https://stackoverflow.com/questions/52950574/wxpython-add-multiple-images-to-a-panel-issue – CostiS Oct 23 '18 at 13:40