Using ThumbnailCtrl for image gallery file app

I’d like to use ThumbnailCtrl in ubuntu linux app for an app that can select multiple images from the system and perform operation on them but for some reason I’m struggeling with find an udated example code for how to implement this.

What’d be the basic bare minimal way to implement this? is this feathure even available in ubuntu as I’m not able to see the render example in this wiki page:
https://docs.wxpython.org/wx.lib.agw.thumbnailctrl.ThumbnailCtrl.html#wx.lib.agw.thumbnailctrl.ThumbnailCtrl

The ThumbnailCtrl example in the wxPython demo works for me using wxPython 4.2.3 gtk3 (phoenix) wxWidgets 3.2.7 + Python 3.12.3 + Linux Mint 22.1

1 Like

Huh ok, where are you suppose to obtain it from minimally and through bash preferable and how do you usually run those example?

I did manage to get my hands on some tar demo examples but in order to run it for my I did copy paste the main “ThumbnailCtrl.py” file to my code and copied the files “ThumbDemoConfig.py”, “images.py” and “run.py” from the demo

And if I’m already here, is there a simple way to make a rightclick menu for the ThumbnailCtrl wideget to work for each individual thumbnail location?

Apologies for the delay, but I’ve only just found some time to investigate this question.

I started with the example in the documentation for wx.lib.agw.scrolledthumbnail. I modified it to add a popup menu which the ScrolledThumbnail class displays when you right-click on a thumbnail.

In the code below, the popup menu has a single menu item which simply prints the pathnames of all the selected thumbnails.

Note: if you hold down Shift or Ctrl when right clicking, the selection will be extended, resulting in multiple selected thumbnails.

One drawback of this approach is that it accesses protected attributes of the ScrolledThumbnail class.

import os
import wx
from wx.lib.agw.scrolledthumbnail import ScrolledThumbnail, Thumb, NativeImageHandler

ID_PRINT_PATHNAME = wx.NewIdRef()

class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "ScrolledThumb Demo", size=(400,300))
        self.scroll = ScrolledThumbnail(self, -1, size=(400,300))
        menu = wx.Menu()
        menu.Append(ID_PRINT_PATHNAME, "Print Selected Thumbnails")
        self.scroll.SetPopupMenu(menu)
        self.Bind(wx.EVT_MENU, self.OnMenuPrintPathnames, id=ID_PRINT_PATHNAME)

    def ShowDir(self, dir):
        files = os.listdir(dir)
        thumbs = []
        for f in files:
            if os.path.splitext(f)[1] in [".jpg", ".gif", ".png"]:
                thumbs.append(Thumb(dir, f, caption=f, imagehandler=NativeImageHandler))
        self.scroll.ShowThumbs(thumbs)

    def OnMenuPrintPathnames(self, event):
        pathnames = [self.scroll._items[index].GetFullFileName() for index in self.scroll._selectedarray]
        print(pathnames)


app = wx.App(False)
frame = MyFrame(None)
frame.ShowDir("images")
frame.Show(True)
app.MainLoop()

Here is the output of a test run:

['images/black_5.jpg']
['images/moon.jpg']
['images/mg_midget.jpg']
['images/black_5.jpg', 'images/moon.jpg', 'images/mg_midget.jpg']
1 Like

Thanks for your time, this basic example you gave is good as a proof of consept and I will go from there it’s just that I’m learning wxPython a bit slowly not having much time myself and coming from a basic backround of pyside2 programming (Qt5) so yeah that helps but I just need to get a little more used to how to write the code and syntax more specificlly to wxPython.

BTW if you have yo use highlight for specific language in markdown codeblocks you write the name of the language after the brackets ```[LANGUAGE]
e.g.

```py

incase you didn’t know or did this outof lazyness