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