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