diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-09-21 20:28:39 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-09-21 20:31:57 +0300 |
commit | 0edb2b8de91647b8cca25ccdb0cba7816f5376d4 (patch) | |
tree | 75f3c18d6973ef3f30b75dc9da5411b748f93ddd /release/scripts/modules | |
parent | a3020d5558322e8839e3f24039147baf7ef8c0dd (diff) |
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.
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/bpy_extras/io_utils.py | 47 |
1 files changed, 47 insertions, 0 deletions
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): |