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