[Bf-blender-cvs] [0edb2b8de91] blender2.8: Py io_utils: deprecate `orientation_helper_factory` and add new `orientation_helper` decorator.

Bastien Montagne noreply at git.blender.org
Fri Sep 21 19:32:08 CEST 2018


Commit: 0edb2b8de91647b8cca25ccdb0cba7816f5376d4
Author: Bastien Montagne
Date:   Fri Sep 21 19:28:39 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0edb2b8de91647b8cca25ccdb0cba7816f5376d4

Py io_utils: deprecate `orientation_helper_factory` and add new `orientation_helper` decorator.

This fixes warning about not using annotations, and a decorator here is
a much cleaner solution anyway.

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

M	release/scripts/modules/bpy_extras/io_utils.py

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

diff --git a/release/scripts/modules/bpy_extras/io_utils.py b/release/scripts/modules/bpy_extras/io_utils.py
index a0c1c3e5c84..c130f890822 100644
--- a/release/scripts/modules/bpy_extras/io_utils.py
+++ b/release/scripts/modules/bpy_extras/io_utils.py
@@ -21,6 +21,7 @@
 __all__ = (
     "ExportHelper",
     "ImportHelper",
+    "orientation_helper",
     "orientation_helper_factory",
     "axis_conversion",
     "axis_conversion_ensure",
@@ -121,7 +122,53 @@ class ImportHelper:
         return _check_axis_conversion(self)
 
 
+def orientation_helper(axis_forward='Y', axis_up='Z'):
+    def wrapper(cls):
+        def _update_axis_forward(self, context):
+            if self.axis_forward[-1] == self.axis_up[-1]:
+                self.axis_up = (self.axis_up[0:-1] +
+                                'XYZ'[('XYZ'.index(self.axis_up[-1]) + 1) % 3])
+
+        cls.__annotations__['axis_forward'] = EnumProperty(
+            name="Forward",
+            items=(
+                ('X', "X Forward", ""),
+                ('Y', "Y Forward", ""),
+                ('Z', "Z Forward", ""),
+                ('-X', "-X Forward", ""),
+                ('-Y', "-Y Forward", ""),
+                ('-Z', "-Z Forward", ""),
+            ),
+            default=axis_forward,
+            update=_update_axis_forward,
+        )
+
+        def _update_axis_up(self, context):
+            if self.axis_up[-1] == self.axis_forward[-1]:
+                self.axis_forward = (self.axis_forward[0:-1] +
+                                     'XYZ'[('XYZ'.index(self.axis_forward[-1]) + 1) % 3])
+
+        cls.__annotations__['axis_up'] = EnumProperty(
+            name="Up",
+            items=(
+                ('X', "X Up", ""),
+                ('Y', "Y Up", ""),
+                ('Z', "Z Up", ""),
+                ('-X', "-X Up", ""),
+                ('-Y', "-Y Up", ""),
+                ('-Z', "-Z Up", ""),
+            ),
+            default=axis_up,
+            update=_update_axis_up,
+        )
+
+        return cls
+
+    return wrapper
+
+
 def orientation_helper_factory(name, axis_forward='Y', axis_up='Z'):
+    print("WARNING! Using this helper function is deprecated, please switch to orientation_helper decorator instead.")
     members = {}
 
     def _update_axis_forward(self, context):



More information about the Bf-blender-cvs mailing list