Export_3ds: Added distance cue chunk export
[blender-addons.git] / magic_uv / utils / compatibility.py
blob6033e75c405556f050d80a2d53e3723dd4a6abbb
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 __author__ = "Nutti <nutti.metro@gmail.com>"
6 __status__ = "production"
7 __version__ = "6.7"
8 __date__ = "22 Sep 2022"
10 import bpy
11 import blf
14 def check_version(major, minor, _):
15 """
16 Check blender version
17 """
19 if bpy.app.version[0] == major and bpy.app.version[1] == minor:
20 return 0
21 if bpy.app.version[0] > major:
22 return 1
23 if bpy.app.version[1] > minor:
24 return 1
25 return -1
28 def make_annotations(cls):
29 if check_version(2, 80, 0) < 0:
30 return cls
32 # make annotation from attributes
33 props = {k: v
34 for k, v in cls.__dict__.items()
35 if isinstance(v, getattr(bpy.props, '_PropertyDeferred', tuple))}
36 if props:
37 if '__annotations__' not in cls.__dict__:
38 setattr(cls, '__annotations__', {})
39 annotations = cls.__dict__['__annotations__']
40 for k, v in props.items():
41 annotations[k] = v
42 delattr(cls, k)
44 return cls
47 class ChangeRegionType:
48 def __init__(self, *_, **kwargs):
49 self.region_type = kwargs.get('region_type', False)
51 def __call__(self, cls):
52 if check_version(2, 80, 0) >= 0:
53 return cls
55 cls.bl_region_type = self.region_type
57 return cls
60 def matmul(m1, m2):
61 if check_version(2, 80, 0) < 0:
62 return m1 * m2
64 return m1 @ m2
67 def layout_split(layout, factor=0.0, align=False):
68 if check_version(2, 80, 0) < 0:
69 return layout.split(percentage=factor, align=align)
71 return layout.split(factor=factor, align=align)
74 def get_user_preferences(context):
75 if hasattr(context, "user_preferences"):
76 return context.user_preferences
78 return context.preferences
81 def get_object_select(obj):
82 if check_version(2, 80, 0) < 0:
83 return obj.select
85 return obj.select_get()
88 def set_object_select(obj, select):
89 if check_version(2, 80, 0) < 0:
90 obj.select = select
91 else:
92 obj.select_set(select)
95 def set_active_object(obj):
96 if check_version(2, 80, 0) < 0:
97 bpy.context.scene.objects.active = obj
98 else:
99 bpy.context.view_layer.objects.active = obj
102 def get_active_object(context):
103 if check_version(2, 80, 0) < 0:
104 return context.scene.objects.active
105 else:
106 return context.view_layer.objects.active
109 def object_has_uv_layers(obj):
110 if check_version(2, 80, 0) < 0:
111 return hasattr(obj.data, "uv_textures")
112 else:
113 return hasattr(obj.data, "uv_layers")
116 def get_object_uv_layers(obj):
117 if check_version(2, 80, 0) < 0:
118 return obj.data.uv_textures
119 else:
120 return obj.data.uv_layers
123 def icon(icon):
124 if icon == 'IMAGE':
125 if check_version(2, 80, 0) < 0:
126 return 'IMAGE_COL'
128 return icon
131 def set_blf_font_color(font_id, r, g, b, a):
132 blf.color(font_id, r, g, b, a)
135 def set_blf_blur(font_id, radius):
136 if check_version(2, 80, 0) < 0:
137 blf.blur(font_id, radius)
140 def get_all_space_types():
141 if check_version(2, 80, 0) >= 0:
142 return {
143 'CLIP_EDITOR': bpy.types.SpaceClipEditor,
144 'CONSOLE': bpy.types.SpaceConsole,
145 'DOPESHEET_EDITOR': bpy.types.SpaceDopeSheetEditor,
146 'FILE_BROWSER': bpy.types.SpaceFileBrowser,
147 'GRAPH_EDITOR': bpy.types.SpaceGraphEditor,
148 'IMAGE_EDITOR': bpy.types.SpaceImageEditor,
149 'INFO': bpy.types.SpaceInfo,
150 'NLA_EDITOR': bpy.types.SpaceNLA,
151 'NODE_EDITOR': bpy.types.SpaceNodeEditor,
152 'OUTLINER': bpy.types.SpaceOutliner,
153 'PROPERTIES': bpy.types.SpaceProperties,
154 'SEQUENCE_EDITOR': bpy.types.SpaceSequenceEditor,
155 'TEXT_EDITOR': bpy.types.SpaceTextEditor,
156 'USER_PREFERENCES': bpy.types.SpacePreferences,
157 'VIEW_3D': bpy.types.SpaceView3D,
159 else:
160 return {
161 'VIEW_3D': bpy.types.SpaceView3D,
162 'TIMELINE': bpy.types.SpaceTimeline,
163 'GRAPH_EDITOR': bpy.types.SpaceGraphEditor,
164 'DOPESHEET_EDITOR': bpy.types.SpaceDopeSheetEditor,
165 'NLA_EDITOR': bpy.types.SpaceNLA,
166 'IMAGE_EDITOR': bpy.types.SpaceImageEditor,
167 'SEQUENCE_EDITOR': bpy.types.SpaceSequenceEditor,
168 'CLIP_EDITOR': bpy.types.SpaceClipEditor,
169 'TEXT_EDITOR': bpy.types.SpaceTextEditor,
170 'NODE_EDITOR': bpy.types.SpaceNodeEditor,
171 'LOGIC_EDITOR': bpy.types.SpaceLogicEditor,
172 'PROPERTIES': bpy.types.SpaceProperties,
173 'OUTLINER': bpy.types.SpaceOutliner,
174 'USER_PREFERENCES': bpy.types.SpaceUserPreferences,
175 'INFO': bpy.types.SpaceInfo,
176 'FILE_BROWSER': bpy.types.SpaceFileBrowser,
177 'CONSOLE': bpy.types.SpaceConsole,