Merge with trunk r41701
[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 from bpy.types import Header, Menu, Panel
22 import os
23 import addon_utils
24
25
26 def ui_items_general(col, context):
27     """ General UI Theme Settings (User Interface)
28     """
29
30     row = col.row()
31
32     subsplit = row.split(percentage=0.95)
33
34     padding = subsplit.split(percentage=0.15)
35     colsub = padding.column()
36     colsub = padding.column()
37     colsub.row().prop(context, "outline")
38     colsub.row().prop(context, "item", slider=True)
39     colsub.row().prop(context, "inner", slider=True)
40     colsub.row().prop(context, "inner_sel", slider=True)
41
42     subsplit = row.split(percentage=0.85)
43
44     padding = subsplit.split(percentage=0.15)
45     colsub = padding.column()
46     colsub = padding.column()
47     colsub.row().prop(context, "text")
48     colsub.row().prop(context, "text_sel")
49     colsub.prop(context, "show_shaded")
50     subsub = colsub.column(align=True)
51     subsub.active = context.show_shaded
52     subsub.prop(context, "shadetop")
53     subsub.prop(context, "shadedown")
54
55     col.separator()
56
57
58 def opengl_lamp_buttons(column, lamp):
59     split = column.split(percentage=0.1)
60
61     split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
62
63     col = split.column()
64     col.active = lamp.use
65     row = col.row()
66     row.label(text="Diffuse:")
67     row.prop(lamp, "diffuse_color", text="")
68     row = col.row()
69     row.label(text="Specular:")
70     row.prop(lamp, "specular_color", text="")
71
72     col = split.column()
73     col.active = lamp.use
74     col.prop(lamp, "direction", text="")
75
76
77 class USERPREF_HT_header(Header):
78     bl_space_type = 'USER_PREFERENCES'
79
80     def draw(self, context):
81         layout = self.layout
82         layout.template_header(menus=False)
83
84         userpref = context.user_preferences
85
86         layout.operator_context = 'EXEC_AREA'
87         layout.operator("wm.save_homefile", text="Save As Default")
88
89         layout.operator_context = 'INVOKE_DEFAULT'
90
91         if userpref.active_section == 'INPUT':
92             layout.operator("wm.keyconfig_export")
93             layout.operator("wm.keyconfig_import")
94         elif userpref.active_section == 'ADDONS':
95             layout.operator("wm.addon_install")
96             layout.menu("USERPREF_MT_addons_dev_guides")
97         elif userpref.active_section == 'THEMES':
98             layout.operator("ui.reset_default_theme")
99
100
101 class USERPREF_PT_tabs(Panel):
102     bl_label = ""
103     bl_space_type = 'USER_PREFERENCES'
104     bl_region_type = 'WINDOW'
105     bl_options = {'HIDE_HEADER'}
106
107     def draw(self, context):
108         layout = self.layout
109
110         userpref = context.user_preferences
111
112         layout.prop(userpref, "active_section", expand=True)
113
114
115 class USERPREF_MT_interaction_presets(Menu):
116     bl_label = "Presets"
117     preset_subdir = "interaction"
118     preset_operator = "script.execute_preset"
119     draw = Menu.draw_preset
120
121
122 class USERPREF_MT_appconfigs(Menu):
123     bl_label = "AppPresets"
124     preset_subdir = "keyconfig"
125     preset_operator = "wm.appconfig_activate"
126
127     def draw(self, context):
128         self.layout.operator("wm.appconfig_default", text="Blender (default)")
129
130         # now draw the presets
131         Menu.draw_preset(self, context)
132
133
134 class USERPREF_MT_splash(Menu):
135     bl_label = "Splash"
136
137     def draw(self, context):
138         layout = self.layout
139         split = layout.split()
140         row = split.row()
141         row.label("")
142         row = split.row()
143         row.label("Interaction:")
144         # XXX, no redraws
145         # text = bpy.path.display_name(context.window_manager.keyconfigs.active.name)
146         # if not text:
147         #     text = "Blender (default)"
148         row.menu("USERPREF_MT_appconfigs", text="Preset")
149
150
151 class USERPREF_PT_interface(Panel):
152     bl_space_type = 'USER_PREFERENCES'
153     bl_label = "Interface"
154     bl_region_type = 'WINDOW'
155     bl_options = {'HIDE_HEADER'}
156
157     @classmethod
158     def poll(cls, context):
159         userpref = context.user_preferences
160         return (userpref.active_section == 'INTERFACE')
161
162     def draw(self, context):
163         layout = self.layout
164
165         userpref = context.user_preferences
166         view = userpref.view
167
168         row = layout.row()
169
170         col = row.column()
171         col.label(text="Display:")
172         col.prop(view, "show_tooltips")
173         col.prop(view, "show_tooltips_python")
174         col.prop(view, "show_object_info", text="Object Info")
175         col.prop(view, "show_large_cursors")
176         col.prop(view, "show_view_name", text="View Name")
177         col.prop(view, "show_playback_fps", text="Playback FPS")
178         col.prop(view, "use_global_scene")
179         col.prop(view, "object_origin_size")
180
181         col.separator()
182         col.separator()
183         col.separator()
184
185         col.prop(view, "show_mini_axis", text="Display Mini Axis")
186         sub = col.column()
187         sub.active = view.show_mini_axis
188         sub.prop(view, "mini_axis_size", text="Size")
189         sub.prop(view, "mini_axis_brightness", text="Brightness")
190
191         col.separator()
192         row.separator()
193         row.separator()
194
195         col = row.column()
196         col.label(text="View Manipulation:")
197         col.prop(view, "use_mouse_auto_depth")
198         col.prop(view, "use_zoom_to_mouse")
199         col.prop(view, "use_rotate_around_active")
200         col.prop(view, "use_global_pivot")
201         col.prop(view, "use_camera_lock_parent")
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(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(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         # 2. Column
419         column = split.column()
420         colsplit = column.split(percentage=0.85)
421
422         col = colsplit.column()
423         col.label(text="OpenGL:")
424         col.prop(system, "gl_clip_alpha", slider=True)
425         col.prop(system, "use_mipmaps")
426         col.label(text="Anisotropic Filtering")
427         col.prop(system, "anisotropic_filter", text="")
428         col.prop(system, "use_vertex_buffer_objects")
429         # Anti-aliasing is disabled as it breaks border/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
469         column.label(text="Color Picker Type:")
470         column.row().prop(system, "color_picker_type", text="")
471
472         column.separator()
473
474         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
475         sub = column.column()
476         sub.active = system.use_weight_color_range
477         sub.template_color_ramp(system, "weight_color_range", expand=True)
478
479         column.separator()
480
481         column.prop(system, "use_international_fonts")
482         if system.use_international_fonts:
483             column.prop(system, "language")
484             row = column.row()
485             row.label(text="Translate:")
486             row.prop(system, "use_translate_interface", text="Interface")
487             row.prop(system, "use_translate_tooltips", text="Tooltips")
488
489
490 class USERPREF_PT_theme(Panel):
491     bl_space_type = 'USER_PREFERENCES'
492     bl_label = "Themes"
493     bl_region_type = 'WINDOW'
494     bl_options = {'HIDE_HEADER'}
495
496     @staticmethod
497     def _theme_generic(split, themedata):
498
499         row = split.row()
500
501         subsplit = row.split(percentage=0.95)
502
503         padding1 = subsplit.split(percentage=0.15)
504         padding1.column()
505
506         subsplit = row.split(percentage=0.85)
507
508         padding2 = subsplit.split(percentage=0.15)
509         padding2.column()
510
511         colsub_pair = padding1.column(), padding2.column()
512
513         props_type = {}
514
515         for i, prop in enumerate(themedata.rna_type.properties):
516             attr = prop.identifier
517             if attr == "rna_type":
518                 continue
519
520             props_type.setdefault((prop.type, prop.subtype), []).append(prop.identifier)
521
522         for props_type, props_ls in sorted(props_type.items()):
523             for i, attr in enumerate(props_ls):
524                 colsub_pair[i % 2].row().prop(themedata, attr)
525
526     @classmethod
527     def poll(cls, context):
528         userpref = context.user_preferences
529         return (userpref.active_section == 'THEMES')
530
531     def draw(self, context):
532         layout = self.layout
533
534         theme = context.user_preferences.themes[0]
535
536         split_themes = layout.split(percentage=0.2)
537         split_themes.prop(theme, "theme_area", expand=True)
538
539         split = layout.split(percentage=0.4)
540
541         layout.separator()
542         layout.separator()
543
544         split = split_themes.split()
545
546         if theme.theme_area == 'USER_INTERFACE':
547             col = split.column()
548
549             ui = theme.user_interface.wcol_regular
550             col.label(text="Regular:")
551             ui_items_general(col, ui)
552
553             ui = theme.user_interface.wcol_tool
554             col.label(text="Tool:")
555             ui_items_general(col, ui)
556
557             ui = theme.user_interface.wcol_radio
558             col.label(text="Radio Buttons:")
559             ui_items_general(col, ui)
560
561             ui = theme.user_interface.wcol_text
562             col.label(text="Text:")
563             ui_items_general(col, ui)
564
565             ui = theme.user_interface.wcol_option
566             col.label(text="Option:")
567             ui_items_general(col, ui)
568
569             ui = theme.user_interface.wcol_toggle
570             col.label(text="Toggle:")
571             ui_items_general(col, ui)
572
573             ui = theme.user_interface.wcol_num
574             col.label(text="Number Field:")
575             ui_items_general(col, ui)
576
577             ui = theme.user_interface.wcol_numslider
578             col.label(text="Value Slider:")
579             ui_items_general(col, ui)
580
581             ui = theme.user_interface.wcol_box
582             col.label(text="Box:")
583             ui_items_general(col, ui)
584
585             ui = theme.user_interface.wcol_menu
586             col.label(text="Menu:")
587             ui_items_general(col, ui)
588
589             ui = theme.user_interface.wcol_pulldown
590             col.label(text="Pulldown:")
591             ui_items_general(col, ui)
592
593             ui = theme.user_interface.wcol_menu_back
594             col.label(text="Menu Back:")
595             ui_items_general(col, ui)
596
597             ui = theme.user_interface.wcol_menu_item
598             col.label(text="Menu Item:")
599             ui_items_general(col, ui)
600
601             ui = theme.user_interface.wcol_scroll
602             col.label(text="Scroll Bar:")
603             ui_items_general(col, ui)
604
605             ui = theme.user_interface.wcol_progress
606             col.label(text="Progress Bar:")
607             ui_items_general(col, ui)
608
609             ui = theme.user_interface.wcol_list_item
610             col.label(text="List Item:")
611             ui_items_general(col, ui)
612
613             ui = theme.user_interface.wcol_state
614             col.label(text="State:")
615
616             row = col.row()
617
618             subsplit = row.split(percentage=0.95)
619
620             padding = subsplit.split(percentage=0.15)
621             colsub = padding.column()
622             colsub = padding.column()
623             colsub.row().prop(ui, "inner_anim")
624             colsub.row().prop(ui, "inner_anim_sel")
625             colsub.row().prop(ui, "inner_driven")
626             colsub.row().prop(ui, "inner_driven_sel")
627
628             subsplit = row.split(percentage=0.85)
629
630             padding = subsplit.split(percentage=0.15)
631             colsub = padding.column()
632             colsub = padding.column()
633             colsub.row().prop(ui, "inner_key")
634             colsub.row().prop(ui, "inner_key_sel")
635             colsub.row().prop(ui, "blend")
636
637             ui = theme.user_interface
638             col.separator()
639             col.separator()
640
641             split = col.split(percentage=0.93)
642             split.prop(ui, "icon_file")
643
644             layout.separator()
645             layout.separator()
646         elif theme.theme_area == 'BONE_COLOR_SETS':
647             col = split.column()
648
649             for i, ui in enumerate(theme.bone_color_sets):
650                 col.label(text="Color Set" + " %d:" % (i + 1))  # i starts from 0
651
652                 row = col.row()
653
654                 subsplit = row.split(percentage=0.95)
655
656                 padding = subsplit.split(percentage=0.15)
657                 colsub = padding.column()
658                 colsub = padding.column()
659                 colsub.row().prop(ui, "normal")
660                 colsub.row().prop(ui, "select")
661                 colsub.row().prop(ui, "active")
662
663                 subsplit = row.split(percentage=0.85)
664
665                 padding = subsplit.split(percentage=0.15)
666                 colsub = padding.column()
667                 colsub = padding.column()
668                 colsub.row().prop(ui, "show_colored_constraints")
669         else:
670             self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
671
672
673 class USERPREF_PT_file(Panel):
674     bl_space_type = 'USER_PREFERENCES'
675     bl_label = "Files"
676     bl_region_type = 'WINDOW'
677     bl_options = {'HIDE_HEADER'}
678
679     @classmethod
680     def poll(cls, context):
681         userpref = context.user_preferences
682         return (userpref.active_section == 'FILES')
683
684     def draw(self, context):
685         layout = self.layout
686
687         userpref = context.user_preferences
688         paths = userpref.filepaths
689
690         split = layout.split(percentage=0.7)
691
692         col = split.column()
693         col.label(text="File Paths:")
694
695         colsplit = col.split(percentage=0.95)
696         col1 = colsplit.split(percentage=0.3)
697
698         sub = col1.column()
699         sub.label(text="Fonts:")
700         sub.label(text="Textures:")
701         sub.label(text="Texture Plugins:")
702         sub.label(text="Sequence Plugins:")
703         sub.label(text="Render Output:")
704         sub.label(text="Scripts:")
705         sub.label(text="Sounds:")
706         sub.label(text="Temp:")
707         sub.label(text="Image Editor:")
708         sub.label(text="Animation Player:")
709
710         sub = col1.column()
711         sub.prop(paths, "font_directory", text="")
712         sub.prop(paths, "texture_directory", text="")
713         sub.prop(paths, "texture_plugin_directory", text="")
714         sub.prop(paths, "sequence_plugin_directory", text="")
715         sub.prop(paths, "render_output_directory", text="")
716         sub.prop(paths, "script_directory", text="")
717         sub.prop(paths, "sound_directory", text="")
718         sub.prop(paths, "temporary_directory", text="")
719         sub.prop(paths, "image_editor", text="")
720         subsplit = sub.split(percentage=0.3)
721         subsplit.prop(paths, "animation_player_preset", text="")
722         subsplit.prop(paths, "animation_player", text="")
723
724         col = split.column()
725         col.label(text="Save & Load:")
726         col.prop(paths, "use_relative_paths")
727         col.prop(paths, "use_file_compression")
728         col.prop(paths, "use_load_ui")
729         col.prop(paths, "use_filter_files")
730         col.prop(paths, "show_hidden_files_datablocks")
731         col.prop(paths, "hide_recent_locations")
732         col.prop(paths, "show_thumbnails")
733
734         col.separator()
735         col.separator()
736
737         col.prop(paths, "save_version")
738         col.prop(paths, "recent_files")
739         col.prop(paths, "use_save_preview_images")
740         col.label(text="Auto Save:")
741         col.prop(paths, "use_auto_save_temporary_files")
742         sub = col.column()
743         sub.active = paths.use_auto_save_temporary_files
744         sub.prop(paths, "auto_save_time", text="Timer (mins)")
745
746 from bl_ui.space_userpref_keymap import InputKeyMapPanel
747
748
749 class USERPREF_MT_ndof_settings(Menu):
750     # accessed from the window keybindings in C (only)
751     bl_label = "3D Mouse Settings"
752
753     def draw(self, context):
754         layout = self.layout
755         input_prefs = context.user_preferences.inputs
756
757         layout.separator()
758         layout.prop(input_prefs, "ndof_sensitivity")
759
760         if context.space_data.type == 'VIEW_3D':
761             layout.separator()
762             layout.prop(input_prefs, "ndof_show_guide")
763
764             layout.separator()
765             layout.label(text="Orbit options")
766             if input_prefs.view_rotate_method == 'TRACKBALL':
767                 layout.prop(input_prefs, "ndof_roll_invert_axis")
768                 layout.prop(input_prefs, "ndof_tilt_invert_axis")
769                 layout.prop(input_prefs, "ndof_rotate_invert_axis")
770             else:
771                 layout.prop(input_prefs, "ndof_orbit_invert_axes")
772
773             layout.separator()
774             layout.label(text="Pan options")
775             layout.prop(input_prefs, "ndof_panx_invert_axis")
776             layout.prop(input_prefs, "ndof_pany_invert_axis")
777             layout.prop(input_prefs, "ndof_panz_invert_axis")
778
779             layout.separator()
780             layout.label(text="Fly options")
781             layout.prop(input_prefs, "ndof_fly_helicopter", icon='NDOF_FLY')
782             layout.prop(input_prefs, "ndof_lock_horizon", icon='NDOF_DOM')
783
784
785 class USERPREF_PT_input(Panel, InputKeyMapPanel):
786     bl_space_type = 'USER_PREFERENCES'
787     bl_label = "Input"
788
789     @classmethod
790     def poll(cls, context):
791         userpref = context.user_preferences
792         return (userpref.active_section == 'INPUT')
793
794     def draw_input_prefs(self, inputs, layout):
795         # General settings
796         row = layout.row()
797         col = row.column()
798
799         sub = col.column()
800         sub.label(text="Presets:")
801         subrow = sub.row(align=True)
802
803         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
804         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
805         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
806         sub.separator()
807
808         sub.label(text="Mouse:")
809         sub1 = sub.column()
810         sub1.active = (inputs.select_mouse == 'RIGHT')
811         sub1.prop(inputs, "use_mouse_emulate_3_button")
812         sub.prop(inputs, "use_mouse_continuous")
813         sub.prop(inputs, "drag_threshold")
814
815         sub.label(text="Select With:")
816         sub.row().prop(inputs, "select_mouse", expand=True)
817
818         sub = col.column()
819         sub.label(text="Double Click:")
820         sub.prop(inputs, "mouse_double_click_time", text="Speed")
821
822         sub.separator()
823
824         sub.prop(inputs, "use_emulate_numpad")
825
826         sub.separator()
827
828         sub.label(text="Orbit Style:")
829         sub.row().prop(inputs, "view_rotate_method", expand=True)
830
831         sub.label(text="Zoom Style:")
832         sub.row().prop(inputs, "view_zoom_method", text="")
833         if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
834             sub.row().prop(inputs, "view_zoom_axis", expand=True)
835             sub.prop(inputs, "invert_mouse_zoom")
836
837         #sub.prop(inputs, "use_mouse_mmb_paste")
838
839         #col.separator()
840
841         sub = col.column()
842         sub.label(text="Mouse Wheel:")
843         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
844         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
845
846         col.separator()
847         sub = col.column()
848         sub.label(text="NDOF Device:")
849         sub.prop(inputs, "ndof_sensitivity", text="NDOF Sensitivity")
850
851         row.separator()
852
853     def draw(self, context):
854         layout = self.layout
855
856         #import time
857
858         #start = time.time()
859
860         userpref = context.user_preferences
861
862         inputs = userpref.inputs
863
864         split = layout.split(percentage=0.25)
865
866         # Input settings
867         self.draw_input_prefs(inputs, split)
868
869         # Keymap Settings
870         self.draw_keymaps(context, split)
871
872         #print("runtime", time.time() - start)
873
874
875 class USERPREF_MT_addons_dev_guides(Menu):
876     bl_label = "Development Guides"
877
878     # menu to open webpages with addons development guides
879     def draw(self, context):
880         layout = self.layout
881         layout.operator("wm.url_open", text="API Concepts", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro"
882         layout.operator("wm.url_open", text="Addon Guidelines", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons"
883         layout.operator("wm.url_open", text="How to share your addon", icon='URL').url = "http://wiki.blender.org/index.php/Dev:Py/Sharing"
884
885
886 class USERPREF_PT_addons(Panel):
887     bl_space_type = 'USER_PREFERENCES'
888     bl_label = "Addons"
889     bl_region_type = 'WINDOW'
890     bl_options = {'HIDE_HEADER'}
891
892     @classmethod
893     def poll(cls, context):
894         userpref = context.user_preferences
895         return (userpref.active_section == 'ADDONS')
896
897     @staticmethod
898     def is_user_addon(mod, user_addon_paths):
899         if not user_addon_paths:
900             user_script_path = bpy.utils.user_script_path()
901             if user_script_path is not None:
902                 user_addon_paths.append(os.path.join(user_script_path, "addons"))
903             user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons"))
904
905         for path in user_addon_paths:
906             if bpy.path.is_subdir(mod.__file__, path):
907                 return True
908         return False
909
910     @staticmethod
911     def draw_error(layout, message):
912         lines = message.split("\n")
913         box = layout.box()
914         rowsub = box.row()
915         rowsub.label(lines[0])
916         rowsub.label(icon='ERROR')
917         for l in lines[1:]:
918             box.label(l)
919
920     def draw(self, context):
921         layout = self.layout
922
923         userpref = context.user_preferences
924         used_ext = {ext.module for ext in userpref.addons}
925
926         # collect the categories that can be filtered on
927         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(addon_utils.addons_fake_modules)]
928
929         split = layout.split(percentage=0.2)
930         col = split.column()
931         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
932         col.label(text="Categories")
933         col.prop(context.window_manager, "addon_filter", expand=True)
934
935         col.label(text="Supported Level")
936         col.prop(context.window_manager, "addon_support", expand=True)
937
938         col = split.column()
939
940         # set in addon_utils.modules(...)
941         if addon_utils.error_duplicates:
942             self.draw_error(col,
943                             "Multiple addons using the same name found!\n"
944                             "likely a problem with the script search path.\n"
945                             "(see console for details)",
946                             )
947
948         if addon_utils.error_encoding:
949             self.draw_error(col,
950                             "One or more addons do not have UTF-8 encoding\n"
951                             "(see console for details)",
952                             )
953
954         filter = context.window_manager.addon_filter
955         search = context.window_manager.addon_search.lower()
956         support = context.window_manager.addon_support
957
958         # initialized on demand
959         user_addon_paths = []
960
961         for mod, info in addons:
962             module_name = mod.__name__
963
964             is_enabled = module_name in used_ext
965
966             if info["support"] not in support:
967                 continue
968
969             # check if addon should be visible with current filters
970             if ((filter == "All") or
971                 (filter == info["category"]) or
972                 (filter == "Enabled" and is_enabled) or
973                 (filter == "Disabled" and not is_enabled)):
974
975                 if search and search not in info["name"].lower():
976                     if info["author"]:
977                         if search not in info["author"].lower():
978                             continue
979                     else:
980                         continue
981
982                 # Addon UI Code
983                 box = col.column().box()
984                 colsub = box.column()
985                 row = colsub.row()
986
987                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
988
989                 rowsub = row.row()
990                 rowsub.active = is_enabled
991                 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
992                 if info["warning"]:
993                     rowsub.label(icon='ERROR')
994
995                 # icon showing support level.
996                 if info["support"] == 'OFFICIAL':
997                     rowsub.label(icon='FILE_BLEND')
998                 elif info["support"] == 'COMMUNITY':
999                     rowsub.label(icon='POSE_DATA')
1000                 else:
1001                     rowsub.label(icon='QUESTION')
1002
1003                 if is_enabled:
1004                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1005                 else:
1006                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
1007
1008                 # Expanded UI (only if additional infos are available)
1009                 if info["show_expanded"]:
1010                     if info["description"]:
1011                         split = colsub.row().split(percentage=0.15)
1012                         split.label(text="Description:")
1013                         split.label(text=info["description"])
1014                     if info["location"]:
1015                         split = colsub.row().split(percentage=0.15)
1016                         split.label(text="Location:")
1017                         split.label(text=info["location"])
1018                     if info["author"]:
1019                         split = colsub.row().split(percentage=0.15)
1020                         split.label(text="Author:")
1021                         split.label(text=info["author"])
1022                     if info["version"]:
1023                         split = colsub.row().split(percentage=0.15)
1024                         split.label(text="Version:")
1025                         split.label(text='.'.join(str(x) for x in info["version"]))
1026                     if info["warning"]:
1027                         split = colsub.row().split(percentage=0.15)
1028                         split.label(text="Warning:")
1029                         split.label(text='  ' + info["warning"], icon='ERROR')
1030
1031                     user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
1032                     tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)
1033
1034                     if tot_row:
1035                         split = colsub.row().split(percentage=0.15)
1036                         split.label(text="Internet:")
1037                         if info["wiki_url"]:
1038                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
1039                         if info["tracker_url"]:
1040                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
1041                         if user_addon:
1042                             split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__
1043
1044                         for i in range(4 - tot_row):
1045                             split.separator()
1046
1047         # Append missing scripts
1048         # First collect scripts that are used but have no script file.
1049         module_names = {mod.__name__ for mod, info in addons}
1050         missing_modules = {ext for ext in used_ext if ext not in module_names}
1051
1052         if missing_modules and filter in {"All", "Enabled"}:
1053             col.column().separator()
1054             col.column().label(text="Missing script files")
1055
1056             module_names = {mod.__name__ for mod, info in addons}
1057             for module_name in sorted(missing_modules):
1058                 is_enabled = module_name in used_ext
1059                 # Addon UI Code
1060                 box = col.column().box()
1061                 colsub = box.column()
1062                 row = colsub.row()
1063
1064                 row.label(text=module_name, icon='ERROR')
1065
1066                 if is_enabled:
1067                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1068
1069 if __name__ == "__main__":  # only for live edit.
1070     bpy.utils.register_module(__name__)