svn merge -r40000:40179 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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, Operator, Panel
22 import os
23 import addon_utils
24
25 from bpy.props import StringProperty, BoolProperty, EnumProperty
26
27
28 def ui_items_general(col, context):
29     """ General UI Theme Settings (User Interface)
30     """
31
32     row = col.row()
33
34     subsplit = row.split(percentage=0.95)
35
36     padding = subsplit.split(percentage=0.15)
37     colsub = padding.column()
38     colsub = padding.column()
39     colsub.row().prop(context, "outline")
40     colsub.row().prop(context, "item", slider=True)
41     colsub.row().prop(context, "inner", slider=True)
42     colsub.row().prop(context, "inner_sel", slider=True)
43
44     subsplit = row.split(percentage=0.85)
45
46     padding = subsplit.split(percentage=0.15)
47     colsub = padding.column()
48     colsub = padding.column()
49     colsub.row().prop(context, "text")
50     colsub.row().prop(context, "text_sel")
51     colsub.prop(context, "show_shaded")
52     subsub = colsub.column(align=True)
53     subsub.active = context.show_shaded
54     subsub.prop(context, "shadetop")
55     subsub.prop(context, "shadedown")
56
57     col.separator()
58
59
60 def opengl_lamp_buttons(column, lamp):
61     split = column.split(percentage=0.1)
62
63     split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
64
65     col = split.column()
66     col.active = lamp.use
67     row = col.row()
68     row.label(text="Diffuse:")
69     row.prop(lamp, "diffuse_color", text="")
70     row = col.row()
71     row.label(text="Specular:")
72     row.prop(lamp, "specular_color", text="")
73
74     col = split.column()
75     col.active = lamp.use
76     col.prop(lamp, "direction", text="")
77
78
79 class USERPREF_HT_header(Header):
80     bl_space_type = 'USER_PREFERENCES'
81
82     def draw(self, context):
83         layout = self.layout
84         layout.template_header(menus=False)
85
86         userpref = context.user_preferences
87
88         layout.operator_context = 'EXEC_AREA'
89         layout.operator("wm.save_homefile", text="Save As Default")
90
91         layout.operator_context = 'INVOKE_DEFAULT'
92
93         if userpref.active_section == 'INPUT':
94             layout.operator("wm.keyconfig_export")
95             layout.operator("wm.keyconfig_import")
96         elif userpref.active_section == 'ADDONS':
97             layout.operator("wm.addon_install")
98             layout.menu("USERPREF_MT_addons_dev_guides")
99         elif userpref.active_section == 'THEMES':
100             layout.operator("ui.reset_default_theme")
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         #column = split.column()
421         #colsplit = column.split(percentage=0.85)
422
423         # No translation in 2.5 yet
424         #col.prop(system, "language")
425         #col.label(text="Translate:")
426         #col.prop(system, "use_translate_tooltips", text="Tooltips")
427         #col.prop(system, "use_translate_buttons", text="Labels")
428         #col.prop(system, "use_translate_toolbox", text="Toolbox")
429
430         #col.separator()
431
432         #col.prop(system, "use_textured_fonts")
433
434         # 2. Column
435         column = split.column()
436         colsplit = column.split(percentage=0.85)
437
438         col = colsplit.column()
439         col.label(text="OpenGL:")
440         col.prop(system, "gl_clip_alpha", slider=True)
441         col.prop(system, "use_mipmaps")
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 broder/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:")
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         column.separator()
485         column.separator()
486
487         column.label(text="Color Picker Type:")
488         column.row().prop(system, "color_picker_type", text="")
489
490         column.separator()
491         column.separator()
492         column.separator()
493
494         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
495         sub = column.column()
496         sub.active = system.use_weight_color_range
497         sub.template_color_ramp(system, "weight_color_range", expand=True)
498
499
500 class USERPREF_PT_theme(Panel):
501     bl_space_type = 'USER_PREFERENCES'
502     bl_label = "Themes"
503     bl_region_type = 'WINDOW'
504     bl_options = {'HIDE_HEADER'}
505
506     @staticmethod
507     def _theme_generic(split, themedata):
508
509         row = split.row()
510
511         subsplit = row.split(percentage=0.95)
512
513         padding1 = subsplit.split(percentage=0.15)
514         padding1.column()
515
516         subsplit = row.split(percentage=0.85)
517
518         padding2 = subsplit.split(percentage=0.15)
519         padding2.column()
520
521         colsub_pair = padding1.column(), padding2.column()
522
523         props_type = {}
524
525         for i, prop in enumerate(themedata.rna_type.properties):
526             attr = prop.identifier
527             if attr == "rna_type":
528                 continue
529
530             props_type.setdefault((prop.type, prop.subtype), []).append(prop.identifier)
531
532         for props_type, props_ls in sorted(props_type.items()):
533             for i, attr in enumerate(props_ls):
534                 colsub_pair[i % 2].row().prop(themedata, attr)
535
536     @classmethod
537     def poll(cls, context):
538         userpref = context.user_preferences
539         return (userpref.active_section == 'THEMES')
540
541     def draw(self, context):
542         layout = self.layout
543
544         theme = context.user_preferences.themes[0]
545
546         split_themes = layout.split(percentage=0.2)
547         split_themes.prop(theme, "theme_area", expand=True)
548
549         split = layout.split(percentage=0.4)
550
551         layout.separator()
552         layout.separator()
553
554         split = split_themes.split()
555
556         if theme.theme_area == 'USER_INTERFACE':
557             col = split.column()
558
559             ui = theme.user_interface.wcol_regular
560             col.label(text="Regular:")
561             ui_items_general(col, ui)
562
563             ui = theme.user_interface.wcol_tool
564             col.label(text="Tool:")
565             ui_items_general(col, ui)
566
567             ui = theme.user_interface.wcol_radio
568             col.label(text="Radio Buttons:")
569             ui_items_general(col, ui)
570
571             ui = theme.user_interface.wcol_text
572             col.label(text="Text:")
573             ui_items_general(col, ui)
574
575             ui = theme.user_interface.wcol_option
576             col.label(text="Option:")
577             ui_items_general(col, ui)
578
579             ui = theme.user_interface.wcol_toggle
580             col.label(text="Toggle:")
581             ui_items_general(col, ui)
582
583             ui = theme.user_interface.wcol_num
584             col.label(text="Number Field:")
585             ui_items_general(col, ui)
586
587             ui = theme.user_interface.wcol_numslider
588             col.label(text="Value Slider:")
589             ui_items_general(col, ui)
590
591             ui = theme.user_interface.wcol_box
592             col.label(text="Box:")
593             ui_items_general(col, ui)
594
595             ui = theme.user_interface.wcol_menu
596             col.label(text="Menu:")
597             ui_items_general(col, ui)
598
599             ui = theme.user_interface.wcol_pulldown
600             col.label(text="Pulldown:")
601             ui_items_general(col, ui)
602
603             ui = theme.user_interface.wcol_menu_back
604             col.label(text="Menu Back:")
605             ui_items_general(col, ui)
606
607             ui = theme.user_interface.wcol_menu_item
608             col.label(text="Menu Item:")
609             ui_items_general(col, ui)
610
611             ui = theme.user_interface.wcol_scroll
612             col.label(text="Scroll Bar:")
613             ui_items_general(col, ui)
614
615             ui = theme.user_interface.wcol_progress
616             col.label(text="Progress Bar:")
617             ui_items_general(col, ui)
618
619             ui = theme.user_interface.wcol_list_item
620             col.label(text="List Item:")
621             ui_items_general(col, ui)
622
623             ui = theme.user_interface.wcol_state
624             col.label(text="State:")
625
626             row = col.row()
627
628             subsplit = row.split(percentage=0.95)
629
630             padding = subsplit.split(percentage=0.15)
631             colsub = padding.column()
632             colsub = padding.column()
633             colsub.row().prop(ui, "inner_anim")
634             colsub.row().prop(ui, "inner_anim_sel")
635             colsub.row().prop(ui, "inner_driven")
636             colsub.row().prop(ui, "inner_driven_sel")
637
638             subsplit = row.split(percentage=0.85)
639
640             padding = subsplit.split(percentage=0.15)
641             colsub = padding.column()
642             colsub = padding.column()
643             colsub.row().prop(ui, "inner_key")
644             colsub.row().prop(ui, "inner_key_sel")
645             colsub.row().prop(ui, "blend")
646
647             ui = theme.user_interface
648             col.separator()
649             col.separator()
650
651             split = col.split(percentage=0.93)
652             split.prop(ui, "icon_file")
653
654             layout.separator()
655             layout.separator()
656         elif theme.theme_area == 'BONE_COLOR_SETS':
657             col = split.column()
658
659             for i, ui in enumerate(theme.bone_color_sets):
660                 col.label(text="Color Set %d:" % (i + 1))  # i starts from 0
661
662                 row = col.row()
663
664                 subsplit = row.split(percentage=0.95)
665
666                 padding = subsplit.split(percentage=0.15)
667                 colsub = padding.column()
668                 colsub = padding.column()
669                 colsub.row().prop(ui, "normal")
670                 colsub.row().prop(ui, "select")
671                 colsub.row().prop(ui, "active")
672
673                 subsplit = row.split(percentage=0.85)
674
675                 padding = subsplit.split(percentage=0.15)
676                 colsub = padding.column()
677                 colsub = padding.column()
678                 colsub.row().prop(ui, "show_colored_constraints")
679         else:
680             self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
681
682
683 class USERPREF_PT_file(Panel):
684     bl_space_type = 'USER_PREFERENCES'
685     bl_label = "Files"
686     bl_region_type = 'WINDOW'
687     bl_options = {'HIDE_HEADER'}
688
689     @classmethod
690     def poll(cls, context):
691         userpref = context.user_preferences
692         return (userpref.active_section == 'FILES')
693
694     def draw(self, context):
695         layout = self.layout
696
697         userpref = context.user_preferences
698         paths = userpref.filepaths
699
700         split = layout.split(percentage=0.7)
701
702         col = split.column()
703         col.label(text="File Paths:")
704
705         colsplit = col.split(percentage=0.95)
706         col1 = colsplit.split(percentage=0.3)
707
708         sub = col1.column()
709         sub.label(text="Fonts:")
710         sub.label(text="Textures:")
711         sub.label(text="Texture Plugins:")
712         sub.label(text="Sequence Plugins:")
713         sub.label(text="Render Output:")
714         sub.label(text="Scripts:")
715         sub.label(text="Sounds:")
716         sub.label(text="Temp:")
717         sub.label(text="Image Editor:")
718         sub.label(text="Animation Player:")
719
720         sub = col1.column()
721         sub.prop(paths, "font_directory", text="")
722         sub.prop(paths, "texture_directory", text="")
723         sub.prop(paths, "texture_plugin_directory", text="")
724         sub.prop(paths, "sequence_plugin_directory", text="")
725         sub.prop(paths, "render_output_directory", text="")
726         sub.prop(paths, "script_directory", text="")
727         sub.prop(paths, "sound_directory", text="")
728         sub.prop(paths, "temporary_directory", text="")
729         sub.prop(paths, "image_editor", text="")
730         subsplit = sub.split(percentage=0.3)
731         subsplit.prop(paths, "animation_player_preset", text="")
732         subsplit.prop(paths, "animation_player", text="")
733
734         col = split.column()
735         col.label(text="Save & Load:")
736         col.prop(paths, "use_relative_paths")
737         col.prop(paths, "use_file_compression")
738         col.prop(paths, "use_load_ui")
739         col.prop(paths, "use_filter_files")
740         col.prop(paths, "show_hidden_files_datablocks")
741         col.prop(paths, "hide_recent_locations")
742         col.prop(paths, "show_thumbnails")
743
744         col.separator()
745         col.separator()
746
747         col.prop(paths, "save_version")
748         col.prop(paths, "recent_files")
749         col.prop(paths, "use_save_preview_images")
750         col.label(text="Auto Save:")
751         col.prop(paths, "use_auto_save_temporary_files")
752         sub = col.column()
753         sub.active = paths.use_auto_save_temporary_files
754         sub.prop(paths, "auto_save_time", text="Timer (mins)")
755
756 from bl_ui.space_userpref_keymap import InputKeyMapPanel
757
758
759 class USERPREF_MT_ndof_settings(Menu):
760     # accessed from the window keybindings in C (only)
761     bl_label = "3D Mouse Settings"
762
763     def draw(self, context):
764         layout = self.layout
765         input_prefs = context.user_preferences.inputs
766
767         layout.separator()
768         layout.prop(input_prefs, "ndof_sensitivity")
769
770         if context.space_data.type == 'VIEW_3D':
771             layout.separator()
772             layout.prop(input_prefs, "ndof_show_guide")
773
774             layout.separator()
775             layout.label(text="orbit options")
776             if input_prefs.view_rotate_method == 'TRACKBALL':
777                 layout.prop(input_prefs, "ndof_roll_invert_axis")
778                 layout.prop(input_prefs, "ndof_tilt_invert_axis")
779                 layout.prop(input_prefs, "ndof_rotate_invert_axis")
780             else:
781                 layout.prop(input_prefs, "ndof_orbit_invert_axes")
782
783             layout.separator()
784             layout.label(text="pan options")
785             layout.prop(input_prefs, "ndof_panx_invert_axis")
786             layout.prop(input_prefs, "ndof_pany_invert_axis")
787             layout.prop(input_prefs, "ndof_panz_invert_axis")
788
789             layout.separator()
790             layout.label(text="fly options")
791             layout.prop(input_prefs, "ndof_fly_helicopter", icon='NDOF_FLY')
792             layout.prop(input_prefs, "ndof_lock_horizon", icon='NDOF_DOM')
793
794
795 class USERPREF_PT_input(Panel, InputKeyMapPanel):
796     bl_space_type = 'USER_PREFERENCES'
797     bl_label = "Input"
798
799     @classmethod
800     def poll(cls, context):
801         userpref = context.user_preferences
802         return (userpref.active_section == 'INPUT')
803
804     def draw_input_prefs(self, inputs, layout):
805         # General settings
806         row = layout.row()
807         col = row.column()
808
809         sub = col.column()
810         sub.label(text="Presets:")
811         subrow = sub.row(align=True)
812
813         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
814         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
815         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
816         sub.separator()
817
818         sub.label(text="Mouse:")
819         sub1 = sub.column()
820         sub1.active = (inputs.select_mouse == 'RIGHT')
821         sub1.prop(inputs, "use_mouse_emulate_3_button")
822         sub.prop(inputs, "use_mouse_continuous")
823         sub.prop(inputs, "drag_threshold")
824
825         sub.label(text="Select With:")
826         sub.row().prop(inputs, "select_mouse", expand=True)
827
828         sub = col.column()
829         sub.label(text="Double Click:")
830         sub.prop(inputs, "mouse_double_click_time", text="Speed")
831
832         sub.separator()
833
834         sub.prop(inputs, "use_emulate_numpad")
835
836         sub.separator()
837
838         sub.label(text="Orbit Style:")
839         sub.row().prop(inputs, "view_rotate_method", expand=True)
840
841         sub.label(text="Zoom Style:")
842         sub.row().prop(inputs, "view_zoom_method", text="")
843         if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
844             sub.row().prop(inputs, "view_zoom_axis", expand=True)
845             sub.prop(inputs, "invert_mouse_zoom")
846
847         #sub.prop(inputs, "use_mouse_mmb_paste")
848
849         #col.separator()
850
851         sub = col.column()
852         sub.label(text="Mouse Wheel:")
853         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
854         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
855
856         col.separator()
857         sub = col.column()
858         sub.label(text="NDOF Device:")
859         sub.prop(inputs, "ndof_sensitivity", text="NDOF Sensitivity")
860
861         row.separator()
862
863     def draw(self, context):
864         layout = self.layout
865
866         #import time
867
868         #start = time.time()
869
870         userpref = context.user_preferences
871
872         inputs = userpref.inputs
873
874         split = layout.split(percentage=0.25)
875
876         # Input settings
877         self.draw_input_prefs(inputs, split)
878
879         # Keymap Settings
880         self.draw_keymaps(context, split)
881
882         #print("runtime", time.time() - start)
883
884
885 class USERPREF_MT_addons_dev_guides(Menu):
886     bl_label = "Development Guides"
887
888     # menu to open webpages with addons development guides
889     def draw(self, context):
890         layout = self.layout
891         layout.operator('wm.url_open', text='API Concepts', icon='URL').url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro'
892         layout.operator('wm.url_open', text='Addon Guidelines', icon='URL').url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons'
893         layout.operator('wm.url_open', text='How to share your addon', icon='URL').url = 'http://wiki.blender.org/index.php/Dev:Py/Sharing'
894
895
896 class USERPREF_PT_addons(Panel):
897     bl_space_type = 'USER_PREFERENCES'
898     bl_label = "Addons"
899     bl_region_type = 'WINDOW'
900     bl_options = {'HIDE_HEADER'}
901
902     _addons_fake_modules = {}
903
904     @classmethod
905     def poll(cls, context):
906         userpref = context.user_preferences
907         return (userpref.active_section == 'ADDONS')
908
909     @staticmethod
910     def module_get(mod_name):
911         return USERPREF_PT_addons._addons_fake_modules[mod_name]
912
913     @staticmethod
914     def is_user_addon(mod, user_addon_paths):
915         if not user_addon_paths:
916             user_script_path = bpy.utils.user_script_path()
917             if user_script_path is not None:
918                 user_addon_paths.append(os.path.join(user_script_path, "addons"))
919             user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons"))
920
921         for path in user_addon_paths:
922             if bpy.path.is_subdir(mod.__file__, path):
923                 return True
924         return False
925
926     @staticmethod
927     def draw_error(layout, message):
928         lines = message.split("\n")
929         box = layout.box()
930         rowsub = box.row()
931         rowsub.label(lines[0])
932         rowsub.label(icon='ERROR')
933         for l in lines[1:]:
934             box.label(l)
935
936     def draw(self, context):
937         layout = self.layout
938
939         userpref = context.user_preferences
940         used_ext = {ext.module for ext in userpref.addons}
941
942         # collect the categories that can be filtered on
943         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)]
944
945         split = layout.split(percentage=0.2)
946         col = split.column()
947         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
948         col.label(text="Categories")
949         col.prop(context.window_manager, "addon_filter", expand=True)
950
951         col.label(text="Supported Level")
952         col.prop(context.window_manager, "addon_support", expand=True)
953
954         col = split.column()
955
956         # set in addon_utils.modules(...)
957         if addon_utils.error_duplicates:
958             self.draw_error(col,
959                             "Multiple addons using the same name found!\n"
960                             "likely a problem with the script search path.\n"
961                             "(see console for details)",
962                             )
963
964         if addon_utils.error_encoding:
965             self.draw_error(col,
966                             "One or more addons do not have UTF-8 encoding\n"
967                             "(see console for details)",
968                             )
969
970         filter = context.window_manager.addon_filter
971         search = context.window_manager.addon_search.lower()
972         support = context.window_manager.addon_support
973
974         # initialized on demand
975         user_addon_paths = []
976
977         for mod, info in addons:
978             module_name = mod.__name__
979
980             is_enabled = module_name in used_ext
981
982             if info["support"] not in support:
983                 continue
984
985             # check if add-on should be visible with current filters
986             if (filter == "All") or \
987                     (filter == info["category"]) or \
988                     (filter == "Enabled" and is_enabled) or \
989                     (filter == "Disabled" and not is_enabled):
990
991                 if search and search not in info["name"].lower():
992                     if info["author"]:
993                         if search not in info["author"].lower():
994                             continue
995                     else:
996                         continue
997
998                 # Addon UI Code
999                 box = col.column().box()
1000                 colsub = box.column()
1001                 row = colsub.row()
1002
1003                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
1004
1005                 rowsub = row.row()
1006                 rowsub.active = is_enabled
1007                 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
1008                 if info["warning"]:
1009                     rowsub.label(icon='ERROR')
1010
1011                 # icon showing support level.
1012                 if info["support"] == 'OFFICIAL':
1013                     rowsub.label(icon='FILE_BLEND')
1014                 elif info["support"] == 'COMMUNITY':
1015                     rowsub.label(icon='POSE_DATA')
1016                 else:
1017                     rowsub.label(icon='QUESTION')
1018
1019                 if is_enabled:
1020                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1021                 else:
1022                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
1023
1024                 # Expanded UI (only if additional infos are available)
1025                 if info["show_expanded"]:
1026                     if info["description"]:
1027                         split = colsub.row().split(percentage=0.15)
1028                         split.label(text='Description:')
1029                         split.label(text=info["description"])
1030                     if info["location"]:
1031                         split = colsub.row().split(percentage=0.15)
1032                         split.label(text='Location:')
1033                         split.label(text=info["location"])
1034                     if info["author"]:
1035                         split = colsub.row().split(percentage=0.15)
1036                         split.label(text='Author:')
1037                         split.label(text=info["author"])
1038                     if info["version"]:
1039                         split = colsub.row().split(percentage=0.15)
1040                         split.label(text='Version:')
1041                         split.label(text='.'.join(str(x) for x in info["version"]))
1042                     if info["warning"]:
1043                         split = colsub.row().split(percentage=0.15)
1044                         split.label(text="Warning:")
1045                         split.label(text='  ' + info["warning"], icon='ERROR')
1046
1047                     user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
1048                     tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)
1049
1050                     if tot_row:
1051                         split = colsub.row().split(percentage=0.15)
1052                         split.label(text="Internet:")
1053                         if info["wiki_url"]:
1054                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
1055                         if info["tracker_url"]:
1056                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
1057                         if user_addon:
1058                             split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__
1059
1060                         for i in range(4 - tot_row):
1061                             split.separator()
1062
1063         # Append missing scripts
1064         # First collect scripts that are used but have no script file.
1065         module_names = {mod.__name__ for mod, info in addons}
1066         missing_modules = {ext for ext in used_ext if ext not in module_names}
1067
1068         if missing_modules and filter in {"All", "Enabled"}:
1069             col.column().separator()
1070             col.column().label(text="Missing script files")
1071
1072             module_names = {mod.__name__ for mod, info in addons}
1073             for module_name in sorted(missing_modules):
1074                 is_enabled = module_name in used_ext
1075                 # Addon UI Code
1076                 box = col.column().box()
1077                 colsub = box.column()
1078                 row = colsub.row()
1079
1080                 row.label(text=module_name, icon='ERROR')
1081
1082                 if is_enabled:
1083                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1084
1085
1086 class WM_OT_addon_enable(Operator):
1087     "Enable an addon"
1088     bl_idname = "wm.addon_enable"
1089     bl_label = "Enable Add-On"
1090
1091     module = StringProperty(
1092             name="Module",
1093             description="Module name of the addon to enable",
1094             )
1095
1096     def execute(self, context):
1097         mod = addon_utils.enable(self.module)
1098
1099         if mod:
1100             info = addon_utils.module_bl_info(mod)
1101
1102             info_ver = info.get("blender", (0, 0, 0))
1103
1104             if info_ver > bpy.app.version:
1105                 self.report({'WARNING'}, ("This script was written Blender "
1106                                           "version %d.%d.%d and might not "
1107                                           "function (correctly).\n"
1108                                           "The script is enabled though.") %
1109                                          info_ver)
1110             return {'FINISHED'}
1111         else:
1112             return {'CANCELLED'}
1113
1114
1115 class WM_OT_addon_disable(Operator):
1116     "Disable an addon"
1117     bl_idname = "wm.addon_disable"
1118     bl_label = "Disable Add-On"
1119
1120     module = StringProperty(
1121             name="Module",
1122             description="Module name of the addon to disable",
1123             )
1124
1125     def execute(self, context):
1126         addon_utils.disable(self.module)
1127         return {'FINISHED'}
1128
1129
1130 class WM_OT_addon_install(Operator):
1131     "Install an addon"
1132     bl_idname = "wm.addon_install"
1133     bl_label = "Install Add-On..."
1134
1135     overwrite = BoolProperty(
1136             name="Overwrite",
1137             description="Remove existing addons with the same ID",
1138             default=True,
1139             )
1140     target = EnumProperty(
1141             name="Target Path",
1142             items=(('DEFAULT', "Default", ""),
1143                    ('PREFS', "User Prefs", "")),
1144             )
1145
1146     filepath = StringProperty(
1147             name="File Path",
1148             description="File path to write file to",
1149             )
1150     filter_folder = BoolProperty(
1151             name="Filter folders",
1152             default=True,
1153             options={'HIDDEN'},
1154             )
1155     filter_python = BoolProperty(
1156             name="Filter python",
1157             default=True,
1158             options={'HIDDEN'},
1159             )
1160     filter_glob = StringProperty(
1161             default="*.py;*.zip",
1162             options={'HIDDEN'},
1163             )
1164
1165     @staticmethod
1166     def _module_remove(path_addons, module):
1167         module = os.path.splitext(module)[0]
1168         for f in os.listdir(path_addons):
1169             f_base = os.path.splitext(f)[0]
1170             if f_base == module:
1171                 f_full = os.path.join(path_addons, f)
1172
1173                 if os.path.isdir(f_full):
1174                     os.rmdir(f_full)
1175                 else:
1176                     os.remove(f_full)
1177
1178     def execute(self, context):
1179         import traceback
1180         import zipfile
1181         import shutil
1182
1183         pyfile = self.filepath
1184
1185         if self.target == 'DEFAULT':
1186             # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
1187             path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
1188         else:
1189             path_addons = bpy.context.user_preferences.filepaths.script_directory
1190             if path_addons:
1191                 path_addons = os.path.join(path_addons, "addons")
1192
1193         if not path_addons:
1194             self.report({'ERROR'}, "Failed to get addons path")
1195             return {'CANCELLED'}
1196
1197         # create dir is if missing.
1198         if not os.path.exists(path_addons):
1199             os.makedirs(path_addons)
1200
1201         # Check if we are installing from a target path,
1202         # doing so causes 2+ addons of same name or when the same from/to
1203         # location is used, removal of the file!
1204         addon_path = ""
1205         pyfile_dir = os.path.dirname(pyfile)
1206         for addon_path in addon_utils.paths():
1207             if os.path.samefile(pyfile_dir, addon_path):
1208                 self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
1209                 return {'CANCELLED'}
1210         del addon_path
1211         del pyfile_dir
1212         # done checking for exceptional case
1213
1214         addons_old = {mod.__name__ for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)}
1215
1216         #check to see if the file is in compressed format (.zip)
1217         if zipfile.is_zipfile(pyfile):
1218             try:
1219                 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1220             except:
1221                 traceback.print_exc()
1222                 return {'CANCELLED'}
1223
1224             if self.overwrite:
1225                 for f in file_to_extract.namelist():
1226                     WM_OT_addon_install._module_remove(path_addons, f)
1227             else:
1228                 for f in file_to_extract.namelist():
1229                     path_dest = os.path.join(path_addons, os.path.basename(f))
1230                     if os.path.exists(path_dest):
1231                         self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1232                         return {'CANCELLED'}
1233
1234             try:  # extract the file to "addons"
1235                 file_to_extract.extractall(path_addons)
1236
1237                 # zip files can create this dir with metadata, don't need it
1238                 macosx_dir = os.path.join(path_addons, '__MACOSX')
1239                 if os.path.isdir(macosx_dir):
1240                     shutil.rmtree(macosx_dir)
1241
1242             except:
1243                 traceback.print_exc()
1244                 return {'CANCELLED'}
1245
1246         else:
1247             path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1248
1249             if self.overwrite:
1250                 WM_OT_addon_install._module_remove(path_addons, os.path.basename(pyfile))
1251             elif os.path.exists(path_dest):
1252                 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1253                 return {'CANCELLED'}
1254
1255             #if not compressed file just copy into the addon path
1256             try:
1257                 shutil.copyfile(pyfile, path_dest)
1258
1259             except:
1260                 traceback.print_exc()
1261                 return {'CANCELLED'}
1262
1263         addons_new = {mod.__name__ for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)} - addons_old
1264         addons_new.discard("modules")
1265
1266         # disable any addons we may have enabled previously and removed.
1267         # this is unlikely but do just incase. bug [#23978]
1268         for new_addon in addons_new:
1269             addon_utils.disable(new_addon)
1270
1271         # possible the zip contains multiple addons, we could disallow this
1272         # but for now just use the first
1273         for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1274             if mod.__name__ in addons_new:
1275                 info = addon_utils.module_bl_info(mod)
1276
1277                 # show the newly installed addon.
1278                 context.window_manager.addon_filter = 'All'
1279                 context.window_manager.addon_search = info["name"]
1280                 break
1281
1282         # incase a new module path was created to install this addon.
1283         bpy.utils.refresh_script_paths()
1284
1285         # TODO, should not be a warning.
1286         # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1287         return {'FINISHED'}
1288
1289     def invoke(self, context, event):
1290         wm = context.window_manager
1291         wm.fileselect_add(self)
1292         return {'RUNNING_MODAL'}
1293
1294
1295 class WM_OT_addon_remove(Operator):
1296     "Disable an addon"
1297     bl_idname = "wm.addon_remove"
1298     bl_label = "Remove Add-On"
1299
1300     module = StringProperty(
1301             name="Module",
1302             description="Module name of the addon to remove",
1303             )
1304
1305     @staticmethod
1306     def path_from_addon(module):
1307         for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1308             if mod.__name__ == module:
1309                 filepath = mod.__file__
1310                 if os.path.exists(filepath):
1311                     if os.path.splitext(os.path.basename(filepath))[0] == "__init__":
1312                         return os.path.dirname(filepath), True
1313                     else:
1314                         return filepath, False
1315         return None, False
1316
1317     def execute(self, context):
1318         path, isdir = WM_OT_addon_remove.path_from_addon(self.module)
1319         if path is None:
1320             self.report('WARNING', "Addon path %r could not be found" % path)
1321             return {'CANCELLED'}
1322
1323         # incase its enabled
1324         addon_utils.disable(self.module)
1325
1326         import shutil
1327         if isdir:
1328             shutil.rmtree(path)
1329         else:
1330             os.remove(path)
1331
1332         context.area.tag_redraw()
1333         return {'FINISHED'}
1334
1335     # lame confirmation check
1336     def draw(self, context):
1337         self.layout.label(text="Remove Addon: %r?" % self.module)
1338         path, isdir = WM_OT_addon_remove.path_from_addon(self.module)
1339         self.layout.label(text="Path: %r" % path)
1340
1341     def invoke(self, context, event):
1342         wm = context.window_manager
1343         return wm.invoke_props_dialog(self, width=600)
1344
1345
1346 class WM_OT_addon_expand(Operator):
1347     "Display more information on this add-on"
1348     bl_idname = "wm.addon_expand"
1349     bl_label = ""
1350
1351     module = StringProperty(
1352             name="Module",
1353             description="Module name of the addon to expand",
1354             )
1355
1356     def execute(self, context):
1357         module_name = self.module
1358
1359         # unlikely to fail, module should have already been imported
1360         try:
1361             # mod = __import__(module_name)
1362             mod = USERPREF_PT_addons.module_get(module_name)
1363         except:
1364             import traceback
1365             traceback.print_exc()
1366             return {'CANCELLED'}
1367
1368         info = addon_utils.module_bl_info(mod)
1369         info["show_expanded"] = not info["show_expanded"]
1370         return {'FINISHED'}
1371
1372 if __name__ == "__main__":  # only for live edit.
1373     bpy.utils.register_module(__name__)