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