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