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