0bb25e984564378aeb15990d0f44b36a9c858ff3
[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 Header, Menu, Panel
22 import os
23
24
25 def ui_items_general(col, context):
26     """ General UI Theme Settings (User Interface)
27     """
28
29     row = col.row()
30
31     subsplit = row.split(percentage=0.95)
32
33     padding = subsplit.split(percentage=0.15)
34     colsub = padding.column()
35     colsub = padding.column()
36     colsub.row().prop(context, "outline")
37     colsub.row().prop(context, "item", slider=True)
38     colsub.row().prop(context, "inner", slider=True)
39     colsub.row().prop(context, "inner_sel", slider=True)
40
41     subsplit = row.split(percentage=0.85)
42
43     padding = subsplit.split(percentage=0.15)
44     colsub = padding.column()
45     colsub = padding.column()
46     colsub.row().prop(context, "text")
47     colsub.row().prop(context, "text_sel")
48     colsub.prop(context, "show_shaded")
49     subsub = colsub.column(align=True)
50     subsub.active = context.show_shaded
51     subsub.prop(context, "shadetop")
52     subsub.prop(context, "shadedown")
53
54     col.separator()
55
56
57 def opengl_lamp_buttons(column, lamp):
58     split = column.split(percentage=0.1)
59
60     split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
61
62     col = split.column()
63     col.active = lamp.use
64     row = col.row()
65     row.label(text="Diffuse:")
66     row.prop(lamp, "diffuse_color", text="")
67     row = col.row()
68     row.label(text="Specular:")
69     row.prop(lamp, "specular_color", text="")
70
71     col = split.column()
72     col.active = lamp.use
73     col.prop(lamp, "direction", text="")
74
75
76 class USERPREF_HT_header(Header):
77     bl_space_type = 'USER_PREFERENCES'
78
79     def draw(self, context):
80         layout = self.layout
81
82         layout.template_header(menus=False)
83
84         userpref = context.user_preferences
85
86         layout.operator_context = 'EXEC_AREA'
87         layout.operator("wm.save_homefile", text="Save As Default")
88
89         layout.operator_context = 'INVOKE_DEFAULT'
90
91         if userpref.active_section == 'INPUT':
92             layout.operator("wm.keyconfig_import")
93             layout.operator("wm.keyconfig_export")
94         elif userpref.active_section == 'ADDONS':
95             layout.operator("wm.addon_install", icon="FILESEL")
96             layout.menu("USERPREF_MT_addons_dev_guides")
97         elif userpref.active_section == 'THEMES':
98             layout.operator("ui.reset_default_theme")
99             layout.operator("wm.theme_install")
100
101
102 class USERPREF_PT_tabs(Panel):
103     bl_label = ""
104     bl_space_type = 'USER_PREFERENCES'
105     bl_region_type = 'WINDOW'
106     bl_options = {'HIDE_HEADER'}
107
108     def draw(self, context):
109         layout = self.layout
110
111         userpref = context.user_preferences
112
113         layout.prop(userpref, "active_section", expand=True)
114
115
116 class USERPREF_MT_interaction_presets(Menu):
117     bl_label = "Presets"
118     preset_subdir = "interaction"
119     preset_operator = "script.execute_preset"
120     draw = Menu.draw_preset
121
122
123 class USERPREF_MT_appconfigs(Menu):
124     bl_label = "AppPresets"
125     preset_subdir = "keyconfig"
126     preset_operator = "wm.appconfig_activate"
127
128     def draw(self, context):
129         self.layout.operator("wm.appconfig_default", text="Blender (default)")
130
131         # now draw the presets
132         Menu.draw_preset(self, context)
133
134
135 class USERPREF_MT_splash(Menu):
136     bl_label = "Splash"
137
138     def draw(self, context):
139         layout = self.layout
140
141         split = layout.split()
142         row = split.row()
143         row.label("")
144         row = split.row()
145         row.label("Interaction:")
146         # XXX, no redraws
147         # text = bpy.path.display_name(context.window_manager.keyconfigs.active.name)
148         # if not text:
149         #     text = "Blender (default)"
150         row.menu("USERPREF_MT_appconfigs", text="Preset")
151
152
153 class USERPREF_PT_interface(Panel):
154     bl_space_type = 'USER_PREFERENCES'
155     bl_label = "Interface"
156     bl_region_type = 'WINDOW'
157     bl_options = {'HIDE_HEADER'}
158
159     @classmethod
160     def poll(cls, context):
161         userpref = context.user_preferences
162         return (userpref.active_section == 'INTERFACE')
163
164     def draw(self, context):
165         layout = self.layout
166
167         userpref = context.user_preferences
168         view = userpref.view
169
170         row = layout.row()
171
172         col = row.column()
173         col.label(text="Display:")
174         col.prop(view, "show_tooltips")
175         col.prop(view, "show_tooltips_python")
176         col.prop(view, "show_object_info", text="Object Info")
177         col.prop(view, "show_large_cursors")
178         col.prop(view, "show_view_name", text="View Name")
179         col.prop(view, "show_playback_fps", text="Playback FPS")
180         col.prop(view, "use_global_scene")
181         col.prop(view, "object_origin_size")
182
183         col.separator()
184         col.separator()
185         col.separator()
186
187         col.prop(view, "show_mini_axis", text="Display Mini Axis")
188         sub = col.column()
189         sub.active = view.show_mini_axis
190         sub.prop(view, "mini_axis_size", text="Size")
191         sub.prop(view, "mini_axis_brightness", text="Brightness")
192
193         col.separator()
194         row.separator()
195         row.separator()
196
197         col = row.column()
198         col.label(text="View Manipulation:")
199         col.prop(view, "use_mouse_depth_cursor")
200         col.prop(view, "use_mouse_depth_navigate")
201         col.prop(view, "use_zoom_to_mouse")
202         col.prop(view, "use_rotate_around_active")
203         col.prop(view, "use_global_pivot")
204         col.prop(view, "use_camera_lock_parent")
205
206         col.separator()
207
208         col.prop(view, "use_auto_perspective")
209         col.prop(view, "smooth_view")
210         col.prop(view, "rotation_angle")
211
212         col.separator()
213         col.separator()
214
215         col.label(text="2D Viewports:")
216         col.prop(view, "view2d_grid_spacing_min", text="Minimum Grid Spacing")
217         col.prop(view, "timecode_style")
218
219         row.separator()
220         row.separator()
221
222         col = row.column()
223         #Toolbox doesn't exist yet
224         #col.label(text="Toolbox:")
225         #col.prop(view, "show_column_layout")
226         #col.label(text="Open Toolbox Delay:")
227         #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
228         #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
229         col.prop(view, "show_manipulator")
230         sub = col.column()
231         sub.active = view.show_manipulator
232         sub.prop(view, "manipulator_size", text="Size")
233         sub.prop(view, "manipulator_handle_size", text="Handle Size")
234         sub.prop(view, "manipulator_hotspot", text="Hotspot")
235
236         col.separator()
237         col.separator()
238         col.separator()
239
240         col.label(text="Menus:")
241         col.prop(view, "use_mouse_over_open")
242         col.label(text="Menu Open Delay:")
243         col.prop(view, "open_toplevel_delay", text="Top Level")
244         col.prop(view, "open_sublevel_delay", text="Sub Level")
245
246         col.separator()
247
248         col.prop(view, "show_splash")
249
250         if os.name == "nt":
251             col.prop(view, "use_quit_dialog")
252
253
254 class USERPREF_PT_edit(Panel):
255     bl_space_type = 'USER_PREFERENCES'
256     bl_label = "Edit"
257     bl_region_type = 'WINDOW'
258     bl_options = {'HIDE_HEADER'}
259
260     @classmethod
261     def poll(cls, context):
262         userpref = context.user_preferences
263         return (userpref.active_section == 'EDITING')
264
265     def draw(self, context):
266         layout = self.layout
267
268         userpref = context.user_preferences
269         edit = userpref.edit
270
271         row = layout.row()
272
273         col = row.column()
274         col.label(text="Link Materials To:")
275         col.prop(edit, "material_link", text="")
276
277         col.separator()
278         col.separator()
279         col.separator()
280
281         col.label(text="New Objects:")
282         col.prop(edit, "use_enter_edit_mode")
283         col.label(text="Align To:")
284         col.prop(edit, "object_align", text="")
285
286         col.separator()
287         col.separator()
288         col.separator()
289
290         col.label(text="Undo:")
291         col.prop(edit, "use_global_undo")
292         col.prop(edit, "undo_steps", text="Steps")
293         col.prop(edit, "undo_memory_limit", text="Memory Limit")
294
295         row.separator()
296         row.separator()
297
298         col = row.column()
299         col.label(text="Grease Pencil:")
300         col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
301         col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
302         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
303         col.prop(edit, "use_grease_pencil_smooth_stroke", text="Smooth Stroke")
304         col.prop(edit, "use_grease_pencil_simplify_stroke", text="Simplify Stroke")
305         col.separator()
306         col.separator()
307         col.separator()
308         col.label(text="Playback:")
309         col.prop(edit, "use_negative_frames")
310         col.separator()
311         col.separator()
312         col.separator()
313         col.label(text="Animation Editors:")
314         col.prop(edit, "fcurve_unselected_alpha", text="F-Curve Visibility")
315
316         row.separator()
317         row.separator()
318
319         col = row.column()
320         col.label(text="Keyframing:")
321         col.prop(edit, "use_visual_keying")
322         col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
323
324         col.separator()
325
326         col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
327         col.prop(edit, "use_auto_keying_warning")
328
329         sub = col.column()
330
331         #~ sub.active = edit.use_keyframe_insert_auto # incorrect, time-line can enable
332         sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
333
334         col.separator()
335
336         col.label(text="New F-Curve Defaults:")
337         col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
338         col.prop(edit, "keyframe_new_handle_type", text="Handles")
339         col.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
340
341         col.separator()
342         col.separator()
343         col.separator()
344
345         col.label(text="Transform:")
346         col.prop(edit, "use_drag_immediately")
347
348         row.separator()
349         row.separator()
350
351         col = row.column()
352         col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
353
354         col.separator()
355         col.separator()
356         col.separator()
357
358         col.label(text="Duplicate Data:")
359         col.prop(edit, "use_duplicate_mesh", text="Mesh")
360         col.prop(edit, "use_duplicate_surface", text="Surface")
361         col.prop(edit, "use_duplicate_curve", text="Curve")
362         col.prop(edit, "use_duplicate_text", text="Text")
363         col.prop(edit, "use_duplicate_metaball", text="Metaball")
364         col.prop(edit, "use_duplicate_armature", text="Armature")
365         col.prop(edit, "use_duplicate_lamp", text="Lamp")
366         col.prop(edit, "use_duplicate_material", text="Material")
367         col.prop(edit, "use_duplicate_texture", text="Texture")
368         #col.prop(edit, "use_duplicate_fcurve", text="F-Curve")
369         col.prop(edit, "use_duplicate_action", text="Action")
370         col.prop(edit, "use_duplicate_particle", text="Particle")
371
372
373 class USERPREF_PT_system(Panel):
374     bl_space_type = 'USER_PREFERENCES'
375     bl_label = "System"
376     bl_region_type = 'WINDOW'
377     bl_options = {'HIDE_HEADER'}
378
379     @classmethod
380     def poll(cls, context):
381         userpref = context.user_preferences
382         return (userpref.active_section == 'SYSTEM')
383
384     def draw(self, context):
385         layout = self.layout
386
387         userpref = context.user_preferences
388         system = userpref.system
389
390         split = layout.split()
391
392         # 1. Column
393         column = split.column()
394         colsplit = column.split(percentage=0.85)
395
396         col = colsplit.column()
397         col.label(text="General:")
398         col.prop(system, "dpi")
399         col.prop(system, "frame_server_port")
400         col.prop(system, "scrollback", text="Console Scrollback")
401
402         col.separator()
403         col.separator()
404
405         col.label(text="Sound:")
406         col.row().prop(system, "audio_device", expand=True)
407         sub = col.column()
408         sub.active = system.audio_device != 'NONE'
409         #sub.prop(system, "use_preview_images")
410         sub.prop(system, "audio_channels", text="Channels")
411         sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
412         sub.prop(system, "audio_sample_rate", text="Sample Rate")
413         sub.prop(system, "audio_sample_format", text="Sample Format")
414
415         col.separator()
416         col.separator()
417
418         col.label(text="Screencast:")
419         col.prop(system, "screencast_fps")
420         col.prop(system, "screencast_wait_time")
421
422         col.separator()
423         col.separator()
424
425         if hasattr(system, "compute_device_type"):
426             col.label(text="Compute Device:")
427             col.row().prop(system, "compute_device_type", expand=True)
428             sub = col.row()
429             sub.active = system.compute_device_type != 'CPU'
430             sub.prop(system, "compute_device", text="")
431
432         # 2. Column
433         column = split.column()
434         colsplit = column.split(percentage=0.85)
435
436         col = colsplit.column()
437         col.label(text="OpenGL:")
438         col.prop(system, "gl_clip_alpha", slider=True)
439         col.prop(system, "use_mipmaps")
440         col.prop(system, "use_gpu_mipmap")
441         col.prop(system, "use_16bit_textures")
442         col.label(text="Anisotropic Filtering")
443         col.prop(system, "anisotropic_filter", text="")
444         col.prop(system, "use_vertex_buffer_objects")
445         col.label(text="Window Draw Method:")
446         col.prop(system, "window_draw_method", text="")
447         col.prop(system, "multi_sample", text="")
448         col.label(text="Text Draw Options:")
449         col.prop(system, "use_text_antialiasing")
450         col.label(text="Textures:")
451         col.prop(system, "gl_texture_limit", text="Limit Size")
452         col.prop(system, "texture_time_out", text="Time Out")
453         col.prop(system, "texture_collection_rate", text="Collection Rate")
454
455         col.separator()
456         col.separator()
457         col.separator()
458
459         col.label(text="Sequencer / Clip Editor:")
460         col.prop(system, "prefetch_frames")
461         col.prop(system, "memory_cache_limit")
462
463         # 3. Column
464         column = split.column()
465
466         column.label(text="Solid OpenGL lights:")
467
468         split = column.split(percentage=0.1)
469         split.label()
470         split.label(text="Colors:")
471         split.label(text="Direction:")
472
473         lamp = system.solid_lights[0]
474         opengl_lamp_buttons(column, lamp)
475
476         lamp = system.solid_lights[1]
477         opengl_lamp_buttons(column, lamp)
478
479         lamp = system.solid_lights[2]
480         opengl_lamp_buttons(column, lamp)
481
482         column.separator()
483
484         column.label(text="Color Picker Type:")
485         column.row().prop(system, "color_picker_type", text="")
486
487         column.separator()
488
489         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
490         sub = column.column()
491         sub.active = system.use_weight_color_range
492         sub.template_color_ramp(system, "weight_color_range", expand=True)
493
494         column.separator()
495
496         column.prop(system, "use_international_fonts")
497         if system.use_international_fonts:
498             column.prop(system, "language")
499             row = column.row()
500             row.label(text="Translate:")
501             row.prop(system, "use_translate_interface", text="Interface")
502             row.prop(system, "use_translate_tooltips", text="Tooltips")
503
504
505 class USERPREF_MT_interface_theme_presets(Menu):
506     bl_label = "Presets"
507     preset_subdir = "interface_theme"
508     preset_operator = "script.execute_preset"
509     preset_type = 'XML'
510     preset_xml_map = (("user_preferences.themes[0]", "Theme"), )
511     draw = Menu.draw_preset
512
513
514 class USERPREF_PT_theme(Panel):
515     bl_space_type = 'USER_PREFERENCES'
516     bl_label = "Themes"
517     bl_region_type = 'WINDOW'
518     bl_options = {'HIDE_HEADER'}
519
520     @staticmethod
521     def _theme_generic(split, themedata):
522
523         col = split.column()
524
525         def theme_generic_recurse(data):
526             col.label(data.rna_type.name)
527             row = col.row()
528             subsplit = row.split(percentage=0.95)
529
530             padding1 = subsplit.split(percentage=0.15)
531             padding1.column()
532
533             subsplit = row.split(percentage=0.85)
534
535             padding2 = subsplit.split(percentage=0.15)
536             padding2.column()
537
538             colsub_pair = padding1.column(), padding2.column()
539
540             props_type = {}
541
542             for i, prop in enumerate(data.rna_type.properties):
543                 if prop.identifier == "rna_type":
544                     continue
545
546                 props_type.setdefault((prop.type, prop.subtype), []).append(prop)
547
548             for props_type, props_ls in sorted(props_type.items()):
549                 if props_type[0] == 'POINTER':
550                     for i, prop in enumerate(props_ls):
551                         theme_generic_recurse(getattr(data, prop.identifier))
552                 else:
553                     for i, prop in enumerate(props_ls):
554                         colsub_pair[i % 2].row().prop(data, prop.identifier)
555
556         theme_generic_recurse(themedata)
557
558     @classmethod
559     def poll(cls, context):
560         userpref = context.user_preferences
561         return (userpref.active_section == 'THEMES')
562
563     def draw(self, context):
564         layout = self.layout
565
566         theme = context.user_preferences.themes[0]
567
568         split_themes = layout.split(percentage=0.2)
569
570         sub = split_themes.column()
571
572         sub.label(text="Presets:")
573         subrow = sub.row(align=True)
574
575         subrow.menu("USERPREF_MT_interface_theme_presets", text=USERPREF_MT_interface_theme_presets.bl_label)
576         subrow.operator("wm.interface_theme_preset_add", text="", icon='ZOOMIN')
577         subrow.operator("wm.interface_theme_preset_add", text="", icon='ZOOMOUT').remove_active = True
578         sub.separator()
579
580         sub.prop(theme, "theme_area", expand=True)
581
582         split = layout.split(percentage=0.4)
583
584         layout.separator()
585         layout.separator()
586
587         split = split_themes.split()
588
589         if theme.theme_area == 'USER_INTERFACE':
590             col = split.column()
591
592             ui = theme.user_interface.wcol_regular
593             col.label(text="Regular:")
594             ui_items_general(col, ui)
595
596             ui = theme.user_interface.wcol_tool
597             col.label(text="Tool:")
598             ui_items_general(col, ui)
599
600             ui = theme.user_interface.wcol_radio
601             col.label(text="Radio Buttons:")
602             ui_items_general(col, ui)
603
604             ui = theme.user_interface.wcol_text
605             col.label(text="Text:")
606             ui_items_general(col, ui)
607
608             ui = theme.user_interface.wcol_option
609             col.label(text="Option:")
610             ui_items_general(col, ui)
611
612             ui = theme.user_interface.wcol_toggle
613             col.label(text="Toggle:")
614             ui_items_general(col, ui)
615
616             ui = theme.user_interface.wcol_num
617             col.label(text="Number Field:")
618             ui_items_general(col, ui)
619
620             ui = theme.user_interface.wcol_numslider
621             col.label(text="Value Slider:")
622             ui_items_general(col, ui)
623
624             ui = theme.user_interface.wcol_box
625             col.label(text="Box:")
626             ui_items_general(col, ui)
627
628             ui = theme.user_interface.wcol_menu
629             col.label(text="Menu:")
630             ui_items_general(col, ui)
631
632             ui = theme.user_interface.wcol_pulldown
633             col.label(text="Pulldown:")
634             ui_items_general(col, ui)
635
636             ui = theme.user_interface.wcol_menu_back
637             col.label(text="Menu Back:")
638             ui_items_general(col, ui)
639
640             ui = theme.user_interface.wcol_tooltip
641             col.label(text="Tooltip:")
642             ui_items_general(col, ui)
643
644             ui = theme.user_interface.wcol_menu_item
645             col.label(text="Menu Item:")
646             ui_items_general(col, ui)
647
648             ui = theme.user_interface.wcol_scroll
649             col.label(text="Scroll Bar:")
650             ui_items_general(col, ui)
651
652             ui = theme.user_interface.wcol_progress
653             col.label(text="Progress Bar:")
654             ui_items_general(col, ui)
655
656             ui = theme.user_interface.wcol_list_item
657             col.label(text="List Item:")
658             ui_items_general(col, ui)
659
660             ui = theme.user_interface.wcol_state
661             col.label(text="State:")
662
663             row = col.row()
664
665             subsplit = row.split(percentage=0.95)
666
667             padding = subsplit.split(percentage=0.15)
668             colsub = padding.column()
669             colsub = padding.column()
670             colsub.row().prop(ui, "inner_anim")
671             colsub.row().prop(ui, "inner_anim_sel")
672             colsub.row().prop(ui, "inner_driven")
673             colsub.row().prop(ui, "inner_driven_sel")
674
675             subsplit = row.split(percentage=0.85)
676
677             padding = subsplit.split(percentage=0.15)
678             colsub = padding.column()
679             colsub = padding.column()
680             colsub.row().prop(ui, "inner_key")
681             colsub.row().prop(ui, "inner_key_sel")
682             colsub.row().prop(ui, "blend")
683
684             col.separator()
685             col.separator()
686
687             ui = theme.user_interface
688             col.label("Icons:")
689
690             row = col.row()
691
692             subsplit = row.split(percentage=0.95)
693
694             padding = subsplit.split(percentage=0.15)
695             colsub = padding.column()
696             colsub = padding.column()
697             colsub.row().prop(ui, "icon_file")
698
699             subsplit = row.split(percentage=0.85)
700
701             padding = subsplit.split(percentage=0.15)
702             colsub = padding.column()
703             colsub = padding.column()
704             colsub.row().prop(ui, "icon_alpha")
705
706             col.separator()
707             col.separator()
708
709             ui = theme.user_interface.panel
710             col.label("Panels:")
711
712             row = col.row()
713
714             subsplit = row.split(percentage=0.95)
715
716             padding = subsplit.split(percentage=0.15)
717             colsub = padding.column()
718             colsub = padding.column()
719             rowsub = colsub.row()
720             rowsub.prop(ui, "show_header")
721             rowsub.label()
722
723             subsplit = row.split(percentage=0.85)
724
725             padding = subsplit.split(percentage=0.15)
726             colsub = padding.column()
727             colsub = padding.column()
728             colsub.row().prop(ui, "header")
729
730             col.separator()
731             col.separator()
732
733             ui = theme.user_interface
734             col.label("Axis Colors:")
735
736             row = col.row()
737
738             subsplit = row.split(percentage=0.95)
739
740             padding = subsplit.split(percentage=0.15)
741             colsub = padding.column()
742             colsub = padding.column()
743             colsub.row().prop(ui, "axis_x")
744             colsub.row().prop(ui, "axis_y")
745             colsub.row().prop(ui, "axis_z")
746             
747             subsplit = row.split(percentage=0.85)
748
749             padding = subsplit.split(percentage=0.15)
750             colsub = padding.column()
751             colsub = padding.column()
752             
753             layout.separator()
754             layout.separator()
755         elif theme.theme_area == 'BONE_COLOR_SETS':
756             col = split.column()
757
758             for i, ui in enumerate(theme.bone_color_sets):
759                 col.label(text="Color Set" + " %d:" % (i + 1))  # i starts from 0
760
761                 row = col.row()
762
763                 subsplit = row.split(percentage=0.95)
764
765                 padding = subsplit.split(percentage=0.15)
766                 colsub = padding.column()
767                 colsub = padding.column()
768                 colsub.row().prop(ui, "normal")
769                 colsub.row().prop(ui, "select")
770                 colsub.row().prop(ui, "active")
771
772                 subsplit = row.split(percentage=0.85)
773
774                 padding = subsplit.split(percentage=0.15)
775                 colsub = padding.column()
776                 colsub = padding.column()
777                 colsub.row().prop(ui, "show_colored_constraints")
778         else:
779             self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
780
781
782 class USERPREF_PT_file(Panel):
783     bl_space_type = 'USER_PREFERENCES'
784     bl_label = "Files"
785     bl_region_type = 'WINDOW'
786     bl_options = {'HIDE_HEADER'}
787
788     @classmethod
789     def poll(cls, context):
790         userpref = context.user_preferences
791         return (userpref.active_section == 'FILES')
792
793     def draw(self, context):
794         layout = self.layout
795
796         userpref = context.user_preferences
797         paths = userpref.filepaths
798         system = userpref.system
799
800         split = layout.split(percentage=0.7)
801
802         col = split.column()
803         col.label(text="File Paths:")
804
805         colsplit = col.split(percentage=0.95)
806         col1 = colsplit.split(percentage=0.3)
807
808         sub = col1.column()
809         sub.label(text="Fonts:")
810         sub.label(text="Textures:")
811         sub.label(text="Render Output:")
812         sub.label(text="Scripts:")
813         sub.label(text="Sounds:")
814         sub.label(text="Temp:")
815         sub.label(text="I18n Branches:")
816         sub.label(text="Image Editor:")
817         sub.label(text="Animation Player:")
818
819         sub = col1.column()
820         sub.prop(paths, "font_directory", text="")
821         sub.prop(paths, "texture_directory", text="")
822         sub.prop(paths, "render_output_directory", text="")
823         sub.prop(paths, "script_directory", text="")
824         sub.prop(paths, "sound_directory", text="")
825         sub.prop(paths, "temporary_directory", text="")
826         sub.prop(paths, "i18n_branches_directory", text="")
827         sub.prop(paths, "image_editor", text="")
828         subsplit = sub.split(percentage=0.3)
829         subsplit.prop(paths, "animation_player_preset", text="")
830         subsplit.prop(paths, "animation_player", text="")
831
832         col.separator()
833         col.separator()
834
835         colsplit = col.split(percentage=0.95)
836         sub = colsplit.column()
837         sub.label(text="Author:")
838         sub.prop(system, "author", text="")
839
840         col = split.column()
841         col.label(text="Save & Load:")
842         col.prop(paths, "use_relative_paths")
843         col.prop(paths, "use_file_compression")
844         col.prop(paths, "use_load_ui")
845         col.prop(paths, "use_filter_files")
846         col.prop(paths, "show_hidden_files_datablocks")
847         col.prop(paths, "hide_recent_locations")
848         col.prop(paths, "hide_system_bookmarks")
849         col.prop(paths, "show_thumbnails")
850
851         col.separator()
852         col.separator()
853
854         col.prop(paths, "save_version")
855         col.prop(paths, "recent_files")
856         col.prop(paths, "use_save_preview_images")
857         col.label(text="Auto Save:")
858         col.prop(paths, "use_auto_save_temporary_files")
859         sub = col.column()
860         sub.active = paths.use_auto_save_temporary_files
861         sub.prop(paths, "auto_save_time", text="Timer (mins)")
862
863         col.separator()
864
865         col.label(text="Scripts:")
866         col.prop(system, "use_scripts_auto_execute")
867         col.prop(system, "use_tabs_as_spaces")
868
869
870 from bl_ui.space_userpref_keymap import InputKeyMapPanel
871
872
873 class USERPREF_MT_ndof_settings(Menu):
874     # accessed from the window key-bindings in C (only)
875     bl_label = "3D Mouse Settings"
876
877     def draw(self, context):
878         layout = self.layout
879
880         input_prefs = context.user_preferences.inputs
881
882         layout.separator()
883         layout.prop(input_prefs, "ndof_sensitivity")
884         layout.prop(input_prefs, "ndof_orbit_sensitivity")
885
886         if context.space_data.type == 'VIEW_3D':
887             layout.separator()
888             layout.prop(input_prefs, "ndof_show_guide")
889
890             layout.separator()
891             layout.label(text="Orbit options")
892             layout.row().prop(input_prefs, "ndof_view_rotate_method", text="")
893             layout.prop(input_prefs, "ndof_roll_invert_axis")
894             layout.prop(input_prefs, "ndof_tilt_invert_axis")
895             layout.prop(input_prefs, "ndof_rotate_invert_axis")
896
897             layout.separator()
898             layout.label(text="Pan options")
899             layout.prop(input_prefs, "ndof_panx_invert_axis")
900             layout.prop(input_prefs, "ndof_pany_invert_axis")
901             layout.prop(input_prefs, "ndof_panz_invert_axis")
902
903             layout.label(text="Zoom options")
904             layout.prop(input_prefs, "ndof_zoom_invert")
905             layout.prop(input_prefs, "ndof_zoom_updown")
906
907             layout.separator()
908             layout.label(text="Fly options")
909             layout.prop(input_prefs, "ndof_fly_helicopter", icon='NDOF_FLY')
910             layout.prop(input_prefs, "ndof_lock_horizon", icon='NDOF_DOM')
911
912
913 class USERPREF_PT_input(Panel, InputKeyMapPanel):
914     bl_space_type = 'USER_PREFERENCES'
915     bl_label = "Input"
916
917     @classmethod
918     def poll(cls, context):
919         userpref = context.user_preferences
920         return (userpref.active_section == 'INPUT')
921
922     def draw_input_prefs(self, inputs, layout):
923         # General settings
924         row = layout.row()
925         col = row.column()
926
927         sub = col.column()
928         sub.label(text="Presets:")
929         subrow = sub.row(align=True)
930
931         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
932         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
933         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
934         sub.separator()
935
936         sub.label(text="Mouse:")
937         sub1 = sub.column()
938         sub1.active = (inputs.select_mouse == 'RIGHT')
939         sub1.prop(inputs, "use_mouse_emulate_3_button")
940         sub.prop(inputs, "use_mouse_continuous")
941         sub.prop(inputs, "drag_threshold")
942         sub.prop(inputs, "tweak_threshold")
943
944         sub.label(text="Select With:")
945         sub.row().prop(inputs, "select_mouse", expand=True)
946
947         sub = col.column()
948         sub.label(text="Double Click:")
949         sub.prop(inputs, "mouse_double_click_time", text="Speed")
950
951         sub.separator()
952
953         sub.prop(inputs, "use_emulate_numpad")
954
955         sub.separator()
956
957         sub.label(text="Orbit Style:")
958         sub.row().prop(inputs, "view_rotate_method", expand=True)
959
960         sub.label(text="Zoom Style:")
961         sub.row().prop(inputs, "view_zoom_method", text="")
962         if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
963             sub.row().prop(inputs, "view_zoom_axis", expand=True)
964             sub.prop(inputs, "invert_mouse_zoom")
965
966         #sub.prop(inputs, "use_mouse_mmb_paste")
967
968         #col.separator()
969
970         sub = col.column()
971         sub.label(text="Mouse Wheel:")
972         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
973         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
974
975         col.separator()
976         sub = col.column()
977         sub.label(text="NDOF Device:")
978         sub.prop(inputs, "ndof_sensitivity", text="NDOF Sensitivity")
979         sub.prop(inputs, "ndof_orbit_sensitivity", text="NDOF Orbit Sensitivity")
980         sub.row().prop(inputs, "ndof_view_rotate_method", expand=True)
981
982         row.separator()
983
984     def draw(self, context):
985         layout = self.layout
986
987         #import time
988
989         #start = time.time()
990
991         userpref = context.user_preferences
992
993         inputs = userpref.inputs
994
995         split = layout.split(percentage=0.25)
996
997         # Input settings
998         self.draw_input_prefs(inputs, split)
999
1000         # Keymap Settings
1001         self.draw_keymaps(context, split)
1002
1003         #print("runtime", time.time() - start)
1004
1005
1006 class USERPREF_MT_addons_dev_guides(Menu):
1007     bl_label = "Development Guides"
1008
1009     # menu to open web-pages with addons development guides
1010     def draw(self, context):
1011         layout = self.layout
1012
1013         layout.operator("wm.url_open", text="API Concepts", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro"
1014         layout.operator("wm.url_open", text="Addon Guidelines", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons"
1015         layout.operator("wm.url_open", text="How to share your addon", icon='URL').url = "http://wiki.blender.org/index.php/Dev:Py/Sharing"
1016
1017
1018 class USERPREF_PT_addons(Panel):
1019     bl_space_type = 'USER_PREFERENCES'
1020     bl_label = "Addons"
1021     bl_region_type = 'WINDOW'
1022     bl_options = {'HIDE_HEADER'}
1023
1024     _support_icon_mapping = {
1025         'OFFICIAL': 'FILE_BLEND',
1026         'COMMUNITY': 'POSE_DATA',
1027         'TESTING': 'MOD_EXPLODE',
1028         }
1029
1030     @classmethod
1031     def poll(cls, context):
1032         userpref = context.user_preferences
1033         return (userpref.active_section == 'ADDONS')
1034
1035     @staticmethod
1036     def is_user_addon(mod, user_addon_paths):
1037         if not user_addon_paths:
1038             for path in (bpy.utils.script_path_user(),
1039                          bpy.utils.script_path_pref()):
1040                 if path is not None:
1041                     user_addon_paths.append(os.path.join(path, "addons"))
1042
1043         for path in user_addon_paths:
1044             if bpy.path.is_subdir(mod.__file__, path):
1045                 return True
1046         return False
1047
1048     @staticmethod
1049     def draw_error(layout, message):
1050         lines = message.split("\n")
1051         box = layout.box()
1052         rowsub = box.row()
1053         rowsub.label(lines[0])
1054         rowsub.label(icon='ERROR')
1055         for l in lines[1:]:
1056             box.label(l)
1057
1058     def draw(self, context):
1059         import addon_utils
1060
1061         layout = self.layout
1062
1063         userpref = context.user_preferences
1064         used_ext = {ext.module for ext in userpref.addons}
1065
1066         userpref_addons_folder = os.path.join(userpref.filepaths.script_directory, "addons")
1067         scripts_addons_folder  = bpy.utils.user_resource('SCRIPTS', "addons")
1068         
1069         # collect the categories that can be filtered on
1070         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(addon_utils.addons_fake_modules)]
1071
1072         split = layout.split(percentage=0.2)
1073         col = split.column()
1074         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
1075
1076         col.label(text="Supported Level")
1077         col.prop(context.window_manager, "addon_support", expand=True)
1078
1079         col.label(text="Categories")
1080         col.prop(context.window_manager, "addon_filter", expand=True)
1081
1082         col = split.column()
1083
1084         # set in addon_utils.modules(...)
1085         if addon_utils.error_duplicates:
1086             self.draw_error(col,
1087                             "Multiple addons using the same name found!\n"
1088                             "likely a problem with the script search path.\n"
1089                             "(see console for details)",
1090                             )
1091
1092         if addon_utils.error_encoding:
1093             self.draw_error(col,
1094                             "One or more addons do not have UTF-8 encoding\n"
1095                             "(see console for details)",
1096                             )
1097
1098         filter = context.window_manager.addon_filter
1099         search = context.window_manager.addon_search.lower()
1100         support = context.window_manager.addon_support
1101
1102         # initialized on demand
1103         user_addon_paths = []
1104
1105         for mod, info in addons:
1106             module_name = mod.__name__
1107
1108             is_enabled = module_name in used_ext
1109
1110             if info["support"] not in support:
1111                 continue
1112
1113             # check if addon should be visible with current filters
1114             if     ((filter == "All") or
1115                     (filter == info["category"]) or
1116                     (filter == "Enabled" and is_enabled) or
1117                     (filter == "Disabled" and not is_enabled) or
1118                     (filter == "User" and (mod.__file__.startswith((scripts_addons_folder, userpref_addons_folder))))
1119                    ):
1120
1121                 if search and search not in info["name"].lower():
1122                     if info["author"]:
1123                         if search not in info["author"].lower():
1124                             continue
1125                     else:
1126                         continue
1127
1128                 # Addon UI Code
1129                 box = col.column().box()
1130                 colsub = box.column()
1131                 row = colsub.row()
1132
1133                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
1134
1135                 rowsub = row.row()
1136                 rowsub.active = is_enabled
1137                 rowsub.label(text='%s: %s' % (info["category"], info["name"]))
1138                 if info["warning"]:
1139                     rowsub.label(icon='ERROR')
1140
1141                 # icon showing support level.
1142                 rowsub.label(icon=self._support_icon_mapping.get(info["support"], 'QUESTION'))
1143
1144                 if is_enabled:
1145                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1146                 else:
1147                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
1148
1149                 # Expanded UI (only if additional info is available)
1150                 if info["show_expanded"]:
1151                     if info["description"]:
1152                         split = colsub.row().split(percentage=0.15)
1153                         split.label(text="Description:")
1154                         split.label(text=info["description"])
1155                     if info["location"]:
1156                         split = colsub.row().split(percentage=0.15)
1157                         split.label(text="Location:")
1158                         split.label(text=info["location"])
1159                     if mod:
1160                         split = colsub.row().split(percentage=0.15)
1161                         split.label(text="File:")
1162                         split.label(text=mod.__file__)
1163                     if info["author"]:
1164                         split = colsub.row().split(percentage=0.15)
1165                         split.label(text="Author:")
1166                         split.label(text=info["author"])
1167                     if info["version"]:
1168                         split = colsub.row().split(percentage=0.15)
1169                         split.label(text="Version:")
1170                         split.label(text='.'.join(str(x) for x in info["version"]))
1171                     if info["warning"]:
1172                         split = colsub.row().split(percentage=0.15)
1173                         split.label(text="Warning:")
1174                         split.label(text='  ' + info["warning"], icon='ERROR')
1175
1176                     user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
1177                     tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)
1178
1179                     if tot_row:
1180                         split = colsub.row().split(percentage=0.15)
1181                         split.label(text="Internet:")
1182                         if info["wiki_url"]:
1183                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
1184                         if info["tracker_url"]:
1185                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
1186                         if user_addon:
1187                             split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__
1188
1189                         for i in range(4 - tot_row):
1190                             split.separator()
1191
1192         # Append missing scripts
1193         # First collect scripts that are used but have no script file.
1194         module_names = {mod.__name__ for mod, info in addons}
1195         missing_modules = {ext for ext in used_ext if ext not in module_names}
1196
1197         if missing_modules and filter in {"All", "Enabled"}:
1198             col.column().separator()
1199             col.column().label(text="Missing script files")
1200
1201             module_names = {mod.__name__ for mod, info in addons}
1202             for module_name in sorted(missing_modules):
1203                 is_enabled = module_name in used_ext
1204                 # Addon UI Code
1205                 box = col.column().box()
1206                 colsub = box.column()
1207                 row = colsub.row()
1208
1209                 row.label(text=module_name, icon='ERROR')
1210
1211                 if is_enabled:
1212                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1213
1214 if __name__ == "__main__":  # only for live edit.
1215     bpy.utils.register_module(__name__)