Page 3 of 4
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Mon Nov 30, 2020 7:50 pm
by Kunda1
Anyone willing to document this on the wiki?
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Mon Nov 30, 2020 10:07 pm
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.
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Tue Dec 01, 2020 1:59 pm
by drmacro
Kunda1 wrote:
pinged by pinger macro
Quick question: which wiki do think this should get into?
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)
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Tue Dec 01, 2020 3:47 pm
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
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Tue Dec 01, 2020 3:52 pm
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
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Thu Dec 03, 2020 2:24 pm
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...
)
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Thu Dec 03, 2020 3:38 pm
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.
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Thu Dec 03, 2020 3:48 pm
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")
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Thu Dec 03, 2020 3:52 pm
by wmayer
Re: Fix thumbnail preview on XDG Desktops (#4078)
Posted: Thu Dec 03, 2020 4:56 pm
by drmacro
Did you fix the docstring while you were in there?