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