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