[Bf-extensions-cvs] [5b25d73] temp-freestyle-svg: cleanup: remove unused imports, match style of existing addons

Campbell Barton noreply at git.blender.org
Mon Nov 24 23:08:39 CET 2014


Commit: 5b25d737733922faa181be8e795bcf2970c1a6fa
Author: Campbell Barton
Date:   Mon Nov 24 23:08:30 2014 +0100
Branches: temp-freestyle-svg
https://developer.blender.org/rBA5b25d737733922faa181be8e795bcf2970c1a6fa

cleanup: remove unused imports, match style of existing addons

===================================================================

M	render_freestyle_svg.py

===================================================================

diff --git a/render_freestyle_svg.py b/render_freestyle_svg.py
index 1724629..31e29f8 100644
--- a/render_freestyle_svg.py
+++ b/render_freestyle_svg.py
@@ -32,7 +32,6 @@ bl_info = {
 
 import bpy
 import parameter_editor
-import os
 
 import xml.etree.cElementTree as et
 
@@ -40,10 +39,8 @@ from freestyle.types import (
         StrokeShader,
         Interface0DIterator,
         Operators,
-        BinaryPredicate1D,
         )
 from freestyle.utils import getCurrentScene
-from freestyle.shaders import RoundCapShader, SquareCapShader
 from freestyle.functions import GetShapeF1D, CurveMaterialF0D
 from freestyle.predicates import (
         AndUP1D,
@@ -100,28 +97,39 @@ def create_path(scene) -> str:
     return scene.render.frame_path(frame).split(".")[0] + ".svg"
 
 
-class svg_export(bpy.types.PropertyGroup):
+class SVGExport(bpy.types.PropertyGroup):
     """Implements the properties for the SVG exporter"""
     bl_idname = "RENDER_PT_svg_export"
 
-    use_svg_export = BoolProperty(name="SVG Export", description="Export Freestyle edges to an .svg format")
-    split_at_invisible = BoolProperty(name="Split at Invisible", description="Split the stroke at an invisible vertex")
-    object_fill = BoolProperty(name="Fill Contours", description="Fill the contour with the object's material color")
-
-    _modes = [
-        ('FRAME', "Frame", "Export a single frame", 0),
-        ('ANIMATION', "Animation", "Export an animation", 1),
-        ]
-
-    mode = EnumProperty(items=_modes, name="Mode", default='FRAME')
-
-    _linejoins = [
-    ('MITTER', "Mitter", "Corners are sharp", 0),
-    ('ROUND', "Round", "Corners are smoothed", 1),
-    ('BEVEL', "Bevel", "Corners are bevelled", 2),
-    ]
-
-    linejoin = EnumProperty(items=_linejoins, name="Linejoin", default='ROUND')
+    use_svg_export = BoolProperty(
+            name="SVG Export",
+            description="Export Freestyle edges to an .svg format",
+            )
+    split_at_invisible = BoolProperty(
+            name="Split at Invisible",
+            description="Split the stroke at an invisible vertex",
+            )
+    object_fill = BoolProperty(
+            name="Fill Contours",
+            description="Fill the contour with the object's material color",
+            )
+    mode = EnumProperty(
+            name="Mode",
+            items=(
+                ('FRAME', "Frame", "Export a single frame", 0),
+                ('ANIMATION', "Animation", "Export an animation", 1),
+                ),
+            default='FRAME',
+            )
+    linejoin = EnumProperty(
+            name="Linejoin",
+            items=(
+                ('MITTER', "Mitter", "Corners are sharp", 0),
+                ('ROUND', "Round", "Corners are smoothed", 1),
+                ('BEVEL', "Bevel", "Corners are bevelled", 2),
+                ),
+            default='ROUND',
+            )
 
 
 class SVGExporterPanel(bpy.types.Panel):
@@ -154,9 +162,10 @@ class SVGExporterPanel(bpy.types.Panel):
         row = layout.row()
         row.prop(svg, "linejoin", expand=True)
 
+
 @persistent
 def svg_export_header(scene):
-    svg = scene.svg_export
+    # svg = scene.svg_export
     render = scene.render
 
     if not (render.use_freestyle and scene.svg_export.use_svg_export):
@@ -168,6 +177,7 @@ def svg_export_header(scene):
     with open(create_path(scene), "w") as f:
         f.write(svg_primitive.format(int(width), int(height)))
 
+
 @persistent
 def svg_export_animation(scene):
     """makes an animation of the exported SVG file """
@@ -222,6 +232,7 @@ def write_animation(filepath, frame_begin, fps=25):
     indent_xml(root)
     tree.write(filepath, encoding='ascii', xml_declaration=True)
 
+
 # - StrokeShaders - #
 class SVGPathShader(StrokeShader):
     """Stroke Shader for writing stroke data to a .svg file."""
@@ -267,7 +278,7 @@ class SVGPathShader(StrokeShader):
         for v in it:
             x, y = v.point
             yield '{:.3f}, {:.3f} '.format(x, height - y)
-            if split_at_invisible and v.attribute.visible == False:
+            if split_at_invisible and v.attribute.visible is False:
                 # end current and start new path;
                 yield '" />' + path
                 # fast-forward till the next visible vertex
@@ -348,7 +359,7 @@ class SVGFillShader(StrokeShader):
         for point in vertices:
             x, y = point
             yield '{:.3f}, {:.3f} '.format(x, height - y)
-        yield 'z" />' # closes the path; connects the current to the first point
+        yield 'z" />'  # closes the path; connects the current to the first point
 
     def write(self):
         """Write SVG data tree to file """
@@ -388,31 +399,32 @@ class SVGFillShader(StrokeShader):
         indent_xml(root)
         tree.write(self.filepath, encoding='ascii', xml_declaration=True)
 
-# - Callbacks - #
 
+# - Callbacks - #
 class ParameterEditorCallback(object):
     """Object to store callbacks for the Parameter Editor in"""
     def lineset_pre(self, scene, layer, lineset) -> None:
         raise NotImplementedError()
 
-    def modifier_post(self, scene, layer, lineset) -> [StrokeShader,]:
+    def modifier_post(self, scene, layer, lineset) -> [StrokeShader, ]:
         raise NotImplementedError()
 
     def lineset_post(self, scene, layer, lineset) -> None:
         raise NotImplementedError()
 
+
 class SVGPathShaderCallback(ParameterEditorCallback):
     @classmethod
-    def modifier_post(cls, scene, layer, lineset) -> [StrokeShader,]:
+    def modifier_post(cls, scene, layer, lineset) -> [StrokeShader, ]:
         if not (scene.render.use_freestyle and scene.svg_export.use_svg_export):
             return
 
         split = scene.svg_export.split_at_invisible
-        cls.shader = SVGPathShader.from_lineset(lineset, create_path(scene),
-                                                render_height(scene), split, scene.frame_current)
+        cls.shader = SVGPathShader.from_lineset(
+                lineset, create_path(scene),
+                render_height(scene), split, scene.frame_current)
         return [cls.shader]
 
-
     @classmethod
     def lineset_post(cls, scene, *args):
         if not (scene.render.use_freestyle and scene.svg_export.use_svg_export):
@@ -420,6 +432,7 @@ class SVGPathShaderCallback(ParameterEditorCallback):
 
         cls.shader.write()
 
+
 class SVGFillShaderCallback(ParameterEditorCallback):
     @staticmethod
     def lineset_post(scene, layer, lineset) -> None:
@@ -438,7 +451,7 @@ class SVGFillShaderCallback(ParameterEditorCallback):
         Operators.sort(pyZBP1D())
         # render and write fills
         shader = SVGFillShader(create_path(scene), render_height(scene), lineset.name)
-        Operators.create(TrueUP1D(), [shader,])
+        Operators.create(TrueUP1D(), [shader, ])
         shader.write()
 
 
@@ -458,15 +471,22 @@ def indent_xml(elem, level=0, indentsize=4):
         elem.tail = i
 
 
+classes = (
+    SVGExporterPanel,
+    SVGExport,
+    )
+
+
 def register():
-    # register UI
-    bpy.utils.register_class(SVGExporterPanel)
-    # register properties
-    bpy.utils.register_class(svg_export)
-    bpy.types.Scene.svg_export = bpy.props.PointerProperty(type=svg_export)
+
+    for cls in classes:
+        bpy.utils.register_class(cls)
+    bpy.types.Scene.svg_export = PointerProperty(type=SVGExport)
+
     # add callbacks
     bpy.app.handlers.render_init.append(svg_export_header)
     bpy.app.handlers.render_complete.append(svg_export_animation)
+
     # manipulate shaders list
     parameter_editor.callbacks_modifiers_post.append(SVGPathShaderCallback.modifier_post)
     parameter_editor.callbacks_lineset_post.append(SVGPathShaderCallback.lineset_post)
@@ -474,14 +494,15 @@ def register():
 
 
 def unregister():
-    # unregister UI
-    bpy.utils.unregister_class(SVGExporterPanel)
-    # unregister properties
-    bpy.utils.unregister_class(svg_export)
+
+    for cls in classes:
+        bpy.utils.unregister_class(cls)
     del bpy.types.Scene.svg_export
+
     # remove callbacks
     bpy.app.handlers.render_init.remove(svg_export_header)
     bpy.app.handlers.render_complete.remove(svg_export_animation)
+
     # manipulate shaders list
     parameter_editor.callbacks_modifiers_post.remove(SVGPathShaderCallback.modifier_post)
     parameter_editor.callbacks_lineset_post.remove(SVGPathShaderCallback.lineset_post)



More information about the Bf-extensions-cvs mailing list