Created
January 17, 2011 22:29
-
-
Save milesegan/783616 to your computer and use it in GitHub Desktop.
photoshop slice export parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, re, sys | |
from xml.etree.ElementTree import ElementTree | |
def hash_style(s): | |
s = re.split(r";\s+", s) | |
s = [re.split(r":", x) for x in s] | |
s = [(x[0], re.sub(r"[^0-9]", "", x[1])) for x in s if re.match(r"^\d", x[1])] | |
return dict(s) | |
def parse_layout(path): | |
doc = [] | |
widgets = [] | |
tree = ElementTree() | |
tree.parse(path) | |
div = tree.findall("body/div")[0] | |
d = dict(div.items()) | |
doc = hash_style(d['style']) | |
for widget in div: | |
d = dict(widget.items()) | |
w = hash_style(d['style']) | |
img = widget[0] | |
d = dict(img.items()) | |
w['src'] = os.path.basename(d['src']) | |
w['src'] = os.path.splitext(w['src'])[0] | |
w['alt'] = w.get('alt', 'slider') | |
widgets.append(w) | |
print "doc %s %s" % (doc['width'], doc['height']) | |
for w in widgets: | |
print " ".join([w['alt'], w['src'], w['top'], w['left'], w['width'], w['height']]) | |
if len(sys.argv) < 2: | |
print "usage: parse_layout layout.html" | |
else: | |
parse_layout(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://www.kvraudio.com/forum/viewtopic.php?p=4392841 .