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