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