Fix thumbnailing
This fixes thumbnailing for XDG desktops. The new script doesn't depend on GNOME libs and works either with python3 or python2. Also, a thumbnailer config file is added to the installation in CMakeList.txt
This commit is contained in:
committed by
wmayer
parent
6bd39e8a90
commit
27130f779a
57
src/Tools/freecad-thumbnailer
Normal file
57
src/Tools/freecad-thumbnailer
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/python
|
||||
"""Support file to show FreeCAD thumbnails on Free Desktop Environments (like GNOME or KDE)
|
||||
|
||||
Installation:
|
||||
- This executable file should be on the PATH so it can be found
|
||||
"$ sudo cp freecad-thumbnailer /usr/share/bin"
|
||||
- the application/x-extension-fcstd MIME type should be registered
|
||||
Check that a corresponding /usr/share/mime/packages/freecad.xml file exists
|
||||
Make sure the MIME database is up to date
|
||||
"$ sudo update-mime-database /usr/share/mime"
|
||||
- Register this thumbnailer
|
||||
Adding a file /usr/share/thumbnailers/FreeCAD.thumbnailer with the following content:
|
||||
|
||||
[Thumbnailer Entry]
|
||||
TryExec=freecad-thumbnailer
|
||||
Exec=freecad-thumbnailer -s %s %i %o
|
||||
MimeType=application/x-extension-fcstd;
|
||||
|
||||
NOTE: To make sure FreeCAD saves thumbnail information:
|
||||
|
||||
Edit -> Preferences... -> Document -> Save thumbnail into project when saving document
|
||||
"""
|
||||
import sys
|
||||
import zipfile
|
||||
import getopt
|
||||
|
||||
opt, par = getopt.getopt(sys.argv[1:], '-s:')
|
||||
input_file = par[0]
|
||||
output_file = par[1]
|
||||
|
||||
try:
|
||||
# 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()
|
||||
|
||||
except:
|
||||
print("Error creating FreeCAD thumbnail for file ", input_file)
|
||||
sys.exit(1)
|
||||
@@ -1,36 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys, zipfile, md5
|
||||
import getopt
|
||||
import gnomevfs
|
||||
|
||||
opt,par = getopt.getopt(sys.argv[1:],'-s:')
|
||||
inpfile = gnomevfs.get_local_path_from_uri(par[0])
|
||||
#inpfile = par[0]
|
||||
outfile = par[1]
|
||||
|
||||
#print "fcthumbnailer"
|
||||
#print inpfile, outfile
|
||||
|
||||
try:
|
||||
zfile=zipfile.ZipFile(inpfile)
|
||||
files=zfile.namelist()
|
||||
#print files
|
||||
# check for meta-file if it's really a FreeCAD document
|
||||
if files[0] != "Document.xml":
|
||||
sys.exit(1)
|
||||
|
||||
image="thumbnails/Thumbnail.png"
|
||||
if image in files:
|
||||
image=zfile.read(image)
|
||||
else:
|
||||
freecad=open("/usr/share/freecad/freecad-doc.png")
|
||||
image=freecad.read()
|
||||
|
||||
thumb=open(outfile,"wb")
|
||||
thumb.write(image)
|
||||
thumb.close()
|
||||
|
||||
except:
|
||||
sys.exit(1)
|
||||
|
||||
@@ -38,3 +38,8 @@ install(
|
||||
FILES org.freecadweb.FreeCAD.xml
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mime/packages
|
||||
)
|
||||
|
||||
install(
|
||||
FILES FreeCAD.thumbnailer
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/thumbnailers
|
||||
)
|
||||
|
||||
4
src/XDGData/FreeCAD.thumbnailer
Normal file
4
src/XDGData/FreeCAD.thumbnailer
Normal file
@@ -0,0 +1,4 @@
|
||||
[Thumbnailer Entry]
|
||||
TryExec=freecad-thumbnailer
|
||||
Exec=freecad-thumbnailer -s %s %i %o
|
||||
MimeType=application/x-extension-fcstd;
|
||||
Reference in New Issue
Block a user