Freestyle: lazy load 'export_svg'
authorCampbell Barton <ideasman42@gmail.com>
Sat, 18 Oct 2014 15:46:09 +0000 (17:46 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 18 Oct 2014 15:49:06 +0000 (17:49 +0200)
Loading XML module, registering etree namespaces... etc
on startup for everyone on chance someone may want to export
an SVG from Freestyle is unacceptable.

This shouldn't have got through the review.

also disable loading when built without freestyle.

release/scripts/freestyle/modules/export_svg.py
release/scripts/startup/freestyle_builtins.py

index 777fc736d20106435123fefd0a257d08de2a022d..9d6e13f4bd6f9016cadafd1b2f285ac69c1ca8dd 100644 (file)
@@ -23,7 +23,6 @@ import bpy
 import xml.etree.cElementTree as et
 
 from bpy.path import abspath
-from bpy.app.handlers import persistent
 from bpy_extras.object_utils import world_to_camera_view
 
 from freestyle.types import StrokeShader, BinaryPredicate1D, Interface0DIterator
@@ -266,12 +265,10 @@ def indent_xml(elem, level=0, indentsize=4):
 
 
 # - callbacks - #
-@persistent
+# called from: bpy.app.handlers.render_init
 def svg_export_header(scene):
-    render = scene.render
-    if not (render.use_freestyle and render.use_svg_export):
-        return
     # create new file (overwrite existing)
+    render = scene.render
     width, height = render.resolution_x, render.resolution_y
     scale = render.resolution_percentage / 100
 
@@ -283,16 +280,15 @@ def svg_export_header(scene):
         print("SVG export: invalid path")
 
 
-@persistent
+# called from: bpy.app.handlers.render_complete
 def svg_export_animation(scene):
-    """makes an animation of the exported SVG file """
+    # makes an animation of the exported SVG file
     render = scene.render
-    if render.use_freestyle and render.use_svg_export and render.svg_mode == 'ANIMATION':
-        write_animation(abspath(render.svg_path), scene.frame_start, render.fps)
+    write_animation(abspath(render.svg_path), scene.frame_start, render.fps)
 
 
 def write_animation(filepath, frame_begin, fps=25):
-    """Adds animate tags to the specified file."""
+    # Adds animate tags to the specified file.
     tree = et.parse(filepath)
     root = tree.getroot()
 
index 25d30771e39f71273d698c15936c2a0269efb9f3..b6493e869799a92705153045de4d79af033c5d4c 100644 (file)
 
 import bpy
 
-from export_svg import svg_export_header, svg_export_animation
+if bpy.app.build_options.freestyle:
+    from bpy.app.handlers import persistent
 
-def register():
-    bpy.app.handlers.render_init.append(svg_export_header)
-    bpy.app.handlers.render_complete.append(svg_export_animation)
+    @persistent
+    def freestyle_render_init(scene):
+        render = scene.render
+        if render.use_freestyle:
+            if render.use_svg_export:
+                from export_svg import svg_export_header
+                svg_export_header(scene)
 
-def unregister():
-    bpy.app.handlers.render_init.remove(svg_export_header)
-    bpy.app.handlers.render_complete.remove(svg_export_animation)
+    @persistent
+    def freestyle_render_complete(scene):
+        render = scene.render
+        if render.use_freestyle:
+            if render.use_svg_export and render.svg_mode == 'ANIMATION':
+                from export_svg import svg_export_animation
+                svg_export_animation(scene)
+
+    def register():
+        bpy.app.handlers.render_init.append(freestyle_render_init)
+        bpy.app.handlers.render_complete.append(freestyle_render_complete)
+
+    def unregister():
+        bpy.app.handlers.render_init.remove(freestyle_render_init)
+        bpy.app.handlers.render_complete.remove(freestyle_render_complete)
+
+else:
+    def register():
+        pass
+
+    def unregister():
+        pass
 
 if __name__ == '__main__':
     register()