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