X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=utils%2FModeller%2Fuv_import_svg.py;h=b366d41255d848a87035d99a97c0ed298653d631;hb=030742fa4ae7d99facb517381da71fa404c4ee2b;hp=62ee9f147680f92df2b37e44b6534cdd7fea48d5;hpb=5960442cc38e72a9cac69be5de0d2f1430b3e671;p=flightgear.git diff --git a/utils/Modeller/uv_import_svg.py b/utils/Modeller/uv_import_svg.py index 62ee9f147..b366d4125 100755 --- a/utils/Modeller/uv_import_svg.py +++ b/utils/Modeller/uv_import_svg.py @@ -13,7 +13,7 @@ __version__ = "0.2" __bpydoc__ = """\ Imports an SVG file containing UV maps, which has been saved by the uv_export.svg script. This allows to move, scale, and rotate object -mapping in SVG editors like Inkscape. Note that all contained UV maps +mappings in SVG editors like Inkscape. Note that all contained UV maps will be set, no matter which objects are actually selected at the moment. The choice has been made when the file was saved! """ @@ -41,8 +41,7 @@ The choice has been made when the file was saved! ID_SEPARATOR = '_.:._' -import Blender, BPyMessages, sys, math, re -from xml.sax import handler, make_parser +import Blender, BPyMessages, sys, math, re, xml.sax numwsp = re.compile('(?<=[\d.])\s+(?=[-+.\d])') @@ -165,7 +164,7 @@ def parse_transform(s): return matrix -class import_svg(handler.ContentHandler): +class import_svg(xml.sax.handler.ContentHandler): # err_handler def error(self, exception): raise Abort(str(exception)) @@ -212,18 +211,18 @@ class import_svg(handler.ContentHandler): def startElement(self, name, attrs): currmat = self.matrices[-1] - try: + if "transform" in attrs: m = parse_transform(attrs["transform"]) if currmat != None: m.multiply(currmat) self.matrices.append(m) - except: + else: self.matrices.append(currmat) if name == "polygon": self.handlePolygon(attrs) elif name == "svg": - try: + if "viewBox" in attrs: x, y, w, h = commawsp.split(attrs["viewBox"], 4) if int(x) or int(y): raise Abort("bad viewBox") @@ -231,7 +230,7 @@ class import_svg(handler.ContentHandler): self.height = int(h) if self.width != self.height: raise Abort("viewBox isn't a square") - except: + else: raise Abort("no viewBox") elif name == "desc" and not self.verified: self.scandesc = True @@ -286,10 +285,7 @@ def run_parser(path): Blender.Window.WaitCursor(1) try: - svg = make_parser() - svg.setContentHandler(import_svg()) - svg.setErrorHandler(import_svg()) - svg.parse(path) + xml.sax.parse(path, import_svg(), import_svg()) Blender.Registry.SetKey("UVImportExportSVG", { "path" : path }, False) except Abort, e: