4f444a8e25391a825ca21ecf95db0589e5644ce3
[blender.git] / release / scripts / ui / space_userpref.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 import os
22 import addon_utils
23
24 from bpy.props import StringProperty, BoolProperty, EnumProperty
25
26
27 def ui_items_general(col, context):
28     """ General UI Theme Settings (User Interface)
29     """
30
31     row = col.row()
32
33     subsplit = row.split(percentage=0.95)
34
35     padding = subsplit.split(percentage=0.15)
36     colsub = padding.column()
37     colsub = padding.column()
38     colsub.row().prop(context, "outline")
39     colsub.row().prop(context, "item", slider=True)
40     colsub.row().prop(context, "inner", slider=True)
41     colsub.row().prop(context, "inner_sel", slider=True)
42
43     subsplit = row.split(percentage=0.85)
44
45     padding = subsplit.split(percentage=0.15)
46     colsub = padding.column()
47     colsub = padding.column()
48     colsub.row().prop(context, "text")
49     colsub.row().prop(context, "text_sel")
50     colsub.prop(context, "show_shaded")
51     subsub = colsub.column(align=True)
52     subsub.active = context.show_shaded
53     subsub.prop(context, "shadetop")
54     subsub.prop(context, "shadedown")
55
56     col.separator()
57
58
59 def opengl_lamp_buttons(column, lamp):
60     split = column.split(percentage=0.1)
61
62     split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
63
64     col = split.column()
65     col.active = lamp.use
66     row = col.row()
67     row.label(text="Diffuse:")
68     row.prop(lamp, "diffuse_color", text="")
69     row = col.row()
70     row.label(text="Specular:")
71     row.prop(lamp, "specular_color", text="")
72
73     col = split.column()
74     col.active = lamp.use
75     col.prop(lamp, "direction", text="")
76
77
78 class USERPREF_HT_header(bpy.types.Header):
79     bl_space_type = 'USER_PREFERENCES'
80
81     def draw(self, context):
82         layout = self.layout
83         layout.template_header(menus=False)
84
85         userpref = context.user_preferences
86
87         layout.operator_context = 'EXEC_AREA'
88         layout.operator("wm.save_homefile", text="Save As Default")
89
90         layout.operator_context = 'INVOKE_DEFAULT'
91
92         if userpref.active_section == 'INPUT':
93             layout.operator("wm.keyconfig_export")
94             layout.operator("wm.keyconfig_import")
95         elif userpref.active_section == 'ADDONS':
96             layout.operator("wm.addon_install")
97             layout.menu("USERPREF_MT_addons_dev_guides", text="  Addons Developer Guides", icon='INFO')
98         elif userpref.active_section == 'THEMES':
99             layout.operator("ui.reset_default_theme")
100
101
102 class USERPREF_PT_tabs(bpy.types.Panel):
103     bl_label = ""
104     bl_space_type = 'USER_PREFERENCES'
105     bl_region_type = 'WINDOW'
106     bl_options = {'HIDE_HEADER'}
107
108     def draw(self, context):
109         layout = self.layout
110
111         userpref = context.user_preferences
112
113         layout.prop(userpref, "active_section", expand=True)
114
115
116 class USERPREF_MT_interaction_presets(bpy.types.Menu):
117     bl_label = "Presets"
118     preset_subdir = "interaction"
119     preset_operator = "script.execute_preset"
120     draw = bpy.types.Menu.draw_preset
121
122
123 class USERPREF_MT_splash(bpy.types.Menu):
124     bl_label = "Splash"
125
126     def draw(self, context):
127         layout = self.layout
128         split = layout.split()
129         row = split.row()
130         row.label("")
131         row = split.row()
132         row.label("Interaction:")
133         # XXX, no redraws
134         # text = bpy.path.display_name(context.window_manager.keyconfigs.active.name)
135         # if not text:
136         #     text = "Blender (default)"
137         row.menu("USERPREF_MT_keyconfigs", text="Preset")
138
139
140 class USERPREF_PT_interface(bpy.types.Panel):
141     bl_space_type = 'USER_PREFERENCES'
142     bl_label = "Interface"
143     bl_region_type = 'WINDOW'
144     bl_options = {'HIDE_HEADER'}
145
146     @classmethod
147     def poll(cls, context):
148         userpref = context.user_preferences
149         return (userpref.active_section == 'INTERFACE')
150
151     def draw(self, context):
152         layout = self.layout
153
154         userpref = context.user_preferences
155         view = userpref.view
156
157         row = layout.row()
158
159         col = row.column()
160         col.label(text="Display:")
161         col.prop(view, "show_tooltips")
162         col.prop(view, "show_tooltips_python")
163         col.prop(view, "show_object_info", text="Object Info")
164         col.prop(view, "show_large_cursors")
165         col.prop(view, "show_view_name", text="View Name")
166         col.prop(view, "show_playback_fps", text="Playback FPS")
167         col.prop(view, "use_global_scene")
168         col.prop(view, "object_origin_size")
169
170         col.separator()
171         col.separator()
172         col.separator()
173
174         col.prop(view, "show_mini_axis", text="Display Mini Axis")
175         sub = col.column()
176         sub.active = view.show_mini_axis
177         sub.prop(view, "mini_axis_size", text="Size")
178         sub.prop(view, "mini_axis_brightness", text="Brightness")
179
180         col.separator()
181         row.separator()
182         row.separator()
183
184         col = row.column()
185         col.label(text="View Manipulation:")
186         col.prop(view, "use_mouse_auto_depth")
187         col.prop(view, "use_zoom_to_mouse")
188         col.prop(view, "use_rotate_around_active")
189         col.prop(view, "use_global_pivot")
190
191         col.separator()
192
193         col.prop(view, "use_auto_perspective")
194         col.prop(view, "smooth_view")
195         col.prop(view, "rotation_angle")
196
197         col.separator()
198         col.separator()
199
200         col.label(text="2D Viewports:")
201         col.prop(view, "view2d_grid_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 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_cats = None
857     _addons_sups = None
858     _addons_fake_modules = {}
859
860     @classmethod
861     def poll(cls, context):
862         userpref = context.user_preferences
863         return (userpref.active_section == 'ADDONS')
864
865     @staticmethod
866     def module_get(mod_name):
867         return USERPREF_PT_addons._addons_fake_modules[mod_name]
868
869     def draw(self, context):
870         layout = self.layout
871
872         userpref = context.user_preferences
873         used_ext = {ext.module for ext in userpref.addons}
874
875         # collect the categories that can be filtered on
876         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)]
877
878         cats = {info["category"] for mod, info in addons}
879         cats.discard("")
880
881         if USERPREF_PT_addons._addons_cats != cats:
882             bpy.types.WindowManager.addon_filter = EnumProperty(items=[(cat, cat, "") for cat in ["All", "Enabled", "Disabled"] + sorted(cats)], name="Category", description="Filter add-ons by category")
883             bpy.types.WindowManager.addon_search = StringProperty(name="Search", description="Search within the selected filter")
884             USERPREF_PT_addons._addons_cats = cats
885
886         sups_default = {'OFFICIAL', 'COMMUNITY'}
887         sups = sups_default | {info["support"] for mod, info in addons}
888         sups.discard("")
889
890         if USERPREF_PT_addons._addons_sups != sups:
891             bpy.types.WindowManager.addon_support = EnumProperty(items=[(sup, sup.title(), "") for  sup in reversed(sorted(sups))], name="Support", description="Display support level", default=sups_default, options={'ENUM_FLAG'})
892             USERPREF_PT_addons._addons_sups = sups
893
894         split = layout.split(percentage=0.2)
895         col = split.column()
896         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
897         col.prop(context.window_manager, "addon_filter", expand=True)
898
899         col.label(text="Supported Level")
900         col.prop(context.window_manager, "addon_support", expand=True)
901
902         col = split.column()
903
904         filter = context.window_manager.addon_filter
905         search = context.window_manager.addon_search.lower()
906         support = context.window_manager.addon_support
907
908         for mod, info in addons:
909             module_name = mod.__name__
910
911             is_enabled = module_name in used_ext
912
913             if info["support"] not in support:
914                 continue
915
916             # check if add-on should be visible with current filters
917             if (filter == "All") or \
918                     (filter == info["category"]) or \
919                     (filter == "Enabled" and is_enabled) or \
920                     (filter == "Disabled" and not is_enabled):
921
922                 if search and search not in info["name"].lower():
923                     if info["author"]:
924                         if search not in info["author"].lower():
925                             continue
926                     else:
927                         continue
928
929                 # Addon UI Code
930                 box = col.column().box()
931                 colsub = box.column()
932                 row = colsub.row()
933
934                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
935
936                 rowsub = row.row()
937                 rowsub.active = is_enabled
938                 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
939                 if info["warning"]:
940                     rowsub.label(icon='ERROR')
941
942                 # icon showing support level.
943                 if info["support"] == 'OFFICIAL':
944                     rowsub.label(icon='FILE_BLEND')
945                 elif info["support"] == 'COMMUNITY':
946                     rowsub.label(icon='POSE_DATA')
947                 else:
948                     rowsub.label(icon='QUESTION')
949
950                 if is_enabled:
951                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
952                 else:
953                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
954
955                 # Expanded UI (only if additional infos are available)
956                 if info["show_expanded"]:
957                     if info["description"]:
958                         split = colsub.row().split(percentage=0.15)
959                         split.label(text='Description:')
960                         split.label(text=info["description"])
961                     if info["location"]:
962                         split = colsub.row().split(percentage=0.15)
963                         split.label(text='Location:')
964                         split.label(text=info["location"])
965                     if info["author"]:
966                         split = colsub.row().split(percentage=0.15)
967                         split.label(text='Author:')
968                         split.label(text=info["author"])
969                     if info["version"]:
970                         split = colsub.row().split(percentage=0.15)
971                         split.label(text='Version:')
972                         split.label(text='.'.join(str(x) for x in info["version"]))
973                     if info["warning"]:
974                         split = colsub.row().split(percentage=0.15)
975                         split.label(text="Warning:")
976                         split.label(text='  ' + info["warning"], icon='ERROR')
977                     if info["wiki_url"] or info["tracker_url"]:
978                         split = colsub.row().split(percentage=0.15)
979                         split.label(text="Internet:")
980                         if info["wiki_url"]:
981                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
982                         if info["tracker_url"]:
983                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
984
985                         if info["wiki_url"] and info["tracker_url"]:
986                             split.separator()
987                         else:
988                             split.separator()
989                             split.separator()
990
991         # Append missing scripts
992         # First collect scripts that are used but have no script file.
993         module_names = {mod.__name__ for mod, info in addons}
994         missing_modules = {ext for ext in used_ext if ext not in module_names}
995
996         if missing_modules and filter in ("All", "Enabled"):
997             col.column().separator()
998             col.column().label(text="Missing script files")
999
1000             module_names = {mod.__name__ for mod, info in addons}
1001             for module_name in sorted(missing_modules):
1002                 is_enabled = module_name in used_ext
1003                 # Addon UI Code
1004                 box = col.column().box()
1005                 colsub = box.column()
1006                 row = colsub.row()
1007
1008                 row.label(text=module_name, icon='ERROR')
1009
1010                 if is_enabled:
1011                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1012
1013
1014 class WM_OT_addon_enable(bpy.types.Operator):
1015     "Enable an addon"
1016     bl_idname = "wm.addon_enable"
1017     bl_label = "Enable Add-On"
1018
1019     module = StringProperty(name="Module", description="Module name of the addon to enable")
1020
1021     def execute(self, context):
1022         mod = addon_utils.enable(self.module)
1023
1024         if mod:
1025             # check if add-on is written for current blender version, or raise a warning
1026             info = addon_utils.module_bl_info(mod)
1027
1028             if info.get("blender", (0, 0, 0)) > bpy.app.version:
1029                 self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
1030             return {'FINISHED'}
1031         else:
1032             return {'CANCELLED'}
1033
1034
1035 class WM_OT_addon_disable(bpy.types.Operator):
1036     "Disable an addon"
1037     bl_idname = "wm.addon_disable"
1038     bl_label = "Disable Add-On"
1039
1040     module = StringProperty(name="Module", description="Module name of the addon to disable")
1041
1042     def execute(self, context):
1043         addon_utils.disable(self.module)
1044         return {'FINISHED'}
1045
1046
1047 class WM_OT_addon_install(bpy.types.Operator):
1048     "Install an addon"
1049     bl_idname = "wm.addon_install"
1050     bl_label = "Install Add-On..."
1051
1052     overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True)
1053
1054     filepath = StringProperty(name="File Path", description="File path to write file to")
1055     filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
1056     filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
1057     filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'})
1058
1059     @staticmethod
1060     def _module_remove(path_addons, module):
1061         module = os.path.splitext(module)[0]
1062         for f in os.listdir(path_addons):
1063             f_base = os.path.splitext(f)[0]
1064             if f_base == module:
1065                 f_full = os.path.join(path_addons, f)
1066
1067                 if os.path.isdir(f_full):
1068                     os.rmdir(f_full)
1069                 else:
1070                     os.remove(f_full)
1071
1072     def execute(self, context):
1073         import traceback
1074         import zipfile
1075         import shutil
1076
1077         pyfile = self.filepath
1078
1079         # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
1080         path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
1081
1082         if not path_addons:
1083             self.report({'ERROR'}, "Failed to get addons path")
1084             return {'CANCELLED'}
1085
1086         # Check if we are installing from a target path,
1087         # doing so causes 2+ addons of same name or when the same from/to
1088         # location is used, removal of the file!
1089         addon_path = ""
1090         pyfile_dir = os.path.dirname(pyfile)
1091         for addon_path in addon_utils.paths():
1092             # if os.path.samefile(pyfile_dir, addon_path):  # Py3.2 only!, upgrade soon!
1093             if (hasattr(os.path, "samefile") and os.path.samefile(pyfile_dir, addon_path)) or pyfile_dir == addon_path:
1094                 self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
1095                 return {'CANCELLED'}
1096         del addon_path
1097         del pyfile_dir
1098         # done checking for exceptional case
1099
1100         contents = set(os.listdir(path_addons))
1101
1102         #check to see if the file is in compressed format (.zip)
1103         if zipfile.is_zipfile(pyfile):
1104             try:
1105                 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1106             except:
1107                 traceback.print_exc()
1108                 return {'CANCELLED'}
1109
1110             if self.overwrite:
1111                 for f in file_to_extract.namelist():
1112                     __class__._module_remove(path_addons, f)
1113             else:
1114                 for f in file_to_extract.namelist():
1115                     path_dest = os.path.join(path_addons, os.path.basename(f))
1116                     if os.path.exists(path_dest):
1117                         self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1118                         return {'CANCELLED'}
1119
1120             try:  # extract the file to "addons"
1121                 file_to_extract.extractall(path_addons)
1122             except:
1123                 traceback.print_exc()
1124                 return {'CANCELLED'}
1125
1126         else:
1127             path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1128
1129             if self.overwrite:
1130                 __class__._module_remove(path_addons, os.path.basename(pyfile))
1131             elif os.path.exists(path_dest):
1132                 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1133                 return {'CANCELLED'}
1134
1135             #if not compressed file just copy into the addon path
1136             try:
1137                 shutil.copyfile(pyfile, path_dest)
1138
1139             except:
1140                 traceback.print_exc()
1141                 return {'CANCELLED'}
1142
1143         # disable any addons we may have enabled previously and removed.
1144         # this is unlikely but do just incase. bug [#23978]
1145         addons_new = set(os.listdir(path_addons)) - contents
1146         for new_addon in addons_new:
1147             addon_utils.disable(os.path.splitext(new_addon)[0])
1148
1149         # possible the zip contains multiple addons, we could disallow this
1150         # but for now just use the first
1151         for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1152             if mod.__name__ in addons_new:
1153                 info = addon_utils.module_bl_info(mod)
1154
1155                 # show the newly installed addon.
1156                 context.window_manager.addon_filter = 'All'
1157                 context.window_manager.addon_search = info["name"]
1158                 break
1159
1160         # TODO, should not be a warning.
1161         # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1162         return {'FINISHED'}
1163
1164     def invoke(self, context, event):
1165         wm = context.window_manager
1166         wm.fileselect_add(self)
1167         return {'RUNNING_MODAL'}
1168
1169
1170 class WM_OT_addon_expand(bpy.types.Operator):
1171     "Display more information on this add-on"
1172     bl_idname = "wm.addon_expand"
1173     bl_label = ""
1174
1175     module = StringProperty(name="Module", description="Module name of the addon to expand")
1176
1177     def execute(self, context):
1178         module_name = self.module
1179
1180         # unlikely to fail, module should have already been imported
1181         try:
1182             # mod = __import__(module_name)
1183             mod = USERPREF_PT_addons.module_get(module_name)
1184         except:
1185             import traceback
1186             traceback.print_exc()
1187             return {'CANCELLED'}
1188
1189         info = addon_utils.module_bl_info(mod)
1190         info["show_expanded"] = not info["show_expanded"]
1191         return {'FINISHED'}
1192
1193
1194 def register():
1195     bpy.utils.register_module(__name__)
1196
1197
1198 def unregister():
1199     bpy.utils.unregister_module(__name__)
1200
1201 if __name__ == "__main__":
1202     register()