5bbf3e6d98db3ee04673198e6a88fdba9a67367e
[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 shutil
23
24
25 def ui_items_general(col, context):
26     """ General UI Theme Settings (User Interface)
27     """
28
29     row = col.row()
30
31     subsplit = row.split(percentage=0.95)
32
33     padding = subsplit.split(percentage=0.15)
34     colsub = padding.column()
35     colsub = padding.column()
36     colsub.row().prop(context, "outline")
37     colsub.row().prop(context, "item", slider=True)
38     colsub.row().prop(context, "inner", slider=True)
39     colsub.row().prop(context, "inner_sel", slider=True)
40
41     subsplit = row.split(percentage=0.85)
42
43     padding = subsplit.split(percentage=0.15)
44     colsub = padding.column()
45     colsub = padding.column()
46     colsub.row().prop(context, "text")
47     colsub.row().prop(context, "text_sel")
48     colsub.prop(context, "shaded")
49     subsub = colsub.column(align=True)
50     subsub.active = context.shaded
51     subsub.prop(context, "shadetop")
52     subsub.prop(context, "shadedown")
53
54     col.separator()
55
56
57 def opengl_lamp_buttons(column, lamp):
58     split = column.split(percentage=0.1)
59
60     if lamp.enabled == True:
61         split.prop(lamp, "enabled", text="", icon='OUTLINER_OB_LAMP')
62     else:
63         split.prop(lamp, "enabled", text="", icon='LAMP_DATA')
64
65     col = split.column()
66     col.active = lamp.enabled
67     row = col.row()
68     row.label(text="Diffuse:")
69     row.prop(lamp, "diffuse_color", text="")
70     row = col.row()
71     row.label(text="Specular:")
72     row.prop(lamp, "specular_color", text="")
73
74     col = split.column()
75     col.active = lamp.enabled
76     col.prop(lamp, "direction", text="")
77
78
79 class USERPREF_HT_header(bpy.types.Header):
80     bl_space_type = 'USER_PREFERENCES'
81
82     def draw(self, context):
83         layout = self.layout
84         layout.template_header(menus=False)
85
86         userpref = context.user_preferences
87
88         layout.operator_context = 'EXEC_AREA'
89         layout.operator("wm.save_homefile", text="Save As Default")
90
91         layout.operator_context = 'INVOKE_DEFAULT'
92
93         if userpref.active_section == 'INPUT':
94             op = layout.operator("wm.keyconfig_export")
95             op.filepath = "keymap.py"
96             op = layout.operator("wm.keyconfig_import")
97             op.filepath = "keymap.py"
98         elif userpref.active_section == 'ADDONS':
99             op = layout.operator("wm.addon_install")
100             op.filepath = "*.py"
101         elif userpref.active_section == 'THEMES':
102             op = layout.operator("ui.reset_default_theme")
103
104
105 class USERPREF_PT_tabs(bpy.types.Panel):
106     bl_label = ""
107     bl_space_type = 'USER_PREFERENCES'
108     bl_region_type = 'WINDOW'
109     bl_show_header = False
110
111     def draw(self, context):
112         layout = self.layout
113
114         userpref = context.user_preferences
115
116         layout.prop(userpref, "active_section", expand=True)
117
118
119 class USERPREF_MT_interaction_presets(bpy.types.Menu):
120     bl_label = "Presets"
121     preset_subdir = "interaction"
122     preset_operator = "script.execute_preset"
123     draw = bpy.types.Menu.draw_preset
124
125
126 class USERPREF_MT_splash(bpy.types.Menu):
127     bl_label = "Splash"
128
129     def draw(self, context):
130         layout = self.layout
131         split = layout.split()
132         row = split.row()
133         row.label("")
134         row = split.row()
135         row.label("Interaction:")
136         row.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
137
138
139 class USERPREF_PT_interface(bpy.types.Panel):
140     bl_space_type = 'USER_PREFERENCES'
141     bl_label = "Interface"
142     bl_region_type = 'WINDOW'
143     bl_show_header = False
144
145     def poll(self, context):
146         userpref = context.user_preferences
147         return (userpref.active_section == 'INTERFACE')
148
149     def draw(self, context):
150         layout = self.layout
151
152         userpref = context.user_preferences
153         view = userpref.view
154
155         row = layout.row()
156
157         col = row.column()
158         col.label(text="Display:")
159         col.prop(view, "tooltips")
160         col.prop(view, "display_object_info", text="Object Info")
161         col.prop(view, "use_large_cursors")
162         col.prop(view, "show_view_name", text="View Name")
163         col.prop(view, "show_playback_fps", text="Playback FPS")
164         col.prop(view, "global_scene")
165         col.prop(view, "object_origin_size")
166
167         col.separator()
168         col.separator()
169         col.separator()
170
171         col.prop(view, "show_mini_axis", text="Display Mini Axis")
172         sub = col.column()
173         sub.active = view.show_mini_axis
174         sub.prop(view, "mini_axis_size", text="Size")
175         sub.prop(view, "mini_axis_brightness", text="Brightness")
176
177         col.separator()
178         col.separator()
179         col.separator()
180
181         col.label(text="Properties Window:")
182         col.prop(view, "properties_width_check")
183
184         row.separator()
185         row.separator()
186
187         col = row.column()
188         col.label(text="View Manipulation:")
189         col.prop(view, "auto_depth")
190         col.prop(view, "zoom_to_mouse")
191         col.prop(view, "rotate_around_selection")
192         col.prop(view, "global_pivot")
193
194         col.separator()
195
196         col.prop(view, "auto_perspective")
197         col.prop(view, "smooth_view")
198         col.prop(view, "rotation_angle")
199
200         col.separator()
201         col.separator()
202
203         col.label(text="2D Viewports:")
204         col.prop(view, "view2d_grid_minimum_spacing", text="Minimum Grid Spacing")
205         col.prop(view, "timecode_style")
206
207         row.separator()
208         row.separator()
209
210         col = row.column()
211         #Toolbox doesn't exist yet
212         #col.label(text="Toolbox:")
213         #col.prop(view, "use_column_layout")
214         #col.label(text="Open Toolbox Delay:")
215         #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
216         #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
217         col.prop(view, "use_manipulator")
218         sub = col.column()
219         sub.active = view.use_manipulator
220         sub.prop(view, "manipulator_size", text="Size")
221         sub.prop(view, "manipulator_handle_size", text="Handle Size")
222         sub.prop(view, "manipulator_hotspot", text="Hotspot")
223
224         col.separator()
225         col.separator()
226         col.separator()
227
228         col.label(text="Menus:")
229         col.prop(view, "open_mouse_over")
230         col.label(text="Menu Open Delay:")
231         col.prop(view, "open_toplevel_delay", text="Top Level")
232         col.prop(view, "open_sublevel_delay", text="Sub Level")
233
234         col.separator()
235
236         col.prop(view, "show_splash")
237
238
239 class USERPREF_PT_edit(bpy.types.Panel):
240     bl_space_type = 'USER_PREFERENCES'
241     bl_label = "Edit"
242     bl_region_type = 'WINDOW'
243     bl_show_header = False
244
245     def poll(self, context):
246         userpref = context.user_preferences
247         return (userpref.active_section == 'EDITING')
248
249     def draw(self, context):
250         layout = self.layout
251
252         userpref = context.user_preferences
253         edit = userpref.edit
254
255         row = layout.row()
256
257         col = row.column()
258         col.label(text="Link Materials To:")
259         col.prop(edit, "material_link", text="")
260
261         col.separator()
262         col.separator()
263         col.separator()
264
265         col.label(text="New Objects:")
266         col.prop(edit, "enter_edit_mode")
267         col.label(text="Align To:")
268         col.prop(edit, "object_align", text="")
269
270         col.separator()
271         col.separator()
272         col.separator()
273
274         col.label(text="Undo:")
275         col.prop(edit, "global_undo")
276         col.prop(edit, "undo_steps", text="Steps")
277         col.prop(edit, "undo_memory_limit", text="Memory Limit")
278
279         row.separator()
280         row.separator()
281
282         col = row.column()
283         col.label(text="Grease Pencil:")
284         col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
285         col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
286         #col.prop(edit, "grease_pencil_simplify_stroke", text="Simplify Stroke")
287         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
288         col.prop(edit, "grease_pencil_smooth_stroke", text="Smooth Stroke")
289         col.separator()
290         col.separator()
291         col.separator()
292         col.label(text="Playback:")
293         col.prop(edit, "use_negative_frames")
294
295         row.separator()
296         row.separator()
297
298         col = row.column()
299         col.label(text="Keyframing:")
300         col.prop(edit, "use_visual_keying")
301         col.prop(edit, "keyframe_insert_needed", text="Only Insert Needed")
302
303         col.separator()
304
305         col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
306
307         sub = col.column()
308
309         # sub.active = edit.use_auto_keying # incorrect, timeline can enable
310         sub.prop(edit, "auto_keyframe_insert_keyingset", text="Only Insert for Keying Set")
311         sub.prop(edit, "auto_keyframe_insert_available", text="Only Insert Available")
312
313         col.separator()
314
315         col.label(text="New F-Curve Defaults:")
316         col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
317         col.prop(edit, "keyframe_new_handle_type", text="Handles")
318         col.prop(edit, "insertkey_xyz_to_rgb", text="XYZ to RGB")
319
320         col.separator()
321         col.separator()
322         col.separator()
323
324         col.label(text="Transform:")
325         col.prop(edit, "drag_immediately")
326
327         row.separator()
328         row.separator()
329
330         sculpt = context.tool_settings.sculpt
331         col = row.column()
332         col.label(text="Paint and Sculpt:")
333         col.prop(edit, "sculpt_paint_use_unified_size", text="Unify Size")
334         col.prop(edit, "sculpt_paint_use_unified_strength", text="Unify Strength")
335         row = col.row(align=True)
336         row.label("Overlay Color:")
337         row.prop(edit, "sculpt_paint_overlay_col", text="")
338         col.prop(sculpt, "use_openmp", text="Threaded Sculpt")
339         col.prop(sculpt, "show_brush")
340
341         col.separator()
342         col.separator()
343         col.separator()
344
345         col.label(text="Duplicate Data:")
346         col.prop(edit, "duplicate_mesh", text="Mesh")
347         col.prop(edit, "duplicate_surface", text="Surface")
348         col.prop(edit, "duplicate_curve", text="Curve")
349         col.prop(edit, "duplicate_text", text="Text")
350         col.prop(edit, "duplicate_metaball", text="Metaball")
351         col.prop(edit, "duplicate_armature", text="Armature")
352         col.prop(edit, "duplicate_lamp", text="Lamp")
353         col.prop(edit, "duplicate_material", text="Material")
354         col.prop(edit, "duplicate_texture", text="Texture")
355         #col.prop(edit, "duplicate_fcurve", text="F-Curve")
356         col.prop(edit, "duplicate_action", text="Action")
357         col.prop(edit, "duplicate_particle", text="Particle")
358
359
360 class USERPREF_PT_system(bpy.types.Panel):
361     bl_space_type = 'USER_PREFERENCES'
362     bl_label = "System"
363     bl_region_type = 'WINDOW'
364     bl_show_header = False
365
366     def poll(self, context):
367         userpref = context.user_preferences
368         return (userpref.active_section == 'SYSTEM')
369
370     def draw(self, context):
371         layout = self.layout
372
373         userpref = context.user_preferences
374         system = userpref.system
375
376         split = layout.split()
377
378
379         # 1. Column
380         column = split.column()
381         colsplit = column.split(percentage=0.85)
382
383         col = colsplit.column()
384         col.label(text="General:")
385         col.prop(system, "dpi")
386         col.prop(system, "frame_server_port")
387         col.prop(system, "scrollback", text="Console Scrollback")
388         col.prop(system, "auto_execute_scripts")
389         col.prop(system, "tabs_as_spaces")
390
391         col.separator()
392         col.separator()
393         col.separator()
394
395         col.label(text="Sound:")
396         col.row().prop(system, "audio_device", expand=True)
397         sub = col.column()
398         sub.active = system.audio_device != 'NONE'
399         #sub.prop(system, "enable_all_codecs")
400         sub.prop(system, "audio_channels", text="Channels")
401         sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
402         sub.prop(system, "audio_sample_rate", text="Sample Rate")
403         sub.prop(system, "audio_sample_format", text="Sample Format")
404
405         col.separator()
406         col.separator()
407         col.separator()
408
409         col.label(text="Screencast:")
410         col.prop(system, "screencast_fps")
411         col.prop(system, "screencast_wait_time")
412         col.separator()
413         col.separator()
414         col.separator()
415
416         #column = split.column()
417         #colsplit = column.split(percentage=0.85)
418
419         # No translation in 2.5 yet
420         #col.prop(system, "language")
421         #col.label(text="Translate:")
422         #col.prop(system, "translate_tooltips", text="Tooltips")
423         #col.prop(system, "translate_buttons", text="Labels")
424         #col.prop(system, "translate_toolbox", text="Toolbox")
425
426         #col.separator()
427
428         #col.prop(system, "use_textured_fonts")
429
430
431         # 2. Column
432         column = split.column()
433         colsplit = column.split(percentage=0.85)
434
435         col = colsplit.column()
436         col.label(text="OpenGL:")
437         col.prop(system, "clip_alpha", slider=True)
438         col.prop(system, "use_mipmaps")
439         col.prop(system, "use_vbos")
440         #Anti-aliasing is disabled as it breaks broder/lasso select
441         #col.prop(system, "use_antialiasing")
442         col.label(text="Window Draw Method:")
443         col.prop(system, "window_draw_method", text="")
444         col.label(text="Textures:")
445         col.prop(system, "gl_texture_limit", text="Limit Size")
446         col.prop(system, "texture_time_out", text="Time Out")
447         col.prop(system, "texture_collection_rate", text="Collection Rate")
448
449         col.separator()
450         col.separator()
451         col.separator()
452
453         col.label(text="Sequencer:")
454         col.prop(system, "prefetch_frames")
455         col.prop(system, "memory_cache_limit")
456
457
458         # 3. Column
459         column = split.column()
460
461         column.label(text="Solid OpenGL lights:")
462
463         split = column.split(percentage=0.1)
464         split.label()
465         split.label(text="Colors:")
466         split.label(text="Direction:")
467
468         lamp = system.solid_lights[0]
469         opengl_lamp_buttons(column, lamp)
470
471         lamp = system.solid_lights[1]
472         opengl_lamp_buttons(column, lamp)
473
474         lamp = system.solid_lights[2]
475         opengl_lamp_buttons(column, lamp)
476
477         column.separator()
478         column.separator()
479         column.separator()
480
481         column.label(text="Color Picker Type:")
482         column.row().prop(system, "color_picker_type", text="")
483
484         column.separator()
485         column.separator()
486         column.separator()
487
488         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
489         sub = column.column()
490         sub.active = system.use_weight_color_range
491         sub.template_color_ramp(system, "weight_color_range", expand=True)
492
493
494 class USERPREF_PT_theme(bpy.types.Panel):
495     bl_space_type = 'USER_PREFERENCES'
496     bl_label = "Themes"
497     bl_region_type = 'WINDOW'
498     bl_show_header = False
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     def poll(self, context):
531         userpref = context.user_preferences
532         return (userpref.active_section == 'THEMES')
533
534     def draw(self, context):
535         layout = self.layout
536
537         theme = context.user_preferences.themes[0]
538
539         split_themes = layout.split(percentage=0.2)
540         split_themes.prop(theme, "theme_area", expand=True)
541
542         split = layout.split(percentage=0.4)
543
544
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
642             ui = theme.user_interface
643             col.separator()
644             col.separator()
645
646             split = col.split(percentage=0.93)
647             split.prop(ui, "icon_file")
648
649             layout.separator()
650             layout.separator()
651
652         else:
653             self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
654
655
656 class USERPREF_PT_file(bpy.types.Panel):
657     bl_space_type = 'USER_PREFERENCES'
658     bl_label = "Files"
659     bl_region_type = 'WINDOW'
660     bl_show_header = False
661
662     def poll(self, context):
663         userpref = context.user_preferences
664         return (userpref.active_section == 'FILES')
665
666     def draw(self, context):
667         layout = self.layout
668
669         userpref = context.user_preferences
670         paths = userpref.filepaths
671
672         split = layout.split(percentage=0.7)
673
674         col = split.column()
675         col.label(text="File Paths:")
676
677         colsplit = col.split(percentage=0.95)
678         col1 = colsplit.split(percentage=0.3)
679
680         sub = col1.column()
681         sub.label(text="Fonts:")
682         sub.label(text="Textures:")
683         sub.label(text="Texture Plugins:")
684         sub.label(text="Sequence Plugins:")
685         sub.label(text="Render Output:")
686         sub.label(text="Scripts:")
687         sub.label(text="Sounds:")
688         sub.label(text="Temp:")
689         sub.label(text="Image Editor:")
690         sub.label(text="Animation Player:")
691
692         sub = col1.column()
693         sub.prop(paths, "fonts_directory", text="")
694         sub.prop(paths, "textures_directory", text="")
695         sub.prop(paths, "texture_plugin_directory", text="")
696         sub.prop(paths, "sequence_plugin_directory", text="")
697         sub.prop(paths, "render_output_directory", text="")
698         sub.prop(paths, "python_scripts_directory", text="")
699         sub.prop(paths, "sounds_directory", text="")
700         sub.prop(paths, "temporary_directory", text="")
701         sub.prop(paths, "image_editor", text="")
702         subsplit = sub.split(percentage=0.3)
703         subsplit.prop(paths, "animation_player_preset", text="")
704         subsplit.prop(paths, "animation_player", text="")
705
706         col = split.column()
707         col.label(text="Save & Load:")
708         col.prop(paths, "use_relative_paths")
709         col.prop(paths, "compress_file")
710         col.prop(paths, "load_ui")
711         col.prop(paths, "filter_file_extensions")
712         col.prop(paths, "hide_dot_files_datablocks")
713
714         col.separator()
715         col.separator()
716
717         col.label(text="Auto Save:")
718         col.prop(paths, "save_version")
719         col.prop(paths, "recent_files")
720         col.prop(paths, "save_preview_images")
721         col.prop(paths, "auto_save_temporary_files")
722         sub = col.column()
723         sub.active = paths.auto_save_temporary_files
724         sub.prop(paths, "auto_save_time", text="Timer (mins)")
725
726 from space_userpref_keymap import InputKeyMapPanel
727
728
729 class USERPREF_PT_input(InputKeyMapPanel):
730     bl_space_type = 'USER_PREFERENCES'
731     bl_label = "Input"
732
733     def poll(self, context):
734         userpref = context.user_preferences
735         return (userpref.active_section == 'INPUT')
736
737     def draw_input_prefs(self, inputs, layout):
738         # General settings
739         row = layout.row()
740         col = row.column()
741
742         sub = col.column()
743         sub.label(text="Presets:")
744         subrow = sub.row(align=True)
745         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
746         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
747         sub.separator()
748
749         sub.label(text="Mouse:")
750         sub1 = sub.column()
751         sub1.active = (inputs.select_mouse == 'RIGHT')
752         sub1.prop(inputs, "emulate_3_button_mouse")
753         sub.prop(inputs, "continuous_mouse")
754
755         sub.label(text="Select With:")
756         sub.row().prop(inputs, "select_mouse", expand=True)
757
758         sub = col.column()
759         sub.label(text="Double Click:")
760         sub.prop(inputs, "double_click_time", text="Speed")
761
762         sub.separator()
763
764         sub.prop(inputs, "emulate_numpad")
765
766         sub.separator()
767
768         sub.label(text="Orbit Style:")
769         sub.row().prop(inputs, "view_rotation", expand=True)
770
771         sub.label(text="Zoom Style:")
772         sub.row().prop(inputs, "zoom_style", text="")
773         if inputs.zoom_style == 'DOLLY':
774             sub.row().prop(inputs, "zoom_axis", expand=True)
775             sub.prop(inputs, "invert_zoom_direction")
776
777         #sub.prop(inputs, "use_middle_mouse_paste")
778
779         #col.separator()
780
781         sub = col.column()
782         sub.label(text="Mouse Wheel:")
783         sub.prop(inputs, "wheel_invert_zoom", text="Invert Wheel Zoom Direction")
784         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
785
786         col.separator()
787         ''' not implemented yet
788         sub = col.column()
789         sub.label(text="NDOF Device:")
790         sub.prop(inputs, "ndof_pan_speed", text="Pan Speed")
791         sub.prop(inputs, "ndof_rotate_speed", text="Orbit Speed")
792         '''
793
794         row.separator()
795
796     def draw(self, context):
797         layout = self.layout
798
799         #import time
800
801         #start = time.time()
802
803         userpref = context.user_preferences
804         wm = context.manager
805
806         inputs = userpref.inputs
807
808         split = layout.split(percentage=0.25)
809
810         # Input settings
811         self.draw_input_prefs(inputs, split)
812
813         # Keymap Settings
814         self.draw_keymaps(context, split)
815
816         #print("runtime", time.time() - start)
817
818
819 class USERPREF_PT_addons(bpy.types.Panel):
820     bl_space_type = 'USER_PREFERENCES'
821     bl_label = "Addons"
822     bl_region_type = 'WINDOW'
823     bl_show_header = False
824
825     def poll(self, context):
826         userpref = context.user_preferences
827         return (userpref.active_section == 'ADDONS')
828
829     @staticmethod
830     def _addon_list():
831         import sys
832         import time
833
834         modules = []
835         loaded_modules = set()
836         paths = bpy.utils.script_paths("addons")
837
838         if bpy.app.debug:
839             t_main = time.time()
840
841         # sys.path.insert(0, None)
842         for path in paths:
843             # sys.path[0] = path
844             modules.extend(bpy.utils.modules_from_path(path, loaded_modules))
845
846         if bpy.app.debug:
847             print("Addon Script Load Time %.4f" % (time.time() - t_main))
848
849         # del sys.path[0]
850         return modules
851
852     def draw(self, context):
853         layout = self.layout
854
855         userpref = context.user_preferences
856         used_ext = {ext.module for ext in userpref.addons}
857
858         # collect the categories that can be filtered on
859         addons = [(mod, addon_info_get(mod)) for mod in self._addon_list()]
860
861         cats = {info["category"] for mod, info in addons}
862         cats.discard("")
863
864         cats = ["All", "Enabled", "Disabled"] + sorted(cats)
865
866         bpy.types.Scene.EnumProperty(items=[(cat, cat, cat + " addons") for cat in cats],
867             name="Category", attr="addon_filter", description="Filter add-ons by category")
868         bpy.types.Scene.StringProperty(name="Search", attr="addon_search",
869             description="Search within the selected filter")
870
871         split = layout.split(percentage=0.2)
872         col = split.column()
873         col.prop(context.scene, "addon_filter", text="Filter", expand=True)
874         col.prop(context.scene, "addon_search", text="", icon='VIEWZOOM')
875
876         col = split.column()
877
878         filter = context.scene.addon_filter
879         search = context.scene.addon_search.lower()
880
881         for mod, info in addons:
882             module_name = mod.__name__
883
884             is_enabled = module_name in used_ext
885
886             # check if add-on should be visible with current filters
887             if (filter == "All") or \
888                     (filter == info["category"]) or \
889                     (filter == "Enabled" and is_enabled) or \
890                     (filter == "Disabled" and not is_enabled):
891
892
893                 if search and search not in info["name"].lower():
894                     if info["author"]:
895                         if search not in info["author"].lower():
896                             continue
897                     else:
898                         continue
899
900                 # Addon UI Code
901                 box = col.column().box()
902                 colsub = box.column()
903                 row = colsub.row()
904
905                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
906
907                 rowsub = row.row()
908                 rowsub.active = is_enabled
909                 rowsub.label(text=info["name"], icon='ERROR' if info["warning"] else 'BLENDER')
910
911                 if is_enabled:
912                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
913                 else:
914                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
915
916                 # Expanded UI (only if additional infos are available)
917                 if info["expanded"]:
918                     if info["description"]:
919                         split = colsub.row().split(percentage=0.15)
920                         split.label(text='Description:')
921                         split.label(text=info["description"])
922                     if info["location"]:
923                         split = colsub.row().split(percentage=0.15)
924                         split.label(text='Location:')
925                         split.label(text=info["location"])
926                     if info["author"]:
927                         split = colsub.row().split(percentage=0.15)
928                         split.label(text='Author:')
929                         split.label(text=info["author"])
930                     if info["version"]:
931                         split = colsub.row().split(percentage=0.15)
932                         split.label(text='Version:')
933                         split.label(text=info["version"])
934                     if info["warning"]:
935                         split = colsub.row().split(percentage=0.15)
936                         split.label(text="Warning:")
937                         split.label(text='  ' + info["warning"], icon='ERROR')
938                     if info["wiki_url"] or info["tracker_url"]:
939                         split = colsub.row().split(percentage=0.15)
940                         split.label(text="Internet:")
941                         if info["wiki_url"]:
942                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
943                         if info["tracker_url"]:
944                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
945
946                         if info["wiki_url"] and info["tracker_url"]:
947                             split.separator()
948                         else:
949                             split.separator()
950                             split.separator()
951
952         # Append missing scripts
953         # First collect scripts that are used but have no script file.
954         module_names = {mod.__name__ for mod, info in addons}
955         missing_modules = {ext for ext in used_ext if ext not in module_names}
956
957         if missing_modules and filter in ("All", "Enabled"):
958             col.column().separator()
959             col.column().label(text="Missing script files")
960
961             module_names = {mod.__name__ for mod, info in addons}
962             for ext in sorted(missing_modules):
963                 # Addon UI Code
964                 box = col.column().box()
965                 colsub = box.column()
966                 row = colsub.row()
967
968                 row.label(text=ext, icon='ERROR')
969                 row.operator("wm.addon_disable").module = ext
970
971 from bpy.props import *
972
973
974 def addon_info_get(mod, info_basis={"name": "", "author": "", "version": "", "blender": "", "location": "", "description": "", "wiki_url": "", "tracker_url": "", "category": "", "warning": "", "expanded": False}):
975     addon_info = getattr(mod, "bl_addon_info", {})
976
977     # avoid re-initializing
978     if "_init" in addon_info:
979         return addon_info
980
981     if not addon_info:
982         mod.bl_addon_info = addon_info
983
984     for key, value in info_basis.items():
985         addon_info.setdefault(key, value)
986
987     if not addon_info["name"]:
988         addon_info["name"] = mod.__name__
989
990     addon_info["_init"] = None
991     return addon_info
992
993
994 class WM_OT_addon_enable(bpy.types.Operator):
995     "Enable an addon"
996     bl_idname = "wm.addon_enable"
997     bl_label = "Enable Add-On"
998
999     module = StringProperty(name="Module", description="Module name of the addon to enable")
1000
1001     def execute(self, context):
1002         module_name = self.properties.module
1003
1004         try:
1005             mod = __import__(module_name)
1006             mod.register()
1007         except:
1008             import traceback
1009             traceback.print_exc()
1010             return {'CANCELLED'}
1011
1012         ext = context.user_preferences.addons.new()
1013         ext.module = module_name
1014
1015         # check if add-on is written for current blender version, or raise a warning
1016         info = addon_info_get(mod)
1017
1018         if info.get("blender", (0, 0, 0)) > bpy.app.version:
1019             self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
1020
1021         return {'FINISHED'}
1022
1023
1024 class WM_OT_addon_disable(bpy.types.Operator):
1025     "Disable an addon"
1026     bl_idname = "wm.addon_disable"
1027     bl_label = "Disable Add-On"
1028
1029     module = StringProperty(name="Module", description="Module name of the addon to disable")
1030
1031     def execute(self, context):
1032         import traceback
1033         module_name = self.properties.module
1034
1035         try:
1036             mod = __import__(module_name)
1037             mod.unregister()
1038         except:
1039             traceback.print_exc()
1040
1041         addons = context.user_preferences.addons
1042         ok = True
1043         while ok: # incase its in more then once.
1044             ok = False
1045             for ext in addons:
1046                 if ext.module == module_name:
1047                     addons.remove(ext)
1048                     ok = True
1049                     break
1050
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     module = StringProperty(name="Module", description="Module name of the addon to disable")
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
1065     def execute(self, context):
1066         import traceback
1067         import zipfile
1068         pyfile = self.properties.filepath
1069
1070         path_addons = bpy.utils.script_paths("addons")[-1]
1071
1072         #check to see if the file is in compressed format (.zip)
1073         if zipfile.is_zipfile(pyfile):
1074             try:
1075                 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1076
1077                 #extract the file to "addons"
1078                 file_to_extract.extractall(path_addons)
1079
1080             except:
1081                 traceback.print_exc()
1082                 return {'CANCELLED'}
1083
1084         else:
1085             path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1086
1087             if os.path.exists(path_dest):
1088                 self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest)
1089                 return {'CANCELLED'}
1090
1091             #if not compressed file just copy into the addon path
1092             try:
1093                 shutil.copyfile(pyfile, path_dest)
1094
1095             except:
1096                 traceback.print_exc()
1097                 return {'CANCELLED'}
1098
1099         # TODO, should not be a warning.
1100         # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1101         return {'FINISHED'}
1102
1103     def invoke(self, context, event):
1104         paths = bpy.utils.script_paths("addons")
1105         if not paths:
1106             self.report({'ERROR'}, "No 'addons' path could be found in " + str(bpy.utils.script_paths()))
1107             return {'CANCELLED'}
1108
1109         wm = context.manager
1110         wm.add_fileselect(self)
1111         return {'RUNNING_MODAL'}
1112
1113
1114 class WM_OT_addon_expand(bpy.types.Operator):
1115     "Display more information on this add-on"
1116     bl_idname = "wm.addon_expand"
1117     bl_label = ""
1118
1119     module = StringProperty(name="Module", description="Module name of the addon to expand")
1120
1121     def execute(self, context):
1122         module_name = self.properties.module
1123
1124         # unlikely to fail, module should have already been imported
1125         try:
1126             mod = __import__(module_name)
1127         except:
1128             import traceback
1129             traceback.print_exc()
1130             return {'CANCELLED'}
1131
1132         info = addon_info_get(mod)
1133         info["expanded"] = not info["expanded"]
1134         return {'FINISHED'}
1135
1136
1137 classes = [
1138     USERPREF_HT_header,
1139     USERPREF_PT_tabs,
1140     USERPREF_PT_interface,
1141     USERPREF_PT_theme,
1142     USERPREF_PT_edit,
1143     USERPREF_PT_system,
1144     USERPREF_PT_file,
1145     USERPREF_PT_input,
1146     USERPREF_PT_addons,
1147
1148     USERPREF_MT_interaction_presets,
1149     USERPREF_MT_splash,
1150
1151     WM_OT_addon_enable,
1152     WM_OT_addon_disable,
1153     WM_OT_addon_install,
1154     WM_OT_addon_expand]
1155
1156
1157 def register():
1158     register = bpy.types.register
1159     for cls in classes:
1160         register(cls)
1161
1162
1163 def unregister():
1164     unregister = bpy.types.unregister
1165     for cls in classes:
1166         unregister(cls)
1167
1168 if __name__ == "__main__":
1169     register()