Sun position: remove unused prop in HDRI mode
[blender-addons.git] / space_view3d_pie_menus / __init__.py
blob783f061a3e4593a8b82e4b1d3d089dcba8602284
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8 compliant>
21 # Contributed to by meta-androcto, pitiwazou, chromoly, italic
23 import bpy
24 from bpy.props import (
25 BoolProperty,
26 PointerProperty,
28 from bpy.types import (
29 PropertyGroup,
30 AddonPreferences,
34 bl_info = {
35 "name": "3D Viewport Pie Menus",
36 "author": "meta-androcto",
37 "version": (1, 2, 9),
38 "blender": (2, 80, 0),
39 "description": "Pie Menu Activation",
40 "location": "Addons Preferences",
41 "warning": "",
42 "doc_url": "{BLENDER_MANUAL_URL}/addons/interface/viewport_pies.html",
43 "category": "Interface"
46 sub_modules_names = (
47 "pie_modes_menu",
48 "pie_views_numpad_menu",
49 "pie_sculpt_menu",
50 "pie_origin",
51 "pie_manipulator_menu",
52 "pie_shading_menu",
53 "pie_align_menu",
54 "pie_delete_menu",
55 "pie_apply_transform_menu",
56 "pie_select_menu",
57 "pie_animation_menu",
58 "pie_save_open_menu",
59 "pie_editor_switch_menu",
60 "pie_defaults_menu",
61 "pie_proportional_menu",
65 sub_modules = [__import__(__package__ + "." + submod, {}, {}, submod) for submod in sub_modules_names]
66 sub_modules.sort(key=lambda mod: (mod.bl_info['category'], mod.bl_info['name']))
69 def _get_pref_class(mod):
70 import inspect
72 for obj in vars(mod).values():
73 if inspect.isclass(obj) and issubclass(obj, PropertyGroup):
74 if hasattr(obj, 'bl_idname') and obj.bl_idname == mod.__name__:
75 return obj
78 def get_addon_preferences(name=''):
79 """Acquisition and registration"""
80 addons = bpy.context.preferences.addons
81 if __name__ not in addons: # wm.read_factory_settings()
82 return None
83 addon_prefs = addons[__name__].preferences
84 if name:
85 if not hasattr(addon_prefs, name):
86 for mod in sub_modules:
87 if mod.__name__.split('.')[-1] == name:
88 cls = _get_pref_class(mod)
89 if cls:
90 prop = PointerProperty(type=cls)
91 create_property(PIEToolsPreferences, name, prop)
92 bpy.utils.unregister_class(PIEToolsPreferences)
93 bpy.utils.register_class(PIEToolsPreferences)
94 return getattr(addon_prefs, name, None)
95 else:
96 return addon_prefs
98 def create_property(cls, name, prop):
99 if not hasattr(cls, '__annotations__'):
100 cls.__annotations__ = dict()
101 cls.__annotations__[name] = prop
104 def register_submodule(mod):
105 mod.register()
106 mod.__addon_enabled__ = True
109 def unregister_submodule(mod):
110 if mod.__addon_enabled__:
111 mod.unregister()
112 mod.__addon_enabled__ = False
114 prefs = get_addon_preferences()
115 name = mod.__name__.split('.')[-1]
116 if hasattr(PIEToolsPreferences, name):
117 delattr(PIEToolsPreferences, name)
118 if prefs:
119 bpy.utils.unregister_class(PIEToolsPreferences)
120 bpy.utils.register_class(PIEToolsPreferences)
121 if name in prefs:
122 del prefs[name]
125 class PIEToolsPreferences(AddonPreferences):
126 bl_idname = __name__
128 def draw(self, context):
129 layout = self.layout
131 for mod in sub_modules:
132 mod_name = mod.__name__.split('.')[-1]
133 info = mod.bl_info
134 column = layout.column()
135 box = column.box()
137 # first stage
138 expand = getattr(self, 'show_expanded_' + mod_name)
139 icon = 'TRIA_DOWN' if expand else 'TRIA_RIGHT'
140 col = box.column()
141 row = col.row()
142 sub = row.row()
143 sub.context_pointer_set('addon_prefs', self)
144 op = sub.operator('wm.context_toggle', text='', icon=icon,
145 emboss=False)
146 op.data_path = 'addon_prefs.show_expanded_' + mod_name
147 sub.label(text='{}: {}'.format(info['category'], info['name']))
148 sub = row.row()
149 sub.alignment = 'RIGHT'
150 if info.get('warning'):
151 sub.label(text='', icon='ERROR')
152 sub.prop(self, 'use_' + mod_name, text='')
154 # The second stage
155 if expand:
156 if info.get('description'):
157 split = col.row().split(factor=0.15)
158 split.label(text='Description:')
159 split.label(text=info['description'])
160 if info.get('location'):
161 split = col.row().split(factor=0.15)
162 split.label(text='Location:')
163 split.label(text=info['location'])
165 if info.get('author'):
166 split = col.row().split(factor=0.15)
167 split.label(text='Author:')
168 split.label(text=info['author'])
170 if info.get('version'):
171 split = col.row().split(factor=0.15)
172 split.label(text='Version:')
173 split.label(text='.'.join(str(x) for x in info['version']),
174 translate=False)
175 if info.get('warning'):
176 split = col.row().split(factor=0.15)
177 split.label(text='Warning:')
178 split.label(text=' ' + info['warning'], icon='ERROR')
180 tot_row = int(bool(info.get('doc_url')))
181 if tot_row:
182 split = col.row().split(factor=0.15)
183 split.label(text='Internet:')
184 if info.get('doc_url'):
185 op = split.operator('wm.url_open',
186 text='Documentation', icon='HELP')
187 op.url = info.get('doc_url')
188 for i in range(4 - tot_row):
189 split.separator()
191 # Details and settings
192 if getattr(self, 'use_' + mod_name):
193 prefs = get_addon_preferences(mod_name)
195 if prefs and hasattr(prefs, 'draw'):
196 box = box.column()
197 prefs.layout = box
198 try:
199 prefs.draw(context)
200 except:
201 import traceback
202 traceback.print_exc()
203 box.label(text='Error (see console)', icon='ERROR')
204 del prefs.layout
206 row = layout.row()
207 row.label(text="End of Pie Menu Activations", icon="FILE_PARENT")
210 for mod in sub_modules:
211 info = mod.bl_info
212 mod_name = mod.__name__.split('.')[-1]
214 def gen_update(mod):
215 def update(self, context):
216 enabled = getattr(self, 'use_' + mod.__name__.split('.')[-1])
217 if enabled:
218 register_submodule(mod)
219 else:
220 unregister_submodule(mod)
221 mod.__addon_enabled__ = enabled
222 return update
224 create_property(
225 PIEToolsPreferences,
226 'use_' + mod_name,
227 BoolProperty(
228 name=info['name'],
229 description=info.get('description', ''),
230 update=gen_update(mod),
231 default=True,
234 create_property(
235 PIEToolsPreferences,
236 'show_expanded_' + mod_name,
237 BoolProperty())
240 classes = (
241 PIEToolsPreferences,
245 def register():
246 for cls in classes:
247 bpy.utils.register_class(cls)
249 prefs = get_addon_preferences()
250 for mod in sub_modules:
251 if not hasattr(mod, '__addon_enabled__'):
252 mod.__addon_enabled__ = False
253 name = mod.__name__.split('.')[-1]
254 if getattr(prefs, 'use_' + name):
255 register_submodule(mod)
258 def unregister():
259 for mod in sub_modules:
260 if mod.__addon_enabled__:
261 unregister_submodule(mod)
263 for cls in reversed(classes):
264 bpy.utils.unregister_class(cls)
267 if __name__ == "__main__":
268 register()