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