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