forked from pKrime/Expy-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_compatibility.py
47 lines (41 loc) · 1.73 KB
/
version_compatibility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -----------------------------------------------------------------------------
# Blender version utils
# -----------------------------------------------------------------------------
import operator
import bpy
if bpy.app.version >= (2, 80, 0):
matmul = operator.matmul
else:
matmul = operator.mul
def make_annotations(cls):
"""Add annotation attribute to fields to avoid Blender 2.8+ warnings"""
if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
return cls
if bpy.app.version < (2, 93, 0):
bl_props = {k: v for k, v in cls.__dict__.items()
if isinstance(v, tuple)}
else:
bl_props = {k: v for k, v in cls.__dict__.items()
if isinstance(v, bpy.props._PropertyDeferred)}
if bl_props:
if '__annotations__' not in cls.__dict__:
setattr(cls, '__annotations__', {})
annotations = cls.__dict__['__annotations__']
for k, v in bl_props.items():
annotations[k] = v
delattr(cls, k)
return cls
def layout_split(layout, factor=0.0, align=False):
"""Intermediate method for pre and post blender 2.8 split UI function"""
if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
return layout.split(percentage=factor, align=align)
return layout.split(factor=factor, align=align)
def get_preferences(context=None):
"""Intermediate method for pre and post blender 2.8 grabbing the preferences itself"""
if not context:
context = bpy.context
if hasattr(context, "user_preferences"):
return context.user_preferences
elif hasattr(context, "preferences"):
return context.preferences
return None