f1b4086c01ae41478360038ff958fdbbc430faa3
1 #!/usr/bin/env python
2 '''
3 Author: Jos Hirth, kaioa.com
4 License: GNU General Public License - http://www.gnu.org/licenses/gpl.html
5 Warranty: see above
6 '''
8 DOCNAME='sodipodi:docname'
10 import sys, simplestyle
11 try:
12 from xml.dom.minidom import parse
13 except:
14 sys.exit(_('The export_gpl.py module requires PyXML. Please download the latest version from http://pyxml.sourceforge.net/.'))
16 colortags=(u'fill',u'stroke',u'stop-color',u'flood-color',u'lighting-color')
17 colors={}
19 def walk(node):
20 checkStyle(node)
21 if node.hasChildNodes():
22 childs=node.childNodes
23 for child in childs:
24 walk(child)
26 def checkStyle(node):
27 if hasattr(node,"hasAttributes") and node.hasAttributes():
28 sa=node.getAttribute('style')
29 if sa!='':
30 styles=simplestyle.parseStyle(sa)
31 for c in range(len(colortags)):
32 if colortags[c] in styles.keys():
33 addColor(styles[colortags[c]])
35 def addColor(col):
36 if simplestyle.isColor(col):
37 c=simplestyle.parseColor(col)
38 colors['%3i %3i %3i ' % (c[0],c[1],c[2])]=simplestyle.formatColoria(c).upper()
40 stream = open(sys.argv[-1:][0],'r')
41 dom = parse(stream)
42 stream.close()
43 walk(dom)
44 print 'GIMP Palette\nName: %s\n#' % (dom.getElementsByTagName('svg')[0].getAttribute(DOCNAME).split('.')[0])
46 for k,v in sorted(colors.items()):
47 print k+v
50 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8