Doc icon generation cleanup
[MacVim.git] / src / MacVim / icons / make_icons.py
blob4820fe2508a8e5a9c079d6d0b86fd4637e4da005
1 # Creates a document icon from an app icon and an optional text.
3 # The font is not quite right, use this script to create a document icon
4 # for 'PDF' and compare the D with the D in Preview's pdf.icns
6 # http://www.macresearch.org/cocoa-scientists-part-xx-python-scriptersmeet-cocoa
7 try:
8 import docerator
9 dont_create = False
10 except:
11 dont_create = True # most likely because we're on tiger
13 import os
14 import sys
17 # icon types
18 LARGE = 0 # 512, 128, 32, 16; about 96kB
19 SMALL = 1 # 128, 32, 16; about 36kB
20 LINK = 2 # Create link to generic icon; 4kB (== smallest block size on HFS+)
22 iconsizes = {
23 SMALL: [128, 32, 16],
24 LARGE: [512, 128, 32, 16],
28 # Resources
29 MAKEICNS = 'makeicns/makeicns'
30 APPICON = 'vim-noshadow-512.png'
31 DEFAULT_BACKGROUND = '/System/Library/CoreServices/CoreTypes.bundle/' + \
32 'Contents/Resources/GenericDocumentIcon.icns'
35 # List of icons to create
36 GENERIC_ICON_NAME = 'MacVim-generic'
37 vimIcons = {
38 GENERIC_ICON_NAME: [u'', LARGE],
39 'MacVim-vim': [u'VIM', LARGE],
40 'MacVim-txt': [u'TXT', SMALL],
41 'MacVim-tex': [u'TEX', SMALL],
42 'MacVim-h': [u'H', SMALL],
43 'MacVim-c': [u'C', SMALL],
44 'MacVim-m': [u'M', SMALL],
45 'MacVim-mm': [u'MM', SMALL],
46 'MacVim-cpp': [u'C\uff0b\uff0b', SMALL], # fullwidth plusses
47 'MacVim-java': [u'JAVA', SMALL],
48 'MacVim-f': [u'FTRAN', SMALL],
49 'MacVim-html': [u'HTML', SMALL],
50 'MacVim-xml': [u'XML', SMALL],
51 'MacVim-js': [u'JS', SMALL],
52 'MacVim-perl': [u'PERL,PL', SMALL],
53 'MacVim-py': [u'PYTHON,PY', SMALL],
54 'MacVim-php': [u'PHP', SMALL],
55 'MacVim-rb': [u'RUBY,RB', SMALL],
56 'MacVim-bash': [u'SH', SMALL],
57 'MacVim-patch': [u'DIFF', SMALL],
58 'MacVim-applescript': [u'\uf8ffSCPT,\uf8ffS', SMALL], # apple sign
59 'MacVim-as': [u'FLASH', LINK],
60 'MacVim-asp': [u'ASP', LINK],
61 'MacVim-bib': [u'BIB', LINK],
62 'MacVim-cs': [u'C#', LINK],
63 'MacVim-csfg': [u'CFDG', LINK],
64 'MacVim-csv': [u'CSV', LINK],
65 'MacVim-tsv': [u'TSV', LINK],
66 'MacVim-cgi': [u'CGI', LINK],
67 'MacVim-cfg': [u'CFG', LINK],
68 'MacVim-css': [u'CSS', SMALL],
69 'MacVim-dtd': [u'DTD', LINK],
70 'MacVim-dylan': [u'DYLAN', LINK],
71 'MacVim-erl': [u'ERLANG,ERL', SMALL],
72 'MacVim-fscript': [u'FSCPT,FSCR', SMALL],
73 'MacVim-hs': [u'HS', SMALL],
74 'MacVim-inc': [u'INC', LINK],
75 'MacVim-ics': [u'ICS', SMALL],
76 'MacVim-ini': [u'INI', LINK],
77 'MacVim-io': [u'IO', LINK],
78 'MacVim-bsh': [u'BSH', LINK],
79 'MacVim-properties': [u'PROP', LINK],
80 'MacVim-jsp': [u'JSP', SMALL],
81 'MacVim-lisp': [u'LISP', SMALL],
82 'MacVim-log': [u'LOG', SMALL],
83 'MacVim-wiki': [u'WIKI', SMALL],
84 'MacVim-ps': [u'PS', LINK],
85 #'MacVim-plist': [u'PLIST', SMALL],
86 'MacVim-sch': [u'SCHEME,SCM', SMALL],
87 'MacVim-sql': [u'SQL', SMALL],
88 'MacVim-tcl': [u'TCL', SMALL],
89 'MacVim-xsl': [u'XSL', LINK],
90 'MacVim-vcf': [u'VCARD,VCF', SMALL],
91 'MacVim-vb': [u'VBASIC,VB', LINK],
92 'MacVim-yaml': [u'YAML', SMALL],
93 'MacVim-gtd': [u'GTD', LINK],
97 def createLinks(icons, target):
98 assert len(icons) > 0
99 for name in icons:
100 icnsName = '%s.icns' % name
101 if os.access(icnsName, os.F_OK):
102 os.remove(icnsName)
103 os.symlink(target, icnsName)
106 def main():
107 if dont_create:
108 print "PyObjC not found, only using a stock icon for document icons."
109 # Can't use the constants from docerator in this case
110 import shutil
111 shutil.copyfile(DEFAULT_BACKGROUND, '%s.icns' % GENERIC_ICON_NAME)
112 createLinks([name for name in vimIcons if name != GENERIC_ICON_NAME],
113 '%s.icns' % GENERIC_ICON_NAME)
114 return
116 srcdir = os.getcwd()
117 if len(sys.argv) > 1:
118 os.chdir(sys.argv[1])
119 appIcon = os.path.join(srcdir, APPICON)
120 makeIcns = os.path.join(srcdir, MAKEICNS)
123 # create LARGE and SMALL icons first...
124 for name, t in vimIcons.iteritems():
125 text, size = t
126 if size == LINK: continue
127 print name
128 docerator.makedocicon(outname='%s.icns' % name, appicon=appIcon, text=text,
129 sizes=iconsizes[size], makeicns=makeIcns)
131 # ...create links later (to make sure the link targets exist)
132 createLinks([name for (name, t) in vimIcons.items() if t[1] == LINK],
133 '%s.icns' % GENERIC_ICON_NAME)
136 if __name__ == '__main__':
137 main()