~ubuntu-branches/debian/squeeze/inkscape/squeeze

« back to all changes in this revision

Viewing changes to share/extensions/export_gimp_palette.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
'''
 
7
 
 
8
DOCNAME='sodipodi:docname'
 
9
 
 
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/>.')
 
15
 
 
16
colortags=(u'fill',u'stroke',u'stop-color',u'flood-color',u'lighting-color')
 
17
colors={}
 
18
 
 
19
def walk(node):
 
20
    checkStyle(node)
 
21
    if node.hasChildNodes():
 
22
        childs=node.childNodes
 
23
        for child in childs:
 
24
            walk(child)
 
25
 
 
26
def checkStyle(node):
 
27
    if 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]])
 
34
 
 
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()
 
39
 
 
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])
 
45
 
 
46
for k,v in sorted(colors.items()):
 
47
    print k+v
 
 
b'\\ No newline at end of file'