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"
8 __date__
= "22 Sep 2022"
14 def check_version(major
, minor
, _
):
19 if bpy
.app
.version
[0] == major
and bpy
.app
.version
[1] == minor
:
21 if bpy
.app
.version
[0] > major
:
23 if bpy
.app
.version
[1] > minor
:
28 def make_annotations(cls
):
29 if check_version(2, 80, 0) < 0:
32 # make annotation from attributes
34 for k
, v
in cls
.__dict
__.items()
35 if isinstance(v
, getattr(bpy
.props
, '_PropertyDeferred', tuple))}
37 if '__annotations__' not in cls
.__dict
__:
38 setattr(cls
, '__annotations__', {})
39 annotations
= cls
.__dict
__['__annotations__']
40 for k
, v
in props
.items():
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:
55 cls
.bl_region_type
= self
.region_type
61 if check_version(2, 80, 0) < 0:
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:
85 return obj
.select_get()
88 def set_object_select(obj
, select
):
89 if check_version(2, 80, 0) < 0:
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
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
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")
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
120 return obj
.data
.uv_layers
125 if check_version(2, 80, 0) < 0:
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:
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
,
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
,