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