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