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