Fix thumbnail preview on XDG Desktops (#4078)

Merged, abandoned or rejected pull requests are moved here to clear the main Pull Requests forum.
pachiburke
Posts: 11
Joined: Tue Nov 24, 2020 9:46 am

Fix thumbnail preview on XDG Desktops (#4078)

Post by pachiburke »

I've just sent a pull request tackling this issue: https://github.com/FreeCAD/FreeCAD/pull/4078

The thumbnailer script (src/Tools/freecad-thumbnailer) needed some updates:
  • now it doesn't depend on gnome libs (it doesn't need to)
  • it works either with python2 and python3
  • a thumbnailer config file is added to the installation step (FreeCAD.thumbnailer in /usr/share/thumbnailers)
  • it no longer uses the .py extension
The freecad-thumbnailer script should be copied to /usr/bin/freecad-thumbnailer and should have execution rights

This is basically what's needed to make it work

Code: Select all

$ sudo chmod +x freecad-thumbnailer
$ sudo cp freecad-thumbnailer /usr/bin/
$ sudo cp FreeCAD.thumbnailer /usr/share/thumbnailers/
I haven't modified any isntallation config file so the freecad-thumbailer script is copied into /usr/bin, as I'm not sure where it is done, and also because the policy could be not installing the thumbnailer by default.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by Kunda1 »

Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
drmacro
Veteran
Posts: 8864
Joined: Sun Mar 02, 2014 4:35 pm

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by drmacro »

I attempted to get this working by hand, i.e. moving the suggested files to directories, updating the mime database (as recommended in the python script)

I have no freecad.xml file. How/when is this created? I do have freecad-daily.xml...

I put the python script in /usr/local/bin/

But I don't see the thumbnails in Thunar...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by wmayer »

I didn't get it to work either.

Btw, here is an example how to create thumbnails for STL files: https://github.com/MLAB-project/stl-thumbnailer

Does it work for you? For me it doesn't.

When I explicitly invoke the script with for example:

Code: Select all

python stl_thumb.py /tmp/boxes.stl /tmp/boxes.png 64
then the image is created. So, it means the script is OK but somehow never called by the system.
drmacro
Veteran
Posts: 8864
Joined: Sun Mar 02, 2014 4:35 pm

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by drmacro »

I can get it to extract a png if I run it by hand. But, if the -s option is included as in:

Code: Select all

[Thumbnailer Entry]
TryExec=freecad-thumbnailer
Exec=freecad-thumbnailer -s %s %i %o
MimeType=application/x-extension-fcstd;

Code: Select all

python3 ./freecad-thumbnailer -s /home/mac/Downloads/FreeCAD/02-top-mac.FCStd /home/mac/Downloads/FreeCAD/02-top-mac.png 64
If fails:

Code: Select all

Error creating FreeCAD thumbnail for file  /home/mac/Downloads/FreeCAD/02-top-mac.png
But, remove the -s and it creates the png.

So, it appears the arguments aren't being parsed correctly.

I have no idea what is supposed to trigger this python to be executed... :roll:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
pachiburke
Posts: 11
Joined: Tue Nov 24, 2020 9:46 am

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by pachiburke »

The FreeCAD.xml (org.freecadweb.FreeCAD.xml by default) file, as well as FreeCAD.thumbnailer, and other support files are in the src/XDGData folder: https://github.com/FreeCAD/FreeCAD/tree ... rc/XDGData.

The xml file is normally installed on your system under /usr/share/freecad/share/mime/packages/org.freecadweb.FreeCAD.xml, but this could be different in the AppImage case (I have not checked it).

This org.freecadweb.FreeCAD.xml defines some Mime information, such as the file type extension for FreeCAD files and it's needed so Nautilus or Thunar can recognize them as freecad files with the right mimetype.

With regards to the -s option, freecad-thumbnailer currently ignores it, but it could pontentially be used to get a given pixel size for the thumbnail. Right now it just uses the default size that FreeCAD stores in its files, so no resizing is done.

Anyhow, If it were to work, the right invocation needs adding the size in pixels for the thumbnail just after the -s option, like this:

Code: Select all

freecad-thumbnailer -s 64 inputfile.fcstd mypath/output.png
I hope this can get you further.
drmacro
Veteran
Posts: 8864
Joined: Sun Mar 02, 2014 4:35 pm

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by drmacro »

pachiburke wrote: Wed Nov 25, 2020 8:55 am The FreeCAD.xml (org.freecadweb.FreeCAD.xml by default) file, as well as FreeCAD.thumbnailer, and other support files are in the src/XDGData folder: https://github.com/FreeCAD/FreeCAD/tree ... rc/XDGData.
I don't know what this implies when attempting to configure this by hand...
The xml file is normally installed on your system under /usr/share/freecad/share/mime/packages/org.freecadweb.FreeCAD.xml, but this could be different in the AppImage case (I have not checked it).

This org.freecadweb.FreeCAD.xml defines some Mime information, such as the file type extension for FreeCAD files and it's needed so Nautilus or Thunar can recognize them as freecad files with the right mimetype.
My system is not using an app image and FreeCAD has not been compiled here. So, there is no /usr/share/freecad/
This sysyem has the daily build so it has: /usr/share/freecad-daily/share/mime/packages/org.freecadweb.FreeCAD.xml
I don't know what implication this has.
With regards to the -s option, freecad-thumbnailer currently ignores it, but it could pontentially be used to get a given pixel size for the thumbnail. Right now it just uses the default size that FreeCAD stores in its files, so no resizing is done.

Anyhow, If it were to work, the right invocation needs adding the size in pixels for the thumbnail just after the -s option, like this:

Code: Select all

freecad-thumbnailer -s 64 inputfile.fcstd mypath/output.png
The docstring shows:

Code: Select all

Exec=freecad-thumbnailer -s %s %i %o
	MimeType=application/x-extension-fcstd;
No indication of what %s %i %o arguments are sourced from.
I still have no idea what triggers the actual execution of this code. For example, when is the mime database updated for all the files existing in a particular folder, or for that matter, system wide?
Is it possible that the extension fcstd is case sensitive? My FreeCAD files all end up with .FCStd
I hope this can get you further.
No joy yet. :(
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
pachiburke
Posts: 11
Joined: Tue Nov 24, 2020 9:46 am

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by pachiburke »

The %s %i and %s parameters are filled by the file browser and have conventional meanings, so the first one is the desired thumbnail size, the second one the input file, and the third one the destination file.

Your file browser normally caches these thumbnails and they only change when the file is updated. You can check if they update correctly by just using the touch command in one of your .FCStd files (the extension case shouldn't matter).

Code: Select all

$ touch myexamplefile.FCStd
and see if the thumbnail gets updated.
drmacro
Veteran
Posts: 8864
Joined: Sun Mar 02, 2014 4:35 pm

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by drmacro »

pachiburke wrote: Wed Nov 25, 2020 3:03 pm The %s %i and %s parameters are filled by the file browser and have conventional meanings, so the first one is the desired thumbnail size, the second one the input file, and the third one the destination file.

Your file browser normally caches these thumbnails and they only change when the file is updated. You can check if they update correctly by just using the touch command in one of your .FCStd files (the extension case shouldn't matter).

Code: Select all

$ touch myexamplefile.FCStd
and see if the thumbnail gets updated.
touch doesn't change anything. Saving from FreeCAD didn't so I didn't expect touch would.

I suspect there is more to this than is obvious. Thunar shows previews of other file formats...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
pachiburke
Posts: 11
Joined: Tue Nov 24, 2020 9:46 am

Re: Fix thumbnail preview on XDG Desktops (#4078)

Post by pachiburke »

@drmacro I'm not sure what could be going wrong in your case.
This has a quite complete guide for thumbnail support in thunar: https://delightlylinux.wordpress.com/20 ... humbnails/

The key pieces for using thumbnails in XDG desktop environments are:
  • Registering the mime type, so it can ge recognized. This what the /usr/share/freecad/share/mime/packages/org.freecadweb.FreeCAD.xml does. it associates the *.fcstd pattern with the application/x-extension-fcstd mimetype.
  • Telling the desktop file manager which thumbnailer to use for each mimetype. This is what the /usr/share/thumbnailers/FreeCAD.thumbnailer does. With its information, the DE can check if the thumbnailer is installed (TryExec, how to call it and how parameters are ordered (Exec), and which mimetype it can deal with (MimeType).
  • Providing a thumbnailer script which can, given an input path (%i) or URI (%u) (we use a path in this case), return a png file in a path (%o), optionally requesting a given pixel size (%s). This is what /usr/bin/freecad-thumbnailer does.
Besides this, the file manager should have thumbnail creation activated.

Also, file managers can cache thumbnails so they don't need to be recreated, and this cache uses the ~/.cache/thumbnails/ subdirectories (normal, large and fail). This cache can sometimes avoid the generation of thumnails when a new thumbnail is installed (and that's why touching the file may fix it, while other tools may need a full delete of the cache dir).

I hope this overview helps you find where your problem may be. I'm not a user of Thunar myself and can't tell too much about it.
Post Reply