FreeCAD

Форк
0
/
freecad-thumbnailer 
67 строк · 2.2 Кб
1
#!/usr/bin/python
2
"""Support file to show FreeCAD thumbnails on Free Desktop Environments (like GNOME or KDE)
3

4
Installation:
5
- This executable file should be on the PATH so it can be found
6
    "$ sudo cp freecad-thumbnailer /usr/bin"
7
  and must have execution rights
8
    "$ sudo chmod +x /usr/bin/freecad-thumbnailer"
9

10
- If a FreeCAD project file doesn't include a thumbnail the file org.freecad.FreeCAD.png is used.
11
  Thus, the file src/Gui/Icons/freecad-icon-48.png must be installed.
12
    "$ sudo cp freecad-icon-48.png /usr/share/icons/hicolor/48x48/apps/org.freecad.FreeCAD.png"
13

14
- The application/x-extension-fcstd MIME type should be registered
15
    Check that a corresponding /usr/share/mime/packages/freecad.xml file exists
16
    Make sure the MIME database is up to date
17
    "$ sudo update-mime-database /usr/share/mime"
18

19
- Register this thumbnailer
20
    Adding a file /usr/share/thumbnailers/FreeCAD.thumbnailer with the following content:
21

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

27
HINT: Make sure that the symlink /usr/bin/python exists and points to the Python executable
28

29
NOTE: To make sure FreeCAD saves thumbnail information:
30

31
    Edit -> Preferences... -> Document -> Save thumbnail into project when saving document
32
"""
33
import sys
34
import zipfile
35
import getopt
36

37
opt, par = getopt.getopt(sys.argv[1:], "-s:")
38
input_file = par[0]
39
output_file = par[1]
40

41
try:
42
    # Read compressed file
43
    zfile = zipfile.ZipFile(input_file)
44
    files = zfile.namelist()
45

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

51
    # Read thumbnail from file or use default icon
52
    image = "thumbnails/Thumbnail.png"
53
    if image in files:
54
        image = zfile.read(image)
55
    else:
56
        # apps should have at least 48x48 icons
57
        freecad = open("/usr/share/icons/hicolor/48x48/apps/org.freecad.FreeCAD.png", "rb")
58
        image = freecad.read()
59

60
    # Write icon to output_file
61
    thumb = open(output_file, "wb")
62
    thumb.write(image)
63
    thumb.close()
64

65
except Exception:
66
    print("Error creating FreeCAD thumbnail for file ", input_file)
67
    sys.exit(1)
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.