Fix thumbnail preview on XDG Desktops (#4078)

Merged, abandoned or rejected pull requests are moved here to clear the main Pull Requests forum.
User avatar
Kunda1
Veteran
Posts: 12693
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

Anyone willing to document this on the wiki?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
drmacro
Veteran
Posts: 5914
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

Kunda1 wrote: Mon Nov 30, 2020 7:50 pm Anyone willing to document this on the wiki?
yes I was going do write anyway for my memory...or lack there of. 8-)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
drmacro
Veteran
Posts: 5914
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

Kunda1 wrote: pinged by pinger macro
Quick question: which wiki do think this should get into?

pachiburke wrote: pinged
Just very minor note: The doc string in freecad-thumbnbails shows:

Code: Select all

...- This executable file should be on the PATH so it can be found
	"$ sudo cp freecad-thumbnailer /usr/share/bin"...
At least on an Ubuntu 20.04 or Debian 10 there is no /usr/share/bin.


Since the files involved are in the FC source, I'm assuming if it is compiled on a given machine, the copying of these files (freecad-thumbnailer, etc.) happens during the install phases of the build/make process.

So it would appear that someone using an appimage (or the PPA?) would need to get a copy of the source from github? Or are they available in the appimage? (or PPA)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
User avatar
Kunda1
Veteran
Posts: 12693
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

drmacro wrote: Tue Dec 01, 2020 1:59 pm Quick question: which wiki do think this should get into?
Good question, not sure what wiki page
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
drmacro
Veteran
Posts: 5914
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

Kunda1 wrote: Tue Dec 01, 2020 3:47 pm
drmacro wrote: Tue Dec 01, 2020 1:59 pm Quick question: which wiki do think this should get into?
Good question, not sure what wiki page
I was thinking maybe a "link for manual install details" from the save thumbnails with project expand:

https://wiki.freecadweb.org/Preferences_Editor
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
drmacro
Veteran
Posts: 5914
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

While messing with a different issue, I noted that, if the symlink for python is set python3 the following is thrown in syslog and no png is created:

Code: Select all

org.freedesktop.thumbnails.Thumbnailer1[1834]: libpng error: Not a PNG file
freecad-thumbnailer runs as usual (I can see messages from it in syslog, same messages with python2 or 3)

But, with python sym,link set to python2, no error and a thumbnail is created.


(Why won't the world accept python 2 is dead... :roll: :lol: )
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
wmayer
Founder
Posts: 18791
Joined: Thu Feb 19, 2009 10:32 am

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

Post by wmayer »

What happens if you open a Py3 session and run this Python code?

Code: Select all

import sys
import zipfile
import getopt

sys.argv=['python3', '-s', '64', '/tmp/test.FCStd', '/tmp/test.png']


opt, par = getopt.getopt(sys.argv[1:], '-s:')
input_file = par[0]
output_file = par[1]

# Read compressed file
zfile = zipfile.ZipFile(input_file)
files = zfile.namelist()

# Check whether we have a FreeCAD document
if "Document.xml" not in files:
    print(input_file, " doesn't look like a FreeCAD file")
    sys.exit(1)

# Read thumbnail from file or use default icon
image = "thumbnails/Thumbnail.png"
if image in files:
    image = zfile.read(image)
else:
    # apps should have at least 48x48 icons
    freecad = open("/usr/share/icons/hicolor/48x48/apps/freecad.png")
    image = freecad.read()

# Write icon to output_file
thumb = open(output_file, "wb")
thumb.write(image)
thumb.close()
You have to create the project /tmp/test.FCStd beforehand.
wmayer
Founder
Posts: 18791
Joined: Thu Feb 19, 2009 10:32 am

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

Post by wmayer »

OK, I found the problem. It happens for project files without a thumbnail and in this case this code is executed:

Code: Select all

freecad = open("/usr/share/icons/hicolor/48x48/apps/freecad.png")
image = freecad.read()
It fails because it doesn't open the file in binary mode but in text mode and that's why it raises a UnicodeDecodeError. But I wonder why it doesn't fail with Py2.

Anyway, the fix is trivial. Replace the line

Code: Select all

        freecad = open("/usr/share/icons/hicolor/48x48/apps/freecad.png")
with

Code: Select all

        freecad = open("/usr/share/icons/hicolor/48x48/apps/freecad.png", "rb")
wmayer
Founder
Posts: 18791
Joined: Thu Feb 19, 2009 10:32 am

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

Post by wmayer »

drmacro
Veteran
Posts: 5914
Joined: Sun Mar 02, 2014 4:35 pm

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

Post by drmacro »

wmayer wrote: Thu Dec 03, 2020 3:52 pm git commit 35ad37946
Did you fix the docstring while you were in there? ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
Post Reply