Merge branch 'blender2.8' into userpref_redesign
[blender.git] / release / scripts / startup / bl_ui / space_userpref.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
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.
7 #
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.
12 #
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.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import (
22     Header,
23     Menu,
24     Panel,
25 )
26 from bpy.app.translations import pgettext_iface as iface_
27 from bpy.app.translations import contexts as i18n_contexts
28
29
30 class USERPREF_HT_header(Header):
31     bl_space_type = 'USER_PREFERENCES'
32
33     def draw(self, context):
34         layout = self.layout
35
36         # No need to show type selector.
37         # layout.template_header()
38
39         userpref = context.user_preferences
40
41         if userpref.active_section == 'INPUT':
42             layout.operator("wm.keyconfig_import", icon='IMPORT')
43             layout.operator("wm.keyconfig_export", icon='EXPORT')
44         elif userpref.active_section == 'ADDONS':
45             layout.operator("wm.addon_install", icon='FILEBROWSER')
46             layout.operator("wm.addon_refresh", icon='FILE_REFRESH')
47             layout.menu("USERPREF_MT_addons_online_resources")
48         elif userpref.active_section == 'LIGHTS':
49             layout.operator('wm.studiolight_install', text="Add MatCap").orientation = 'MATCAP'
50             layout.operator('wm.studiolight_install', text="Add World HDRI").orientation = 'WORLD'
51             layout.operator('wm.studiolight_install', text="Add Camera HDRI").orientation = 'CAMERA'
52         elif userpref.active_section == 'THEMES':
53             layout.operator("wm.theme_install", icon='FILEBROWSER')
54             layout.operator("ui.reset_default_theme", icon='LOOP_BACK')
55
56         layout.separator_spacer()
57
58         layout.operator_context = 'EXEC_AREA'
59         layout.operator("wm.save_userpref")
60
61
62 class USERPREF_PT_navigation(Panel):
63     bl_label = ""
64     bl_space_type = 'USER_PREFERENCES'
65     bl_region_type = 'UI'
66     bl_options = {'HIDE_HEADER'}
67
68     def draw(self, context):
69         layout = self.layout
70
71         userpref = context.user_preferences
72
73         col = layout.column()
74
75         col.prop(userpref, "active_section", expand=True)
76
77
78 class USERPREF_PT_interface(Panel):
79     bl_space_type = 'USER_PREFERENCES'
80     bl_label = "Interface"
81     bl_region_type = 'WINDOW'
82     bl_options = {'HIDE_HEADER'}
83
84     @classmethod
85     def poll(cls, context):
86         userpref = context.user_preferences
87         return (userpref.active_section == 'INTERFACE')
88
89     def draw(self, context):
90         layout = self.layout
91
92         userpref = context.user_preferences
93         view = userpref.view
94
95         split = layout.split()
96         row = split.row()
97         col = row.column()
98
99         col.label(text="Display:")
100         col.prop(view, "ui_scale", text="Scale")
101         col.prop(view, "ui_line_width", text="Line Width")
102         col.prop(view, "show_tooltips")
103         col.prop(view, "show_object_info", text="Object Info")
104         col.prop(view, "show_large_cursors")
105         col.prop(view, "show_view_name", text="View Name")
106         col.prop(view, "show_playback_fps", text="Playback FPS")
107         col.prop(view, "object_origin_size")
108
109         col.separator()
110
111         # col.prop(view, "show_gizmo_navigate")
112
113         sub = col.column(align=True)
114
115         sub.label(text="3D Viewport Axis:")
116         sub.row().prop(view, "mini_axis_type", text="")
117
118         sub = col.column(align=True)
119         sub.active = view.mini_axis_type == 'MINIMAL'
120         sub.prop(view, "mini_axis_size", text="Size")
121         sub.prop(view, "mini_axis_brightness", text="Brightness")
122
123         col.separator()
124
125         # Toolbox doesn't exist yet
126         # col.label(text="Toolbox:")
127         #col.prop(view, "show_column_layout")
128         #col.label(text="Open Toolbox Delay:")
129         #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
130         #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
131         col.prop(view, "show_gizmo", text="Gizmos")
132         sub = col.column()
133         sub.active = view.show_gizmo
134         sub.prop(view, "gizmo_size", text="Size")
135
136         col.separator()
137
138         col.label(text="Development:")
139         col.prop(view, "show_tooltips_python")
140         col.prop(view, "show_developer_ui")
141
142         row = split.row()
143         row.separator()
144         col = row.column()
145
146         col.prop(view, "use_mouse_depth_cursor")
147         col.prop(view, "use_cursor_lock_adjust")
148         col.prop(view, "use_mouse_depth_navigate")
149         col.prop(view, "use_zoom_to_mouse")
150         col.prop(view, "use_rotate_around_active")
151         col.prop(view, "use_camera_lock_parent")
152
153         col.separator()
154
155         col.prop(view, "use_auto_perspective")
156         col.prop(view, "smooth_view")
157         col.prop(view, "rotation_angle")
158
159         col.separator()
160         col.separator()
161
162         col.label(text="2D Viewports:")
163         col.prop(view, "view2d_grid_spacing_min", text="Minimum Grid Spacing")
164         col.prop(view, "timecode_style")
165         col.prop(view, "view_frame_type")
166         if view.view_frame_type == 'SECONDS':
167             col.prop(view, "view_frame_seconds")
168         elif view.view_frame_type == 'KEYFRAMES':
169             col.prop(view, "view_frame_keyframes")
170
171         row = split.row()
172         row.separator()
173         col = row.column()
174
175         col.label(text="Menus:")
176         col.prop(view, "use_mouse_over_open")
177         sub = col.column()
178         sub.active = view.use_mouse_over_open
179
180         sub.prop(view, "open_toplevel_delay", text="Top Level")
181         sub.prop(view, "open_sublevel_delay", text="Sub Level")
182
183         col.separator()
184         col.label(text="Pie Menus:")
185         sub = col.column(align=True)
186         sub.prop(view, "pie_animation_timeout")
187         sub.prop(view, "pie_initial_timeout")
188         sub.prop(view, "pie_menu_radius")
189         sub.prop(view, "pie_menu_threshold")
190         sub.prop(view, "pie_menu_confirm")
191         col.separator()
192
193         col.prop(view, "show_splash")
194
195         col.label(text="Warnings:")
196         col.prop(view, "use_quit_dialog")
197
198         col.separator()
199
200         col.label(text="App Template:")
201         col.label(text="Options intended for use with app-templates only.")
202         col.prop(view, "show_layout_ui")
203         col.prop(view, "show_view3d_cursor")
204
205
206 class USERPREF_PT_edit(Panel):
207     bl_space_type = 'USER_PREFERENCES'
208     bl_label = "Edit"
209     bl_region_type = 'WINDOW'
210     bl_options = {'HIDE_HEADER'}
211
212     @classmethod
213     def poll(cls, context):
214         userpref = context.user_preferences
215         return (userpref.active_section == 'EDITING')
216
217     def draw(self, context):
218         layout = self.layout
219
220         userpref = context.user_preferences
221         edit = userpref.edit
222
223         split = layout.split()
224         row = split.row()
225         col = row.column()
226
227         col.label(text="Link Materials To:")
228         col.prop(edit, "material_link", text="")
229
230         col.separator()
231         col.separator()
232         col.separator()
233
234         col.label(text="New Objects:")
235         col.prop(edit, "use_enter_edit_mode")
236         col.label(text="Align To:")
237         col.prop(edit, "object_align", text="")
238
239         col.separator()
240         col.separator()
241         col.separator()
242
243         col.label(text="Undo:")
244         col.prop(edit, "use_global_undo")
245         col.prop(edit, "undo_steps", text="Steps")
246         col.prop(edit, "undo_memory_limit", text="Memory Limit")
247
248         row = split.row()
249         row.separator()
250         col = row.column()
251
252         col.label(text="Grease Pencil/Annotations:")
253         col.separator()
254         col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
255         col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
256         col.separator()
257
258         col.label(text="Annotations:")
259         sub = col.row()
260         sub.prop(edit, "grease_pencil_default_color", text="Default Color")
261         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
262         col.separator()
263         col.prop(edit, "use_grease_pencil_simplify_stroke", text="Simplify Stroke")
264         col.separator()
265
266         col.separator()
267         col.separator()
268         col.separator()
269         col.label(text="Playback:")
270         col.prop(edit, "use_negative_frames")
271         col.separator()
272         col.label(text="Node Editor:")
273         col.prop(edit, "node_margin")
274         col.label(text="Animation Editors:")
275         col.prop(edit, "fcurve_unselected_alpha", text="F-Curve Visibility")
276
277         row = split.row()
278         row.separator()
279         col = row.column()
280
281         col.label(text="Keyframing:")
282         col.prop(edit, "use_visual_keying")
283         col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
284
285         col.separator()
286
287         col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
288         col.prop(edit, "use_auto_keying_warning")
289
290         sub = col.column()
291
292         # ~ sub.active = edit.use_keyframe_insert_auto # incorrect, time-line can enable
293         sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
294
295         col.separator()
296
297         col.label(text="New F-Curve Defaults:")
298         col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
299         col.prop(edit, "keyframe_new_handle_type", text="Handles")
300         col.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
301
302         col.separator()
303         col.separator()
304         col.separator()
305
306         col.label(text="Transform:")
307         col.prop(edit, "use_drag_immediately")
308         col.prop(edit, "use_numeric_input_advanced")
309
310         row = split.row()
311         row.separator()
312         col = row.column()
313
314         col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
315
316         col.separator()
317         col.separator()
318         col.separator()
319
320         col.label(text="Duplicate Data:")
321         col.prop(edit, "use_duplicate_mesh", text="Mesh")
322         col.prop(edit, "use_duplicate_surface", text="Surface")
323         col.prop(edit, "use_duplicate_curve", text="Curve")
324         col.prop(edit, "use_duplicate_text", text="Text")
325         col.prop(edit, "use_duplicate_metaball", text="Metaball")
326         col.prop(edit, "use_duplicate_armature", text="Armature")
327         col.prop(edit, "use_duplicate_light", text="Light")
328         col.prop(edit, "use_duplicate_material", text="Material")
329         col.prop(edit, "use_duplicate_texture", text="Texture")
330         #col.prop(edit, "use_duplicate_fcurve", text="F-Curve")
331         col.prop(edit, "use_duplicate_action", text="Action")
332         col.prop(edit, "use_duplicate_particle", text="Particle")
333
334
335 class USERPREF_PT_system_general(Panel):
336     bl_space_type = 'USER_PREFERENCES'
337     bl_label = "System General"
338     bl_region_type = 'WINDOW'
339     bl_options = {'HIDE_HEADER'}
340
341     @classmethod
342     def poll(cls, context):
343         userpref = context.user_preferences
344         return (userpref.active_section == 'SYSTEM_GENERAL')
345
346     def draw(self, context):
347         import sys
348         layout = self.layout
349
350         userpref = context.user_preferences
351         system = userpref.system
352
353         split = layout.split()
354
355         # 1. Column
356         column = split.column()
357         colsplit = column.split(factor=0.85)
358
359         col = colsplit.column()
360         col.label(text="General:")
361
362         col.prop(system, "scrollback", text="Console Scrollback")
363
364         col.separator()
365
366         col.label(text="Sound:")
367         col.row().prop(system, "audio_device", expand=False)
368         sub = col.column()
369         sub.active = system.audio_device not in {'NONE', 'Null'}
370         #sub.prop(system, "use_preview_images")
371         sub.prop(system, "audio_channels", text="Channels")
372         sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
373         sub.prop(system, "audio_sample_rate", text="Sample Rate")
374         sub.prop(system, "audio_sample_format", text="Sample Format")
375
376         col.separator()
377
378         if bpy.app.build_options.cycles:
379             addon = userpref.addons.get("cycles")
380             if addon is not None:
381                 addon.preferences.draw_impl(col, context)
382             del addon
383
384         if hasattr(system, "opensubdiv_compute_type"):
385             col.label(text="OpenSubdiv compute:")
386             col.row().prop(system, "opensubdiv_compute_type", text="")
387
388         # 2. Column
389         column = split.column()
390         colsplit = column.split(factor=0.85)
391
392         col = colsplit.column()
393         col.label(text="OpenGL:")
394         col.prop(system, "gl_clip_alpha", slider=True)
395         col.prop(system, "use_gpu_mipmap")
396         col.prop(system, "use_16bit_textures")
397
398         col.separator()
399         col.label(text="Selection:")
400         col.prop(system, "select_method", text="")
401         col.prop(system, "use_select_pick_depth")
402
403         col.separator()
404
405         col.label(text="Anisotropic Filtering:")
406         col.prop(system, "anisotropic_filter", text="")
407
408         col.separator()
409
410         col.prop(system, "multi_sample", text="")
411         if sys.platform == "linux" and system.multi_sample != 'NONE':
412             col.label(text="Might fail for Mesh editing selection!")
413             col.separator()
414         col.prop(system, "use_region_overlap")
415
416         col.separator()
417         col.prop(system, "gpu_viewport_quality")
418
419         col.separator()
420         col.label(text="Grease Pencil Options:")
421         col.prop(system, "gpencil_multi_sample", text="")
422
423         col.separator()
424         col.label(text="Text Draw Options:")
425         col.prop(system, "use_text_antialiasing", text="Anti-aliasing")
426         sub = col.column()
427         sub.active = system.use_text_antialiasing
428         sub.prop(system, "text_hinting", text="Hinting")
429
430         # 3. Column
431         column = split.column()
432
433         column.label(text="Textures:")
434         column.prop(system, "gl_texture_limit", text="Limit Size")
435         column.prop(system, "texture_time_out", text="Time Out")
436         column.prop(system, "texture_collection_rate", text="Collection Rate")
437
438         column.separator()
439
440         column.label(text="Images Draw Method:")
441         column.prop(system, "image_draw_method", text="")
442
443         column.separator()
444
445         column.label(text="Sequencer/Clip Editor:")
446         # currently disabled in the code
447         # column.prop(system, "prefetch_frames")
448         column.prop(system, "memory_cache_limit")
449
450         column.separator()
451
452         column.label(text="Color Picker Type:")
453         column.row().prop(system, "color_picker_type", text="")
454
455         column.separator()
456
457         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
458         sub = column.column()
459         sub.active = system.use_weight_color_range
460         sub.template_color_ramp(system, "weight_color_range", expand=True)
461
462         column.separator()
463         column.prop(system, "font_path_ui")
464         column.prop(system, "font_path_ui_mono")
465
466         if bpy.app.build_options.international:
467             column.prop(system, "use_international_fonts")
468             sub_col = column.column()
469             sub_col.active = system.use_international_fonts
470             sub_col.prop(system, "language")
471             row = sub_col.row()
472             row.label(text="Translate:", text_ctxt=i18n_contexts.id_windowmanager)
473             row = sub_col.row(align=True)
474             row.prop(system, "use_translate_tooltips", text="Tooltips", toggle=True)
475             row.prop(system, "use_translate_interface", text="Interface", toggle=True)
476             row.prop(system, "use_translate_new_dataname", text="New Data", toggle=True)
477
478
479 class USERPREF_MT_interface_theme_presets(Menu):
480     bl_label = "Presets"
481     preset_subdir = "interface_theme"
482     preset_operator = "script.execute_preset"
483     preset_type = 'XML'
484     preset_xml_map = (
485         ("user_preferences.themes[0]", "Theme"),
486         ("user_preferences.ui_styles[0]", "ThemeStyle"),
487     )
488     draw = Menu.draw_preset
489
490     def reset_cb(context):
491         bpy.ops.ui.reset_default_theme()
492
493
494 class USERPREF_PT_theme(Panel):
495     bl_space_type = 'USER_PREFERENCES'
496     bl_label = "Themes"
497     bl_region_type = 'WINDOW'
498     bl_options = {'HIDE_HEADER'}
499
500     # not essential, hard-coded UI delimiters for the theme layout
501     ui_delimiters = {
502         'VIEW_3D': {
503             "text_grease_pencil",
504             "text_keyframe",
505             "speaker",
506             "freestyle_face_mark",
507             "split_normal",
508             "bone_solid",
509             "paint_curve_pivot",
510         },
511         'GRAPH_EDITOR': {
512             "handle_vertex_select",
513         },
514         'IMAGE_EDITOR': {
515             "paint_curve_pivot",
516         },
517         'NODE_EDITOR': {
518             "layout_node",
519         },
520         'CLIP_EDITOR': {
521             "handle_vertex_select",
522         }
523     }
524
525     @staticmethod
526     def _theme_generic(split, themedata, theme_area):
527
528         col = split.column()
529
530         def theme_generic_recurse(data):
531             col.label(text=data.rna_type.name)
532             row = col.row()
533             subsplit = row.split(factor=0.95)
534
535             padding1 = subsplit.split(factor=0.15)
536             padding1.column()
537
538             subsplit = row.split(factor=0.85)
539
540             padding2 = subsplit.split(factor=0.15)
541             padding2.column()
542
543             colsub_pair = padding1.column(), padding2.column()
544
545             props_type = {}
546
547             for i, prop in enumerate(data.rna_type.properties):
548                 if prop.identifier == "rna_type":
549                     continue
550
551                 props_type.setdefault((prop.type, prop.subtype), []).append(prop)
552
553             th_delimiters = USERPREF_PT_theme.ui_delimiters.get(theme_area)
554             for props_type, props_ls in sorted(props_type.items()):
555                 if props_type[0] == 'POINTER':
556                     for i, prop in enumerate(props_ls):
557                         theme_generic_recurse(getattr(data, prop.identifier))
558                 else:
559                     if th_delimiters is None:
560                         # simple, no delimiters
561                         for i, prop in enumerate(props_ls):
562                             colsub_pair[i % 2].row().prop(data, prop.identifier)
563                     else:
564                         # add hard coded delimiters
565                         i = 0
566                         for prop in props_ls:
567                             colsub = colsub_pair[i]
568                             colsub.row().prop(data, prop.identifier)
569                             i = (i + 1) % 2
570                             if prop.identifier in th_delimiters:
571                                 if i:
572                                     colsub = colsub_pair[1]
573                                     colsub.row().label(text="")
574                                 colsub_pair[0].row().label(text="")
575                                 colsub_pair[1].row().label(text="")
576                                 i = 0
577
578         theme_generic_recurse(themedata)
579
580     @staticmethod
581     def _theme_widget_style(layout, widget_style):
582
583         row = layout.row()
584
585         subsplit = row.split(factor=0.95)
586
587         padding = subsplit.split(factor=0.15)
588         colsub = padding.column()
589         colsub = padding.column()
590         colsub.row().prop(widget_style, "outline")
591         colsub.row().prop(widget_style, "item", slider=True)
592         colsub.row().prop(widget_style, "inner", slider=True)
593         colsub.row().prop(widget_style, "inner_sel", slider=True)
594         colsub.row().prop(widget_style, "roundness")
595
596         subsplit = row.split(factor=0.85)
597
598         padding = subsplit.split(factor=0.15)
599         colsub = padding.column()
600         colsub = padding.column()
601         colsub.row().prop(widget_style, "text")
602         colsub.row().prop(widget_style, "text_sel")
603         colsub.prop(widget_style, "show_shaded")
604         subsub = colsub.column(align=True)
605         subsub.active = widget_style.show_shaded
606         subsub.prop(widget_style, "shadetop")
607         subsub.prop(widget_style, "shadedown")
608
609         layout.separator()
610
611     @staticmethod
612     def _ui_font_style(layout, font_style):
613
614         split = layout.split()
615
616         col = split.column()
617         col.label(text="Kerning Style:")
618         col.row().prop(font_style, "font_kerning_style", expand=True)
619         col.prop(font_style, "points")
620
621         col = split.column()
622         col.label(text="Shadow Offset:")
623         col.prop(font_style, "shadow_offset_x", text="X")
624         col.prop(font_style, "shadow_offset_y", text="Y")
625
626         col = split.column()
627         col.prop(font_style, "shadow")
628         col.prop(font_style, "shadow_alpha")
629         col.prop(font_style, "shadow_value")
630
631         layout.separator()
632
633     @classmethod
634     def poll(cls, context):
635         userpref = context.user_preferences
636         return (userpref.active_section == 'THEMES')
637
638     def draw(self, context):
639         layout = self.layout
640
641         theme = context.user_preferences.themes[0]
642
643         split_themes = layout.split(factor=0.2)
644
645         sub = split_themes.column()
646
647         sub.label(text="Presets:")
648         subrow = sub.row(align=True)
649
650         subrow.menu("USERPREF_MT_interface_theme_presets", text=USERPREF_MT_interface_theme_presets.bl_label)
651         subrow.operator("wm.interface_theme_preset_add", text="", icon='ADD')
652         subrow.operator("wm.interface_theme_preset_add", text="", icon='REMOVE').remove_active = True
653         sub.separator()
654
655         sub.prop(theme, "theme_area", expand=True)
656
657         split = layout.split(factor=0.4)
658
659         layout.separator()
660         layout.separator()
661
662         split = split_themes.split()
663
664         if theme.theme_area == 'USER_INTERFACE':
665             col = split.column()
666             ui = theme.user_interface
667
668             col.label(text="Regular:")
669             self._theme_widget_style(col, ui.wcol_regular)
670
671             col.label(text="Tool:")
672             self._theme_widget_style(col, ui.wcol_tool)
673
674             col.label(text="Toolbar Item:")
675             self._theme_widget_style(col, ui.wcol_toolbar_item)
676
677             col.label(text="Radio Buttons:")
678             self._theme_widget_style(col, ui.wcol_radio)
679
680             col.label(text="Text:")
681             self._theme_widget_style(col, ui.wcol_text)
682
683             col.label(text="Option:")
684             self._theme_widget_style(col, ui.wcol_option)
685
686             col.label(text="Toggle:")
687             self._theme_widget_style(col, ui.wcol_toggle)
688
689             col.label(text="Number Field:")
690             self._theme_widget_style(col, ui.wcol_num)
691
692             col.label(text="Value Slider:")
693             self._theme_widget_style(col, ui.wcol_numslider)
694
695             col.label(text="Box:")
696             self._theme_widget_style(col, ui.wcol_box)
697
698             col.label(text="Menu:")
699             self._theme_widget_style(col, ui.wcol_menu)
700
701             col.label(text="Pie Menu:")
702             self._theme_widget_style(col, ui.wcol_pie_menu)
703
704             col.label(text="Pulldown:")
705             self._theme_widget_style(col, ui.wcol_pulldown)
706
707             col.label(text="Menu Back:")
708             self._theme_widget_style(col, ui.wcol_menu_back)
709
710             col.label(text="Tooltip:")
711             self._theme_widget_style(col, ui.wcol_tooltip)
712
713             col.label(text="Menu Item:")
714             self._theme_widget_style(col, ui.wcol_menu_item)
715
716             col.label(text="Scroll Bar:")
717             self._theme_widget_style(col, ui.wcol_scroll)
718
719             col.label(text="Progress Bar:")
720             self._theme_widget_style(col, ui.wcol_progress)
721
722             col.label(text="List Item:")
723             self._theme_widget_style(col, ui.wcol_list_item)
724
725             col.label(text="Tab:")
726             self._theme_widget_style(col, ui.wcol_tab)
727
728             ui_state = theme.user_interface.wcol_state
729             col.label(text="State:")
730
731             row = col.row()
732
733             subsplit = row.split(factor=0.95)
734
735             padding = subsplit.split(factor=0.15)
736             colsub = padding.column()
737             colsub = padding.column()
738             colsub.row().prop(ui_state, "inner_anim")
739             colsub.row().prop(ui_state, "inner_anim_sel")
740             colsub.row().prop(ui_state, "inner_driven")
741             colsub.row().prop(ui_state, "inner_driven_sel")
742             colsub.row().prop(ui_state, "blend")
743
744             subsplit = row.split(factor=0.85)
745
746             padding = subsplit.split(factor=0.15)
747             colsub = padding.column()
748             colsub = padding.column()
749             colsub.row().prop(ui_state, "inner_key")
750             colsub.row().prop(ui_state, "inner_key_sel")
751             colsub.row().prop(ui_state, "inner_overridden")
752             colsub.row().prop(ui_state, "inner_overridden_sel")
753
754             col.separator()
755             col.separator()
756
757             col.label(text="Styles:")
758
759             row = col.row()
760
761             subsplit = row.split(factor=0.95)
762
763             padding = subsplit.split(factor=0.15)
764             colsub = padding.column()
765             colsub = padding.column()
766             colsub.row().prop(ui, "menu_shadow_fac")
767             colsub.row().prop(ui, "icon_alpha")
768             colsub.row().prop(ui, "icon_saturation")
769             colsub.row().prop(ui, "editor_outline")
770
771             subsplit = row.split(factor=0.85)
772
773             padding = subsplit.split(factor=0.15)
774             colsub = padding.column()
775             colsub = padding.column()
776             colsub.row().prop(ui, "menu_shadow_width")
777             colsub.row().prop(ui, "widget_emboss")
778
779             col.separator()
780             col.separator()
781
782             col.label(text="Axis & Gizmo Colors:")
783
784             row = col.row()
785
786             subsplit = row.split(factor=0.95)
787
788             padding = subsplit.split(factor=0.15)
789             colsub = padding.column()
790             colsub = padding.column()
791             colsub.row().prop(ui, "axis_x")
792             colsub.row().prop(ui, "axis_y")
793             colsub.row().prop(ui, "axis_z")
794
795             subsplit = row.split(factor=0.85)
796
797             padding = subsplit.split(factor=0.15)
798             colsub = padding.column()
799             colsub = padding.column()
800             colsub.row().prop(ui, "gizmo_primary")
801             colsub.row().prop(ui, "gizmo_secondary")
802             colsub.row().prop(ui, "gizmo_a")
803             colsub.row().prop(ui, "gizmo_b")
804
805             col.separator()
806             col.separator()
807
808             col.label(text="Icon Colors:")
809
810             row = col.row()
811
812             subsplit = row.split(factor=0.95)
813
814             padding = subsplit.split(factor=0.15)
815             colsub = padding.column()
816             colsub = padding.column()
817             colsub.row().prop(ui, "icon_collection")
818             colsub.row().prop(ui, "icon_object")
819             colsub.row().prop(ui, "icon_object_data")
820
821             subsplit = row.split(factor=0.85)
822
823             padding = subsplit.split(factor=0.15)
824             colsub = padding.column()
825             colsub = padding.column()
826             colsub.row().prop(ui, "icon_modifier")
827             colsub.row().prop(ui, "icon_shading")
828
829             col.separator()
830             col.separator()
831         elif theme.theme_area == 'BONE_COLOR_SETS':
832             col = split.column()
833
834             for i, ui in enumerate(theme.bone_color_sets, 1):
835                 col.label(text=iface_(f"Color Set {i:d}"), translate=False)
836
837                 row = col.row()
838
839                 subsplit = row.split(factor=0.95)
840
841                 padding = subsplit.split(factor=0.15)
842                 colsub = padding.column()
843                 colsub = padding.column()
844                 colsub.row().prop(ui, "normal")
845                 colsub.row().prop(ui, "select")
846                 colsub.row().prop(ui, "active")
847
848                 subsplit = row.split(factor=0.85)
849
850                 padding = subsplit.split(factor=0.15)
851                 colsub = padding.column()
852                 colsub = padding.column()
853                 colsub.row().prop(ui, "show_colored_constraints")
854         elif theme.theme_area == 'STYLE':
855             col = split.column()
856
857             style = context.user_preferences.ui_styles[0]
858
859             col.label(text="Panel Title:")
860             self._ui_font_style(col, style.panel_title)
861
862             col.separator()
863
864             col.label(text="Widget:")
865             self._ui_font_style(col, style.widget)
866
867             col.separator()
868
869             col.label(text="Widget Label:")
870             self._ui_font_style(col, style.widget_label)
871         else:
872             self._theme_generic(split, getattr(theme, theme.theme_area.lower()), theme.theme_area)
873
874
875 class USERPREF_PT_file(Panel):
876     bl_space_type = 'USER_PREFERENCES'
877     bl_label = "Files"
878     bl_region_type = 'WINDOW'
879     bl_options = {'HIDE_HEADER'}
880
881     @classmethod
882     def poll(cls, context):
883         userpref = context.user_preferences
884         return (userpref.active_section == 'FILES')
885
886     def draw(self, context):
887         layout = self.layout
888
889         userpref = context.user_preferences
890         paths = userpref.filepaths
891         system = userpref.system
892
893         split = layout.split(factor=0.7)
894
895         col = split.column()
896         col.label(text="File Paths:")
897
898         colsplit = col.split(factor=0.95)
899         col1 = colsplit.split(factor=0.3)
900
901         sub = col1.column()
902         sub.label(text="Fonts:")
903         sub.label(text="Textures:")
904         sub.label(text="Render Output:")
905         sub.label(text="Scripts:")
906         sub.label(text="Sounds:")
907         sub.label(text="Temp:")
908         sub.label(text="Render Cache:")
909         sub.label(text="I18n Branches:")
910         sub.label(text="Image Editor:")
911         sub.label(text="Animation Player:")
912
913         sub = col1.column()
914         sub.prop(paths, "font_directory", text="")
915         sub.prop(paths, "texture_directory", text="")
916         sub.prop(paths, "render_output_directory", text="")
917         sub.prop(paths, "script_directory", text="")
918         sub.prop(paths, "sound_directory", text="")
919         sub.prop(paths, "temporary_directory", text="")
920         sub.prop(paths, "render_cache_directory", text="")
921         sub.prop(paths, "i18n_branches_directory", text="")
922         sub.prop(paths, "image_editor", text="")
923         subsplit = sub.split(factor=0.3)
924         subsplit.prop(paths, "animation_player_preset", text="")
925         subsplit.prop(paths, "animation_player", text="")
926
927         col.separator()
928         col.separator()
929
930         colsplit = col.split(factor=0.95)
931         sub = colsplit.column()
932
933         row = sub.split(factor=0.3)
934         row.label(text="Auto Execution:")
935         row.prop(system, "use_scripts_auto_execute")
936
937         if system.use_scripts_auto_execute:
938             box = sub.box()
939             row = box.row()
940             row.label(text="Excluded Paths:")
941             row.operator("wm.userpref_autoexec_path_add", text="", icon='ADD', emboss=False)
942             for i, path_cmp in enumerate(userpref.autoexec_paths):
943                 row = box.row()
944                 row.prop(path_cmp, "path", text="")
945                 row.prop(path_cmp, "use_glob", text="", icon='FILTER')
946                 row.operator("wm.userpref_autoexec_path_remove", text="", icon='X', emboss=False).index = i
947
948         col = split.column()
949         col.label(text="Save & Load:")
950         col.prop(paths, "use_relative_paths")
951         col.prop(paths, "use_file_compression")
952         col.prop(paths, "use_load_ui")
953         col.prop(paths, "use_filter_files")
954         col.prop(paths, "show_hidden_files_datablocks")
955         col.prop(paths, "hide_recent_locations")
956         col.prop(paths, "hide_system_bookmarks")
957         col.prop(paths, "show_thumbnails")
958
959         col.separator()
960
961         col.prop(paths, "save_version")
962         col.prop(paths, "recent_files")
963         col.prop(paths, "use_save_preview_images")
964
965         col.separator()
966
967         col.label(text="Auto Save:")
968         col.prop(paths, "use_keep_session")
969         col.prop(paths, "use_auto_save_temporary_files")
970         sub = col.column()
971         sub.active = paths.use_auto_save_temporary_files
972         sub.prop(paths, "auto_save_time", text="Timer (mins)")
973
974         col.separator()
975
976         col.label(text="Text Editor:")
977         col.prop(system, "use_tabs_as_spaces")
978
979         colsplit = col.split(factor=0.95)
980         col1 = colsplit.split(factor=0.3)
981
982         sub = col1.column()
983         sub.label(text="Author:")
984         sub = col1.column()
985         sub.prop(system, "author", text="")
986
987
988 class USERPREF_MT_ndof_settings(Menu):
989     # accessed from the window key-bindings in C (only)
990     bl_label = "3D Mouse Settings"
991
992     def draw(self, context):
993         layout = self.layout
994
995         input_prefs = context.user_preferences.inputs
996
997         is_view3d = context.space_data.type == 'VIEW_3D'
998
999         layout.prop(input_prefs, "ndof_sensitivity")
1000         layout.prop(input_prefs, "ndof_orbit_sensitivity")
1001         layout.prop(input_prefs, "ndof_deadzone")
1002
1003         if is_view3d:
1004             layout.separator()
1005             layout.prop(input_prefs, "ndof_show_guide")
1006
1007             layout.separator()
1008             layout.label(text="Orbit Style")
1009             layout.row().prop(input_prefs, "ndof_view_navigate_method", text="")
1010             layout.row().prop(input_prefs, "ndof_view_rotate_method", text="")
1011             layout.separator()
1012             layout.label(text="Orbit Options")
1013             layout.prop(input_prefs, "ndof_rotx_invert_axis")
1014             layout.prop(input_prefs, "ndof_roty_invert_axis")
1015             layout.prop(input_prefs, "ndof_rotz_invert_axis")
1016
1017         # view2d use pan/zoom
1018         layout.separator()
1019         layout.label(text="Pan Options")
1020         layout.prop(input_prefs, "ndof_panx_invert_axis")
1021         layout.prop(input_prefs, "ndof_pany_invert_axis")
1022         layout.prop(input_prefs, "ndof_panz_invert_axis")
1023         layout.prop(input_prefs, "ndof_pan_yz_swap_axis")
1024
1025         layout.label(text="Zoom Options")
1026         layout.prop(input_prefs, "ndof_zoom_invert")
1027
1028         if is_view3d:
1029             layout.separator()
1030             layout.label(text="Fly/Walk Options")
1031             layout.prop(input_prefs, "ndof_fly_helicopter", icon='NDOF_FLY')
1032             layout.prop(input_prefs, "ndof_lock_horizon", icon='NDOF_DOM')
1033
1034
1035 class USERPREF_MT_keyconfigs(Menu):
1036     bl_label = "KeyPresets"
1037     preset_subdir = "keyconfig"
1038     preset_operator = "wm.keyconfig_activate"
1039
1040     def draw(self, context):
1041         Menu.draw_preset(self, context)
1042
1043
1044 class USERPREF_PT_input(Panel):
1045     bl_space_type = 'USER_PREFERENCES'
1046     bl_label = "Input"
1047     bl_region_type = 'WINDOW'
1048     bl_options = {'HIDE_HEADER'}
1049
1050     @classmethod
1051     def poll(cls, context):
1052         userpref = context.user_preferences
1053         return (userpref.active_section == 'INPUT')
1054
1055     @staticmethod
1056     def draw_input_prefs(inputs, layout):
1057         import sys
1058
1059         # General settings
1060         sub = layout.column()
1061
1062         sub.label(text="Mouse:")
1063         sub.prop(inputs, "use_mouse_emulate_3_button")
1064         sub.prop(inputs, "use_mouse_continuous")
1065         sub.prop(inputs, "drag_threshold")
1066         sub.prop(inputs, "tweak_threshold")
1067
1068         sub = layout.column()
1069         sub.label(text="Double Click:")
1070         sub.prop(inputs, "mouse_double_click_time", text="Speed")
1071
1072         sub.separator()
1073
1074         sub.prop(inputs, "use_emulate_numpad")
1075
1076         sub.separator()
1077
1078         sub.label(text="Orbit Style:")
1079         sub.row().prop(inputs, "view_rotate_method", expand=True)
1080
1081         sub.separator()
1082
1083         sub.label(text="Zoom Style:")
1084         sub.row().prop(inputs, "view_zoom_method", text="")
1085         if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
1086             sub.row().prop(inputs, "view_zoom_axis", expand=True)
1087             sub.prop(inputs, "invert_mouse_zoom", text="Invert Mouse Zoom Direction")
1088
1089         #sub.prop(inputs, "use_mouse_mmb_paste")
1090
1091         # layout.separator()
1092
1093         sub = layout.column()
1094         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
1095         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
1096
1097         if sys.platform == "darwin":
1098             sub = layout.column()
1099             sub.prop(inputs, "use_trackpad_natural", text="Natural Trackpad Direction")
1100
1101         layout.separator()
1102         sub = layout.column()
1103         sub.label(text="View Navigation:")
1104         sub.row().prop(inputs, "navigation_mode", expand=True)
1105
1106         sub.label(text="Walk Navigation:")
1107
1108         walk = inputs.walk_navigation
1109
1110         sub.prop(walk, "use_mouse_reverse")
1111         sub.prop(walk, "mouse_speed")
1112         sub.prop(walk, "teleport_time")
1113
1114         sub = layout.column(align=True)
1115         sub.prop(walk, "walk_speed")
1116         sub.prop(walk, "walk_speed_factor")
1117
1118         sub.separator()
1119         sub.prop(walk, "use_gravity")
1120         sub = layout.column(align=True)
1121         sub.active = walk.use_gravity
1122         sub.prop(walk, "view_height")
1123         sub.prop(walk, "jump_height")
1124
1125         sub.separator()
1126         sub = layout.column()
1127         sub.label(text="Tablet Pressure:")
1128         sub.prop(inputs, "pressure_threshold_max")
1129         sub.prop(inputs, "pressure_softness")
1130
1131         if inputs.use_ndof:
1132             layout.separator()
1133             layout.label(text="NDOF Device:")
1134             sub = layout.column(align=True)
1135             sub.prop(inputs, "ndof_sensitivity", text="Pan Sensitivity")
1136             sub.prop(inputs, "ndof_orbit_sensitivity", text="Orbit Sensitivity")
1137             sub.prop(inputs, "ndof_deadzone", text="Deadzone")
1138
1139             sub.separator()
1140             layout.label(text="Navigation Style:")
1141             sub = layout.column(align=True)
1142             sub.row().prop(inputs, "ndof_view_navigate_method", expand=True)
1143
1144             sub.separator()
1145             layout.label(text="Rotation Style:")
1146             sub = layout.column(align=True)
1147             sub.row().prop(inputs, "ndof_view_rotate_method", expand=True)
1148
1149     def draw(self, context):
1150         from rna_keymap_ui import draw_keymaps
1151
1152         layout = self.layout
1153
1154         #import time
1155
1156         #start = time.time()
1157
1158         userpref = context.user_preferences
1159
1160         inputs = userpref.inputs
1161
1162         split = layout.split(factor=0.25)
1163
1164         row = split.row()
1165         col = row.column()
1166
1167         # Input settings
1168         self.draw_input_prefs(inputs, col)
1169
1170         row.separator()
1171
1172         # Keymap Settings
1173         col = split.column()
1174         draw_keymaps(context, col)
1175
1176         #print("runtime", time.time() - start)
1177
1178
1179 class USERPREF_MT_addons_online_resources(Menu):
1180     bl_label = "Online Resources"
1181
1182     # menu to open web-pages with addons development guides
1183     def draw(self, context):
1184         layout = self.layout
1185
1186         layout.operator(
1187             "wm.url_open", text="Add-ons Catalog", icon='URL',
1188         ).url = "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts"
1189
1190         layout.separator()
1191
1192         layout.operator(
1193             "wm.url_open", text="How to share your add-on", icon='URL',
1194         ).url = "http://wiki.blender.org/index.php/Dev:Py/Sharing"
1195         layout.operator(
1196             "wm.url_open", text="Add-on Guidelines", icon='URL',
1197         ).url = "http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons"
1198         layout.operator(
1199             "wm.url_open", text="API Concepts", icon='URL',
1200         ).url = bpy.types.WM_OT_doc_view._prefix + "/info_quickstart.html"
1201         layout.operator(
1202             "wm.url_open", text="Add-on Tutorial", icon='URL',
1203         ).url = bpy.types.WM_OT_doc_view._prefix + "/info_tutorial_addon.html"
1204
1205
1206 class USERPREF_PT_addons(Panel):
1207     bl_space_type = 'USER_PREFERENCES'
1208     bl_label = "Add-ons"
1209     bl_region_type = 'WINDOW'
1210     bl_options = {'HIDE_HEADER'}
1211
1212     _support_icon_mapping = {
1213         'OFFICIAL': 'FILE_BLEND',
1214         'COMMUNITY': 'COMMUNITY',
1215         'TESTING': 'EXPERIMENTAL',
1216     }
1217
1218     @classmethod
1219     def poll(cls, context):
1220         userpref = context.user_preferences
1221         return (userpref.active_section == 'ADDONS')
1222
1223     @staticmethod
1224     def is_user_addon(mod, user_addon_paths):
1225         import os
1226
1227         if not user_addon_paths:
1228             for path in (
1229                     bpy.utils.script_path_user(),
1230                     bpy.utils.script_path_pref(),
1231             ):
1232                 if path is not None:
1233                     user_addon_paths.append(os.path.join(path, "addons"))
1234
1235         for path in user_addon_paths:
1236             if bpy.path.is_subdir(mod.__file__, path):
1237                 return True
1238         return False
1239
1240     @staticmethod
1241     def draw_error(layout, message):
1242         lines = message.split("\n")
1243         box = layout.box()
1244         sub = box.row()
1245         sub.label(text=lines[0])
1246         sub.label(icon='ERROR')
1247         for l in lines[1:]:
1248             box.label(text=l)
1249
1250     def draw(self, context):
1251         import os
1252         import addon_utils
1253
1254         layout = self.layout
1255
1256         userpref = context.user_preferences
1257         used_ext = {ext.module for ext in userpref.addons}
1258
1259         addon_user_dirs = tuple(
1260             p for p in (
1261                 os.path.join(userpref.filepaths.script_directory, "addons"),
1262                 bpy.utils.user_resource('SCRIPTS', "addons"),
1263             )
1264             if p
1265         )
1266
1267         # Development option for 2.8x, don't show users bundled addons
1268         # unless they have been updated for 2.8x.
1269         # Developers can turn them on with '--debug'
1270         show_official_27x_addons = bpy.app.debug
1271
1272         # collect the categories that can be filtered on
1273         addons = [
1274             (mod, addon_utils.module_bl_info(mod))
1275             for mod in addon_utils.modules(refresh=False)
1276         ]
1277
1278         split = layout.split(factor=0.2)
1279         col = split.column()
1280         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
1281
1282         col.label(text="Supported Level")
1283         col.prop(context.window_manager, "addon_support", expand=True)
1284
1285         col.label(text="Categories")
1286         col.prop(context.window_manager, "addon_filter", expand=True)
1287
1288         col = split.column()
1289
1290         # set in addon_utils.modules_refresh()
1291         if addon_utils.error_duplicates:
1292             box = col.box()
1293             row = box.row()
1294             row.label(text="Multiple add-ons with the same name found!")
1295             row.label(icon='ERROR')
1296             box.label(text="Delete one of each pair to resolve:")
1297             for (addon_name, addon_file, addon_path) in addon_utils.error_duplicates:
1298                 box.separator()
1299                 sub_col = box.column(align=True)
1300                 sub_col.label(text=addon_name + ":")
1301                 sub_col.label(text="    " + addon_file)
1302                 sub_col.label(text="    " + addon_path)
1303
1304         if addon_utils.error_encoding:
1305             self.draw_error(
1306                 col,
1307                 "One or more addons do not have UTF-8 encoding\n"
1308                 "(see console for details)",
1309             )
1310
1311         filter = context.window_manager.addon_filter
1312         search = context.window_manager.addon_search.lower()
1313         support = context.window_manager.addon_support
1314
1315         # initialized on demand
1316         user_addon_paths = []
1317
1318         for mod, info in addons:
1319             module_name = mod.__name__
1320
1321             is_enabled = module_name in used_ext
1322
1323             if info["support"] not in support:
1324                 continue
1325
1326             # check if addon should be visible with current filters
1327             if (
1328                     (filter == "All") or
1329                     (filter == info["category"]) or
1330                     (filter == "Enabled" and is_enabled) or
1331                     (filter == "Disabled" and not is_enabled) or
1332                     (filter == "User" and (mod.__file__.startswith(addon_user_dirs)))
1333             ):
1334                 if search and search not in info["name"].lower():
1335                     if info["author"]:
1336                         if search not in info["author"].lower():
1337                             continue
1338                     else:
1339                         continue
1340
1341                 # Skip 2.7x add-ons included with Blender, unless in debug mode.
1342                 is_addon_27x = info.get("blender", (0,)) < (2, 80)
1343                 if (
1344                         is_addon_27x and
1345                         (not show_official_27x_addons) and
1346                         (not mod.__file__.startswith(addon_user_dirs))
1347                 ):
1348                     continue
1349
1350                 # Addon UI Code
1351                 col_box = col.column()
1352                 box = col_box.box()
1353                 colsub = box.column()
1354                 row = colsub.row(align=True)
1355
1356                 row.operator(
1357                     "wm.addon_expand",
1358                     icon='DISCLOSURE_TRI_DOWN' if info["show_expanded"] else 'DISCLOSURE_TRI_RIGHT',
1359                     emboss=False,
1360                 ).module = module_name
1361
1362                 row.operator(
1363                     "wm.addon_disable" if is_enabled else "wm.addon_enable",
1364                     icon='CHECKBOX_HLT' if is_enabled else 'CHECKBOX_DEHLT', text="",
1365                     emboss=False,
1366                 ).module = module_name
1367
1368                 sub = row.row()
1369                 sub.active = is_enabled
1370                 sub.label(text="%s: %s" % (info["category"], info["name"]))
1371
1372                 # WARNING: 2.8x exception, may be removed
1373                 # use disabled state for old add-ons, chances are they are broken.
1374                 if is_addon_27x:
1375                     sub.label(text="upgrade to 2.8x required")
1376                     sub.label(icon='ERROR')
1377                 # Remove code above after 2.8x migration is complete.
1378                 elif info["warning"]:
1379                     sub.label(icon='ERROR')
1380
1381                 # icon showing support level.
1382                 sub.label(icon=self._support_icon_mapping.get(info["support"], 'QUESTION'))
1383
1384                 # Expanded UI (only if additional info is available)
1385                 if info["show_expanded"]:
1386                     if info["description"]:
1387                         split = colsub.row().split(factor=0.15)
1388                         split.label(text="Description:")
1389                         split.label(text=info["description"])
1390                     if info["location"]:
1391                         split = colsub.row().split(factor=0.15)
1392                         split.label(text="Location:")
1393                         split.label(text=info["location"])
1394                     if mod:
1395                         split = colsub.row().split(factor=0.15)
1396                         split.label(text="File:")
1397                         split.label(text=mod.__file__, translate=False)
1398                     if info["author"]:
1399                         split = colsub.row().split(factor=0.15)
1400                         split.label(text="Author:")
1401                         split.label(text=info["author"], translate=False)
1402                     if info["version"]:
1403                         split = colsub.row().split(factor=0.15)
1404                         split.label(text="Version:")
1405                         split.label(text=".".join(str(x) for x in info["version"]), translate=False)
1406                     if info["warning"]:
1407                         split = colsub.row().split(factor=0.15)
1408                         split.label(text="Warning:")
1409                         split.label(text="  " + info["warning"], icon='ERROR')
1410
1411                     user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
1412                     tot_row = bool(info["wiki_url"]) + bool(user_addon)
1413
1414                     if tot_row:
1415                         split = colsub.row().split(factor=0.15)
1416                         split.label(text="Internet:")
1417                         if info["wiki_url"]:
1418                             split.operator(
1419                                 "wm.url_open", text="Documentation", icon='HELP',
1420                             ).url = info["wiki_url"]
1421                         # Only add "Report a Bug" button if tracker_url is set
1422                         # or the add-on is bundled (use official tracker then).
1423                         if info.get("tracker_url") or not user_addon:
1424                             split.operator(
1425                                 "wm.url_open", text="Report a Bug", icon='URL',
1426                             ).url = info.get(
1427                                 "tracker_url",
1428                                 "https://developer.blender.org/maniphest/task/edit/form/2",
1429                             )
1430                         if user_addon:
1431                             split.operator(
1432                                 "wm.addon_remove", text="Remove", icon='CANCEL',
1433                             ).module = mod.__name__
1434
1435                         for _ in range(4 - tot_row):
1436                             split.separator()
1437
1438                     # Show addon user preferences
1439                     if is_enabled:
1440                         addon_preferences = userpref.addons[module_name].preferences
1441                         if addon_preferences is not None:
1442                             draw = getattr(addon_preferences, "draw", None)
1443                             if draw is not None:
1444                                 addon_preferences_class = type(addon_preferences)
1445                                 box_prefs = col_box.box()
1446                                 box_prefs.label(text="Preferences:")
1447                                 addon_preferences_class.layout = box_prefs
1448                                 try:
1449                                     draw(context)
1450                                 except:
1451                                     import traceback
1452                                     traceback.print_exc()
1453                                     box_prefs.label(text="Error (see console)", icon='ERROR')
1454                                 del addon_preferences_class.layout
1455
1456         # Append missing scripts
1457         # First collect scripts that are used but have no script file.
1458         module_names = {mod.__name__ for mod, info in addons}
1459         missing_modules = {ext for ext in used_ext if ext not in module_names}
1460
1461         if missing_modules and filter in {"All", "Enabled"}:
1462             col.column().separator()
1463             col.column().label(text="Missing script files")
1464
1465             module_names = {mod.__name__ for mod, info in addons}
1466             for module_name in sorted(missing_modules):
1467                 is_enabled = module_name in used_ext
1468                 # Addon UI Code
1469                 box = col.column().box()
1470                 colsub = box.column()
1471                 row = colsub.row(align=True)
1472
1473                 row.label(text="", icon='ERROR')
1474
1475                 if is_enabled:
1476                     row.operator(
1477                         "wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False,
1478                     ).module = module_name
1479
1480                 row.label(text=module_name, translate=False)
1481
1482
1483 class StudioLightPanelMixin():
1484     bl_space_type = 'USER_PREFERENCES'
1485     bl_region_type = 'WINDOW'
1486
1487     @classmethod
1488     def poll(cls, context):
1489         userpref = context.user_preferences
1490         return (userpref.active_section == 'LIGHTS')
1491
1492     def _get_lights(self, userpref):
1493         return [light for light in userpref.studio_lights if light.is_user_defined and light.orientation == self.sl_orientation]
1494
1495     def draw(self, context):
1496         layout = self.layout
1497         userpref = context.user_preferences
1498         lights = self._get_lights(userpref)
1499         if lights:
1500             flow = layout.column_flow(columns=4)
1501             for studio_light in lights:
1502                 self.draw_studio_light(flow, studio_light)
1503         else:
1504             layout.label(text="No custom {} configured".format(self.bl_label))
1505
1506     def draw_studio_light(self, layout, studio_light):
1507         box = layout.box()
1508         row = box.row()
1509
1510         row.template_icon(layout.icon(studio_light), scale=6.0)
1511         op = row.operator('wm.studiolight_uninstall', text="", icon='REMOVE')
1512         op.index = studio_light.index
1513
1514         box.label(text=studio_light.name)
1515
1516
1517 class USERPREF_PT_studiolight_matcaps(Panel, StudioLightPanelMixin):
1518     bl_label = "MatCaps"
1519     sl_orientation = 'MATCAP'
1520
1521
1522 class USERPREF_PT_studiolight_world(Panel, StudioLightPanelMixin):
1523     bl_label = "World HDRI"
1524     sl_orientation = 'WORLD'
1525
1526
1527 class USERPREF_PT_studiolight_camera(Panel, StudioLightPanelMixin):
1528     bl_label = "Camera HDRI"
1529     sl_orientation = 'CAMERA'
1530
1531
1532 class USERPREF_PT_studiolight_specular(Panel, StudioLightPanelMixin):
1533     bl_label = "Specular Lights"
1534     sl_orientation = 'CAMERA'
1535
1536     @classmethod
1537     def poll(cls, context):
1538         userpref = context.user_preferences
1539         return (userpref.active_section == 'LIGHTS')
1540
1541     def opengl_light_buttons(self, column, light):
1542         split = column.split()
1543
1544         col = split.column()
1545         col.prop(light, "use", text="Use", icon='OUTLINER_OB_LIGHT' if light.use else 'LIGHT_DATA')
1546
1547         sub = col.column()
1548         sub.active = light.use
1549         sub.prop(light, "specular_color")
1550
1551         col = split.column()
1552         col.active = light.use
1553         col.prop(light, "direction", text="")
1554
1555     def draw(self, context):
1556         layout = self.layout
1557         column = layout.split()
1558
1559         userpref = context.user_preferences
1560         system = userpref.system
1561
1562         light = system.solid_lights[0]
1563         colsplit = column.split(factor=0.85)
1564         self.opengl_light_buttons(colsplit, light)
1565
1566         light = system.solid_lights[1]
1567         colsplit = column.split(factor=0.85)
1568         self.opengl_light_buttons(colsplit, light)
1569
1570         light = system.solid_lights[2]
1571         self.opengl_light_buttons(column, light)
1572
1573
1574 classes = (
1575     USERPREF_HT_header,
1576     USERPREF_PT_navigation,
1577     USERPREF_PT_interface,
1578     USERPREF_PT_edit,
1579     USERPREF_PT_system_general,
1580     USERPREF_MT_interface_theme_presets,
1581     USERPREF_PT_theme,
1582     USERPREF_PT_file,
1583     USERPREF_MT_ndof_settings,
1584     USERPREF_MT_keyconfigs,
1585     USERPREF_PT_input,
1586     USERPREF_MT_addons_online_resources,
1587     USERPREF_PT_addons,
1588     USERPREF_PT_studiolight_matcaps,
1589     USERPREF_PT_studiolight_world,
1590     USERPREF_PT_studiolight_camera,
1591     USERPREF_PT_studiolight_specular,
1592 )
1593
1594 if __name__ == "__main__":  # only for live edit.
1595     from bpy.utils import register_class
1596     for cls in classes:
1597         register_class(cls)