Crouch on IRC noticed inconsistency between name COLOR_SETS & attribute bone_color_sets
[blender.git] / release / scripts / startup / bl_ui / space_userpref.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 import os
22 import addon_utils
23
24 from bpy.props import StringProperty, BoolProperty, EnumProperty
25
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 class USERPREF_MT_appconfigs(bpy.types.Menu):
123     bl_label = "AppPresets"
124     preset_subdir = "keyconfig"
125     preset_operator = "wm.appconfig_activate"
126
127     def draw(self, context):
128         props = self.layout.operator("wm.appconfig_default", text="Blender (default)")
129
130         # now draw the presets
131         bpy.types.Menu.draw_preset(self, context)
132
133 class USERPREF_MT_splash(bpy.types.Menu):
134     bl_label = "Splash"
135
136     def draw(self, context):
137         layout = self.layout
138         split = layout.split()
139         row = split.row()
140         row.label("")
141         row = split.row()
142         row.label("Interaction:")
143         # XXX, no redraws
144         # text = bpy.path.display_name(context.window_manager.keyconfigs.active.name)
145         # if not text:
146         #     text = "Blender (default)"
147         row.menu("USERPREF_MT_appconfigs", text="Preset")
148
149
150 class USERPREF_PT_interface(bpy.types.Panel):
151     bl_space_type = 'USER_PREFERENCES'
152     bl_label = "Interface"
153     bl_region_type = 'WINDOW'
154     bl_options = {'HIDE_HEADER'}
155
156     @classmethod
157     def poll(cls, context):
158         userpref = context.user_preferences
159         return (userpref.active_section == 'INTERFACE')
160
161     def draw(self, context):
162         layout = self.layout
163
164         userpref = context.user_preferences
165         view = userpref.view
166
167         row = layout.row()
168
169         col = row.column()
170         col.label(text="Display:")
171         col.prop(view, "show_tooltips")
172         col.prop(view, "show_tooltips_python")
173         col.prop(view, "show_object_info", text="Object Info")
174         col.prop(view, "show_large_cursors")
175         col.prop(view, "show_view_name", text="View Name")
176         col.prop(view, "show_playback_fps", text="Playback FPS")
177         col.prop(view, "use_global_scene")
178         col.prop(view, "object_origin_size")
179
180         col.separator()
181         col.separator()
182         col.separator()
183
184         col.prop(view, "show_mini_axis", text="Display Mini Axis")
185         sub = col.column()
186         sub.active = view.show_mini_axis
187         sub.prop(view, "mini_axis_size", text="Size")
188         sub.prop(view, "mini_axis_brightness", text="Brightness")
189
190         col.separator()
191         row.separator()
192         row.separator()
193
194         col = row.column()
195         col.label(text="View Manipulation:")
196         col.prop(view, "use_mouse_auto_depth")
197         col.prop(view, "use_zoom_to_mouse")
198         col.prop(view, "use_rotate_around_active")
199         col.prop(view, "use_global_pivot")
200
201         col.separator()
202
203         col.prop(view, "use_auto_perspective")
204         col.prop(view, "smooth_view")
205         col.prop(view, "rotation_angle")
206
207         col.separator()
208         col.separator()
209
210         col.label(text="2D Viewports:")
211         col.prop(view, "view2d_grid_spacing_min", text="Minimum Grid Spacing")
212         col.prop(view, "timecode_style")
213
214         row.separator()
215         row.separator()
216
217         col = row.column()
218         #Toolbox doesn't exist yet
219         #col.label(text="Toolbox:")
220         #col.prop(view, "show_column_layout")
221         #col.label(text="Open Toolbox Delay:")
222         #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
223         #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
224         col.prop(view, "show_manipulator")
225         sub = col.column()
226         sub.active = view.show_manipulator
227         sub.prop(view, "manipulator_size", text="Size")
228         sub.prop(view, "manipulator_handle_size", text="Handle Size")
229         sub.prop(view, "manipulator_hotspot", text="Hotspot")
230
231         col.separator()
232         col.separator()
233         col.separator()
234
235         col.label(text="Menus:")
236         col.prop(view, "use_mouse_over_open")
237         col.label(text="Menu Open Delay:")
238         col.prop(view, "open_toplevel_delay", text="Top Level")
239         col.prop(view, "open_sublevel_delay", text="Sub Level")
240
241         col.separator()
242
243         col.prop(view, "show_splash")
244
245
246 class USERPREF_PT_edit(bpy.types.Panel):
247     bl_space_type = 'USER_PREFERENCES'
248     bl_label = "Edit"
249     bl_region_type = 'WINDOW'
250     bl_options = {'HIDE_HEADER'}
251
252     @classmethod
253     def poll(cls, context):
254         userpref = context.user_preferences
255         return (userpref.active_section == 'EDITING')
256
257     def draw(self, context):
258         layout = self.layout
259
260         userpref = context.user_preferences
261         edit = userpref.edit
262
263         row = layout.row()
264
265         col = row.column()
266         col.label(text="Link Materials To:")
267         col.prop(edit, "material_link", text="")
268
269         col.separator()
270         col.separator()
271         col.separator()
272
273         col.label(text="New Objects:")
274         col.prop(edit, "use_enter_edit_mode")
275         col.label(text="Align To:")
276         col.prop(edit, "object_align", text="")
277
278         col.separator()
279         col.separator()
280         col.separator()
281
282         col.label(text="Undo:")
283         col.prop(edit, "use_global_undo")
284         col.prop(edit, "undo_steps", text="Steps")
285         col.prop(edit, "undo_memory_limit", text="Memory Limit")
286
287         row.separator()
288         row.separator()
289
290         col = row.column()
291         col.label(text="Grease Pencil:")
292         col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
293         col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
294         #col.prop(edit, "use_grease_pencil_simplify_stroke", text="Simplify Stroke")
295         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
296         col.prop(edit, "use_grease_pencil_smooth_stroke", text="Smooth Stroke")
297         col.separator()
298         col.separator()
299         col.separator()
300         col.label(text="Playback:")
301         col.prop(edit, "use_negative_frames")
302
303         row.separator()
304         row.separator()
305
306         col = row.column()
307         col.label(text="Keyframing:")
308         col.prop(edit, "use_visual_keying")
309         col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
310
311         col.separator()
312
313         col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
314
315         sub = col.column()
316
317         # sub.active = edit.use_keyframe_insert_auto # incorrect, timeline can enable
318         sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
319
320         col.separator()
321
322         col.label(text="New F-Curve Defaults:")
323         col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
324         col.prop(edit, "keyframe_new_handle_type", text="Handles")
325         col.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
326
327         col.separator()
328         col.separator()
329         col.separator()
330
331         col.label(text="Transform:")
332         col.prop(edit, "use_drag_immediately")
333
334         row.separator()
335         row.separator()
336
337         col = row.column()
338         col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
339
340         col.separator()
341         col.separator()
342         col.separator()
343
344         col.label(text="Duplicate Data:")
345         col.prop(edit, "use_duplicate_mesh", text="Mesh")
346         col.prop(edit, "use_duplicate_surface", text="Surface")
347         col.prop(edit, "use_duplicate_curve", text="Curve")
348         col.prop(edit, "use_duplicate_text", text="Text")
349         col.prop(edit, "use_duplicate_metaball", text="Metaball")
350         col.prop(edit, "use_duplicate_armature", text="Armature")
351         col.prop(edit, "use_duplicate_lamp", text="Lamp")
352         col.prop(edit, "use_duplicate_material", text="Material")
353         col.prop(edit, "use_duplicate_texture", text="Texture")
354         #col.prop(edit, "use_duplicate_fcurve", text="F-Curve")
355         col.prop(edit, "use_duplicate_action", text="Action")
356         col.prop(edit, "use_duplicate_particle", text="Particle")
357
358
359 class USERPREF_PT_system(bpy.types.Panel):
360     bl_space_type = 'USER_PREFERENCES'
361     bl_label = "System"
362     bl_region_type = 'WINDOW'
363     bl_options = {'HIDE_HEADER'}
364
365     @classmethod
366     def poll(cls, 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         # 1. Column
379         column = split.column()
380         colsplit = column.split(percentage=0.85)
381
382         col = colsplit.column()
383         col.label(text="General:")
384         col.prop(system, "dpi")
385         col.prop(system, "frame_server_port")
386         col.prop(system, "scrollback", text="Console Scrollback")
387         col.prop(system, "author", text="Author")
388         col.prop(system, "use_scripts_auto_execute")
389         col.prop(system, "use_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, "use_preview_images")
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, "use_translate_tooltips", text="Tooltips")
423         #col.prop(system, "use_translate_buttons", text="Labels")
424         #col.prop(system, "use_translate_toolbox", text="Toolbox")
425
426         #col.separator()
427
428         #col.prop(system, "use_textured_fonts")
429
430         # 2. Column
431         column = split.column()
432         colsplit = column.split(percentage=0.85)
433
434         col = colsplit.column()
435         col.label(text="OpenGL:")
436         col.prop(system, "gl_clip_alpha", slider=True)
437         col.prop(system, "use_mipmaps")
438         col.prop(system, "use_vertex_buffer_objects")
439         #Anti-aliasing is disabled as it breaks broder/lasso select
440         #col.prop(system, "use_antialiasing")
441         col.label(text="Window Draw Method:")
442         col.prop(system, "window_draw_method", text="")
443         col.label(text="Text Draw Options:")
444         col.prop(system, "use_text_antialiasing")
445         col.label(text="Textures:")
446         col.prop(system, "gl_texture_limit", text="Limit Size")
447         col.prop(system, "texture_time_out", text="Time Out")
448         col.prop(system, "texture_collection_rate", text="Collection Rate")
449
450         col.separator()
451         col.separator()
452         col.separator()
453
454         col.label(text="Sequencer:")
455         col.prop(system, "prefetch_frames")
456         col.prop(system, "memory_cache_limit")
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_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(bpy.types.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_PT_input(InputKeyMapPanel):
754     bl_space_type = 'USER_PREFERENCES'
755     bl_label = "Input"
756
757     @classmethod
758     def poll(cls, context):
759         userpref = context.user_preferences
760         return (userpref.active_section == 'INPUT')
761
762     def draw_input_prefs(self, inputs, layout):
763         # General settings
764         row = layout.row()
765         col = row.column()
766
767         sub = col.column()
768         sub.label(text="Presets:")
769         subrow = sub.row(align=True)
770
771         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
772         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
773         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
774         sub.separator()
775
776         sub.label(text="Mouse:")
777         sub1 = sub.column()
778         sub1.active = (inputs.select_mouse == 'RIGHT')
779         sub1.prop(inputs, "use_mouse_emulate_3_button")
780         sub.prop(inputs, "use_mouse_continuous")
781         sub.prop(inputs, "drag_threshold")
782
783         sub.label(text="Select With:")
784         sub.row().prop(inputs, "select_mouse", expand=True)
785
786         sub = col.column()
787         sub.label(text="Double Click:")
788         sub.prop(inputs, "mouse_double_click_time", text="Speed")
789
790         sub.separator()
791
792         sub.prop(inputs, "use_emulate_numpad")
793
794         sub.separator()
795
796         sub.label(text="Orbit Style:")
797         sub.row().prop(inputs, "view_rotate_method", expand=True)
798
799         sub.label(text="Zoom Style:")
800         sub.row().prop(inputs, "view_zoom_method", text="")
801         if inputs.view_zoom_method == 'DOLLY':
802             sub.row().prop(inputs, "view_zoom_axis", expand=True)
803             sub.prop(inputs, "invert_mouse_wheel_zoom")
804
805         #sub.prop(inputs, "use_mouse_mmb_paste")
806
807         #col.separator()
808
809         sub = col.column()
810         sub.label(text="Mouse Wheel:")
811         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
812         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
813
814         col.separator()
815         ''' not implemented yet
816         sub = col.column()
817         sub.label(text="NDOF Device:")
818         sub.prop(inputs, "ndof_pan_speed", text="Pan Speed")
819         sub.prop(inputs, "ndof_rotate_speed", text="Orbit Speed")
820         '''
821
822         row.separator()
823
824     def draw(self, context):
825         layout = self.layout
826
827         #import time
828
829         #start = time.time()
830
831         userpref = context.user_preferences
832
833         inputs = userpref.inputs
834
835         split = layout.split(percentage=0.25)
836
837         # Input settings
838         self.draw_input_prefs(inputs, split)
839
840         # Keymap Settings
841         self.draw_keymaps(context, split)
842
843         #print("runtime", time.time() - start)
844
845
846 class USERPREF_MT_addons_dev_guides(bpy.types.Menu):
847     bl_label = "Addons develoment guides"
848
849     # menu to open webpages with addons development guides
850     def draw(self, context):
851         layout = self.layout
852         layout.operator('wm.url_open', text='API Concepts'
853             ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro'
854         layout.operator('wm.url_open', text='Addons guidelines',
855             ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons'
856         layout.operator('wm.url_open', text='How to share your addon',
857             ).url = 'http://wiki.blender.org/index.php/Dev:Py/Sharing'
858
859
860 class USERPREF_PT_addons(bpy.types.Panel):
861     bl_space_type = 'USER_PREFERENCES'
862     bl_label = "Addons"
863     bl_region_type = 'WINDOW'
864     bl_options = {'HIDE_HEADER'}
865
866     _addons_fake_modules = {}
867
868     @classmethod
869     def poll(cls, context):
870         userpref = context.user_preferences
871         return (userpref.active_section == 'ADDONS')
872
873     @staticmethod
874     def module_get(mod_name):
875         return USERPREF_PT_addons._addons_fake_modules[mod_name]
876
877     def draw(self, context):
878         layout = self.layout
879
880         userpref = context.user_preferences
881         used_ext = {ext.module for ext in userpref.addons}
882
883         # collect the categories that can be filtered on
884         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)]
885
886         split = layout.split(percentage=0.2)
887         col = split.column()
888         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
889         col.prop(context.window_manager, "addon_filter", expand=True)
890
891         col.label(text="Supported Level")
892         col.prop(context.window_manager, "addon_support", expand=True)
893
894         col = split.column()
895
896         filter = context.window_manager.addon_filter
897         search = context.window_manager.addon_search.lower()
898         support = context.window_manager.addon_support
899
900         for mod, info in addons:
901             module_name = mod.__name__
902
903             is_enabled = module_name in used_ext
904
905             if info["support"] not in support:
906                 continue
907
908             # check if add-on should be visible with current filters
909             if (filter == "All") or \
910                     (filter == info["category"]) or \
911                     (filter == "Enabled" and is_enabled) or \
912                     (filter == "Disabled" and not is_enabled):
913
914                 if search and search not in info["name"].lower():
915                     if info["author"]:
916                         if search not in info["author"].lower():
917                             continue
918                     else:
919                         continue
920
921                 # Addon UI Code
922                 box = col.column().box()
923                 colsub = box.column()
924                 row = colsub.row()
925
926                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
927
928                 rowsub = row.row()
929                 rowsub.active = is_enabled
930                 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
931                 if info["warning"]:
932                     rowsub.label(icon='ERROR')
933
934                 # icon showing support level.
935                 if info["support"] == 'OFFICIAL':
936                     rowsub.label(icon='FILE_BLEND')
937                 elif info["support"] == 'COMMUNITY':
938                     rowsub.label(icon='POSE_DATA')
939                 else:
940                     rowsub.label(icon='QUESTION')
941
942                 if is_enabled:
943                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
944                 else:
945                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
946
947                 # Expanded UI (only if additional infos are available)
948                 if info["show_expanded"]:
949                     if info["description"]:
950                         split = colsub.row().split(percentage=0.15)
951                         split.label(text='Description:')
952                         split.label(text=info["description"])
953                     if info["location"]:
954                         split = colsub.row().split(percentage=0.15)
955                         split.label(text='Location:')
956                         split.label(text=info["location"])
957                     if info["author"]:
958                         split = colsub.row().split(percentage=0.15)
959                         split.label(text='Author:')
960                         split.label(text=info["author"])
961                     if info["version"]:
962                         split = colsub.row().split(percentage=0.15)
963                         split.label(text='Version:')
964                         split.label(text='.'.join(str(x) for x in info["version"]))
965                     if info["warning"]:
966                         split = colsub.row().split(percentage=0.15)
967                         split.label(text="Warning:")
968                         split.label(text='  ' + info["warning"], icon='ERROR')
969                     if info["wiki_url"] or info["tracker_url"]:
970                         split = colsub.row().split(percentage=0.15)
971                         split.label(text="Internet:")
972                         if info["wiki_url"]:
973                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
974                         if info["tracker_url"]:
975                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
976
977                         if info["wiki_url"] and info["tracker_url"]:
978                             split.separator()
979                         else:
980                             split.separator()
981                             split.separator()
982
983         # Append missing scripts
984         # First collect scripts that are used but have no script file.
985         module_names = {mod.__name__ for mod, info in addons}
986         missing_modules = {ext for ext in used_ext if ext not in module_names}
987
988         if missing_modules and filter in {"All", "Enabled"}:
989             col.column().separator()
990             col.column().label(text="Missing script files")
991
992             module_names = {mod.__name__ for mod, info in addons}
993             for module_name in sorted(missing_modules):
994                 is_enabled = module_name in used_ext
995                 # Addon UI Code
996                 box = col.column().box()
997                 colsub = box.column()
998                 row = colsub.row()
999
1000                 row.label(text=module_name, icon='ERROR')
1001
1002                 if is_enabled:
1003                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1004
1005
1006 class WM_OT_addon_enable(bpy.types.Operator):
1007     "Enable an addon"
1008     bl_idname = "wm.addon_enable"
1009     bl_label = "Enable Add-On"
1010
1011     module = StringProperty(name="Module", description="Module name of the addon to enable")
1012
1013     def execute(self, context):
1014         mod = addon_utils.enable(self.module)
1015
1016         if mod:
1017             # check if add-on is written for current blender version, or raise a warning
1018             info = addon_utils.module_bl_info(mod)
1019
1020             if info.get("blender", (0, 0, 0)) > bpy.app.version:
1021                 self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
1022             return {'FINISHED'}
1023         else:
1024             return {'CANCELLED'}
1025
1026
1027 class WM_OT_addon_disable(bpy.types.Operator):
1028     "Disable an addon"
1029     bl_idname = "wm.addon_disable"
1030     bl_label = "Disable Add-On"
1031
1032     module = StringProperty(name="Module", description="Module name of the addon to disable")
1033
1034     def execute(self, context):
1035         addon_utils.disable(self.module)
1036         return {'FINISHED'}
1037
1038
1039 class WM_OT_addon_install(bpy.types.Operator):
1040     "Install an addon"
1041     bl_idname = "wm.addon_install"
1042     bl_label = "Install Add-On..."
1043
1044     overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True)
1045
1046     filepath = StringProperty(name="File Path", description="File path to write file to")
1047     filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
1048     filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
1049     filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'})
1050
1051     @staticmethod
1052     def _module_remove(path_addons, module):
1053         module = os.path.splitext(module)[0]
1054         for f in os.listdir(path_addons):
1055             f_base = os.path.splitext(f)[0]
1056             if f_base == module:
1057                 f_full = os.path.join(path_addons, f)
1058
1059                 if os.path.isdir(f_full):
1060                     os.rmdir(f_full)
1061                 else:
1062                     os.remove(f_full)
1063
1064     def execute(self, context):
1065         import traceback
1066         import zipfile
1067         import shutil
1068
1069         pyfile = self.filepath
1070
1071         # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
1072         path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
1073
1074         if not path_addons:
1075             self.report({'ERROR'}, "Failed to get addons path")
1076             return {'CANCELLED'}
1077
1078         # Check if we are installing from a target path,
1079         # doing so causes 2+ addons of same name or when the same from/to
1080         # location is used, removal of the file!
1081         addon_path = ""
1082         pyfile_dir = os.path.dirname(pyfile)
1083         for addon_path in addon_utils.paths():
1084             if os.path.samefile(pyfile_dir, addon_path):
1085                 self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
1086                 return {'CANCELLED'}
1087         del addon_path
1088         del pyfile_dir
1089         # done checking for exceptional case
1090
1091         contents = set(os.listdir(path_addons))
1092
1093         #check to see if the file is in compressed format (.zip)
1094         if zipfile.is_zipfile(pyfile):
1095             try:
1096                 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1097             except:
1098                 traceback.print_exc()
1099                 return {'CANCELLED'}
1100
1101             if self.overwrite:
1102                 for f in file_to_extract.namelist():
1103                     __class__._module_remove(path_addons, f)
1104             else:
1105                 for f in file_to_extract.namelist():
1106                     path_dest = os.path.join(path_addons, os.path.basename(f))
1107                     if os.path.exists(path_dest):
1108                         self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1109                         return {'CANCELLED'}
1110
1111             try:  # extract the file to "addons"
1112                 file_to_extract.extractall(path_addons)
1113
1114                 # zip files can create this dir with metadata, don't need it
1115                 macosx_dir = os.path.join(path_addons, '__MACOSX')
1116                 if os.path.isdir(macosx_dir):
1117                     shutil.rmtree(macosx_dir)
1118
1119             except:
1120                 traceback.print_exc()
1121                 return {'CANCELLED'}
1122
1123         else:
1124             path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1125
1126             if self.overwrite:
1127                 __class__._module_remove(path_addons, os.path.basename(pyfile))
1128             elif os.path.exists(path_dest):
1129                 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1130                 return {'CANCELLED'}
1131
1132             #if not compressed file just copy into the addon path
1133             try:
1134                 shutil.copyfile(pyfile, path_dest)
1135
1136             except:
1137                 traceback.print_exc()
1138                 return {'CANCELLED'}
1139
1140         # disable any addons we may have enabled previously and removed.
1141         # this is unlikely but do just incase. bug [#23978]
1142         addons_new = set(os.listdir(path_addons)) - contents
1143         for new_addon in addons_new:
1144             addon_utils.disable(os.path.splitext(new_addon)[0])
1145
1146         # possible the zip contains multiple addons, we could disallow this
1147         # but for now just use the first
1148         for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1149             if mod.__name__ in addons_new:
1150                 info = addon_utils.module_bl_info(mod)
1151
1152                 # show the newly installed addon.
1153                 context.window_manager.addon_filter = 'All'
1154                 context.window_manager.addon_search = info["name"]
1155                 break
1156
1157         # TODO, should not be a warning.
1158         # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1159         return {'FINISHED'}
1160
1161     def invoke(self, context, event):
1162         wm = context.window_manager
1163         wm.fileselect_add(self)
1164         return {'RUNNING_MODAL'}
1165
1166
1167 class WM_OT_addon_expand(bpy.types.Operator):
1168     "Display more information on this add-on"
1169     bl_idname = "wm.addon_expand"
1170     bl_label = ""
1171
1172     module = StringProperty(name="Module", description="Module name of the addon to expand")
1173
1174     def execute(self, context):
1175         module_name = self.module
1176
1177         # unlikely to fail, module should have already been imported
1178         try:
1179             # mod = __import__(module_name)
1180             mod = USERPREF_PT_addons.module_get(module_name)
1181         except:
1182             import traceback
1183             traceback.print_exc()
1184             return {'CANCELLED'}
1185
1186         info = addon_utils.module_bl_info(mod)
1187         info["show_expanded"] = not info["show_expanded"]
1188         return {'FINISHED'}