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