svn merge ^/trunk/blender -r43934:43976
[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
248 class USERPREF_PT_edit(Panel):
249     bl_space_type = 'USER_PREFERENCES'
250     bl_label = "Edit"
251     bl_region_type = 'WINDOW'
252     bl_options = {'HIDE_HEADER'}
253
254     @classmethod
255     def poll(cls, context):
256         userpref = context.user_preferences
257         return (userpref.active_section == 'EDITING')
258
259     def draw(self, context):
260         layout = self.layout
261
262         userpref = context.user_preferences
263         edit = userpref.edit
264
265         row = layout.row()
266
267         col = row.column()
268         col.label(text="Link Materials To:")
269         col.prop(edit, "material_link", text="")
270
271         col.separator()
272         col.separator()
273         col.separator()
274
275         col.label(text="New Objects:")
276         col.prop(edit, "use_enter_edit_mode")
277         col.label(text="Align To:")
278         col.prop(edit, "object_align", text="")
279
280         col.separator()
281         col.separator()
282         col.separator()
283
284         col.label(text="Undo:")
285         col.prop(edit, "use_global_undo")
286         col.prop(edit, "undo_steps", text="Steps")
287         col.prop(edit, "undo_memory_limit", text="Memory Limit")
288
289         row.separator()
290         row.separator()
291
292         col = row.column()
293         col.label(text="Grease Pencil:")
294         col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
295         col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
296         #~ col.prop(edit, "use_grease_pencil_simplify_stroke", text="Simplify Stroke")
297         col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
298         col.prop(edit, "use_grease_pencil_smooth_stroke", text="Smooth Stroke")
299         col.separator()
300         col.separator()
301         col.separator()
302         col.label(text="Playback:")
303         col.prop(edit, "use_negative_frames")
304
305         row.separator()
306         row.separator()
307
308         col = row.column()
309         col.label(text="Keyframing:")
310         col.prop(edit, "use_visual_keying")
311         col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
312
313         col.separator()
314
315         col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
316
317         sub = col.column()
318
319         #~ sub.active = edit.use_keyframe_insert_auto # incorrect, time-line can enable
320         sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
321
322         col.separator()
323
324         col.label(text="New F-Curve Defaults:")
325         col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
326         col.prop(edit, "keyframe_new_handle_type", text="Handles")
327         col.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
328
329         col.separator()
330         col.separator()
331         col.separator()
332
333         col.label(text="Transform:")
334         col.prop(edit, "use_drag_immediately")
335
336         row.separator()
337         row.separator()
338
339         col = row.column()
340         col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
341
342         col.separator()
343         col.separator()
344         col.separator()
345
346         col.label(text="Duplicate Data:")
347         col.prop(edit, "use_duplicate_mesh", text="Mesh")
348         col.prop(edit, "use_duplicate_surface", text="Surface")
349         col.prop(edit, "use_duplicate_curve", text="Curve")
350         col.prop(edit, "use_duplicate_text", text="Text")
351         col.prop(edit, "use_duplicate_metaball", text="Metaball")
352         col.prop(edit, "use_duplicate_armature", text="Armature")
353         col.prop(edit, "use_duplicate_lamp", text="Lamp")
354         col.prop(edit, "use_duplicate_material", text="Material")
355         col.prop(edit, "use_duplicate_texture", text="Texture")
356         #col.prop(edit, "use_duplicate_fcurve", text="F-Curve")
357         col.prop(edit, "use_duplicate_action", text="Action")
358         col.prop(edit, "use_duplicate_particle", text="Particle")
359
360
361 class USERPREF_PT_system(Panel):
362     bl_space_type = 'USER_PREFERENCES'
363     bl_label = "System"
364     bl_region_type = 'WINDOW'
365     bl_options = {'HIDE_HEADER'}
366
367     @classmethod
368     def poll(cls, context):
369         userpref = context.user_preferences
370         return (userpref.active_section == 'SYSTEM')
371
372     def draw(self, context):
373         layout = self.layout
374
375         userpref = context.user_preferences
376         system = userpref.system
377
378         split = layout.split()
379
380         # 1. Column
381         column = split.column()
382         colsplit = column.split(percentage=0.85)
383
384         col = colsplit.column()
385         col.label(text="General:")
386         col.prop(system, "dpi")
387         col.prop(system, "frame_server_port")
388         col.prop(system, "scrollback", text="Console Scrollback")
389
390         col.separator()
391         col.separator()
392
393         col.label(text="Sound:")
394         col.row().prop(system, "audio_device", expand=True)
395         sub = col.column()
396         sub.active = system.audio_device != 'NONE'
397         #sub.prop(system, "use_preview_images")
398         sub.prop(system, "audio_channels", text="Channels")
399         sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
400         sub.prop(system, "audio_sample_rate", text="Sample Rate")
401         sub.prop(system, "audio_sample_format", text="Sample Format")
402
403         col.separator()
404         col.separator()
405
406         col.label(text="Screencast:")
407         col.prop(system, "screencast_fps")
408         col.prop(system, "screencast_wait_time")
409
410         col.separator()
411         col.separator()
412
413         if hasattr(system, 'compute_device'):
414             col.label(text="Compute Device:")
415             col.row().prop(system, "compute_device_type", expand=True)
416             sub = col.row()
417             sub.active = system.compute_device_type != 'CPU'
418             sub.prop(system, "compute_device", text="")
419
420         # 2. Column
421         column = split.column()
422         colsplit = column.split(percentage=0.85)
423
424         col = colsplit.column()
425         col.label(text="OpenGL:")
426         col.prop(system, "gl_clip_alpha", slider=True)
427         col.prop(system, "use_mipmaps")
428         col.prop(system, "use_16bit_textures")
429         col.label(text="Anisotropic Filtering")
430         col.prop(system, "anisotropic_filter", text="")
431         col.prop(system, "use_vertex_buffer_objects")
432         # Anti-aliasing is disabled as it breaks border/lasso select
433         #~ col.prop(system, "use_antialiasing")
434         col.label(text="Window Draw Method:")
435         col.prop(system, "window_draw_method", text="")
436         col.label(text="Text Draw Options:")
437         col.prop(system, "use_text_antialiasing")
438         col.label(text="Textures:")
439         col.prop(system, "gl_texture_limit", text="Limit Size")
440         col.prop(system, "texture_time_out", text="Time Out")
441         col.prop(system, "texture_collection_rate", text="Collection Rate")
442
443         col.separator()
444         col.separator()
445         col.separator()
446
447         col.label(text="Sequencer:")
448         col.prop(system, "prefetch_frames")
449         col.prop(system, "memory_cache_limit")
450
451         # 3. Column
452         column = split.column()
453
454         column.label(text="Solid OpenGL lights:")
455
456         split = column.split(percentage=0.1)
457         split.label()
458         split.label(text="Colors:")
459         split.label(text="Direction:")
460
461         lamp = system.solid_lights[0]
462         opengl_lamp_buttons(column, lamp)
463
464         lamp = system.solid_lights[1]
465         opengl_lamp_buttons(column, lamp)
466
467         lamp = system.solid_lights[2]
468         opengl_lamp_buttons(column, lamp)
469
470         column.separator()
471
472         column.label(text="Color Picker Type:")
473         column.row().prop(system, "color_picker_type", text="")
474
475         column.separator()
476
477         column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
478         sub = column.column()
479         sub.active = system.use_weight_color_range
480         sub.template_color_ramp(system, "weight_color_range", expand=True)
481
482         column.separator()
483
484         column.prop(system, "use_international_fonts")
485         if system.use_international_fonts:
486             column.prop(system, "language")
487             row = column.row()
488             row.label(text="Translate:")
489             row.prop(system, "use_translate_interface", text="Interface")
490             row.prop(system, "use_translate_tooltips", text="Tooltips")
491
492
493 class USERPREF_MT_interface_theme_presets(Menu):
494     bl_label = "Presets"
495     preset_subdir = "interface_theme"
496     preset_operator = "script.execute_preset"
497     preset_type = 'XML'
498     preset_xml_map = (("user_preferences.themes[0]", "Theme"), )
499     draw = Menu.draw_preset
500
501
502 class USERPREF_PT_theme(Panel):
503     bl_space_type = 'USER_PREFERENCES'
504     bl_label = "Themes"
505     bl_region_type = 'WINDOW'
506     bl_options = {'HIDE_HEADER'}
507
508     @staticmethod
509     def _theme_generic(split, themedata):
510
511         col = split.column()
512
513         def theme_generic_recurse(data):
514             col.label(data.rna_type.name)
515             row = col.row()
516             subsplit = row.split(percentage=0.95)
517
518             padding1 = subsplit.split(percentage=0.15)
519             padding1.column()
520
521             subsplit = row.split(percentage=0.85)
522
523             padding2 = subsplit.split(percentage=0.15)
524             padding2.column()
525
526             colsub_pair = padding1.column(), padding2.column()
527
528             props_type = {}
529
530             for i, prop in enumerate(data.rna_type.properties):
531                 if prop.identifier == "rna_type":
532                     continue
533
534                 props_type.setdefault((prop.type, prop.subtype), []).append(prop)
535
536             for props_type, props_ls in sorted(props_type.items()):
537                 if props_type[0] == 'POINTER':
538                     for i, prop in enumerate(props_ls):
539                         theme_generic_recurse(getattr(data, prop.identifier))
540                 else:
541                     for i, prop in enumerate(props_ls):
542                         colsub_pair[i % 2].row().prop(data, prop.identifier)
543
544         theme_generic_recurse(themedata)
545
546     @classmethod
547     def poll(cls, context):
548         userpref = context.user_preferences
549         return (userpref.active_section == 'THEMES')
550
551     def draw(self, context):
552         layout = self.layout
553
554         theme = context.user_preferences.themes[0]
555
556         split_themes = layout.split(percentage=0.2)
557
558         sub = split_themes.column()
559
560         sub.label(text="Presets:")
561         subrow = sub.row(align=True)
562
563         subrow.menu("USERPREF_MT_interface_theme_presets", text=USERPREF_MT_interface_theme_presets.bl_label)
564         subrow.operator("wm.interface_theme_preset_add", text="", icon='ZOOMIN')
565         subrow.operator("wm.interface_theme_preset_add", text="", icon='ZOOMOUT').remove_active = True
566         sub.separator()
567
568         sub.prop(theme, "theme_area", expand=True)
569
570         split = layout.split(percentage=0.4)
571
572         layout.separator()
573         layout.separator()
574
575         split = split_themes.split()
576
577         if theme.theme_area == 'USER_INTERFACE':
578             col = split.column()
579
580             ui = theme.user_interface.wcol_regular
581             col.label(text="Regular:")
582             ui_items_general(col, ui)
583
584             ui = theme.user_interface.wcol_tool
585             col.label(text="Tool:")
586             ui_items_general(col, ui)
587
588             ui = theme.user_interface.wcol_radio
589             col.label(text="Radio Buttons:")
590             ui_items_general(col, ui)
591
592             ui = theme.user_interface.wcol_text
593             col.label(text="Text:")
594             ui_items_general(col, ui)
595
596             ui = theme.user_interface.wcol_option
597             col.label(text="Option:")
598             ui_items_general(col, ui)
599
600             ui = theme.user_interface.wcol_toggle
601             col.label(text="Toggle:")
602             ui_items_general(col, ui)
603
604             ui = theme.user_interface.wcol_num
605             col.label(text="Number Field:")
606             ui_items_general(col, ui)
607
608             ui = theme.user_interface.wcol_numslider
609             col.label(text="Value Slider:")
610             ui_items_general(col, ui)
611
612             ui = theme.user_interface.wcol_box
613             col.label(text="Box:")
614             ui_items_general(col, ui)
615
616             ui = theme.user_interface.wcol_menu
617             col.label(text="Menu:")
618             ui_items_general(col, ui)
619
620             ui = theme.user_interface.wcol_pulldown
621             col.label(text="Pulldown:")
622             ui_items_general(col, ui)
623
624             ui = theme.user_interface.wcol_menu_back
625             col.label(text="Menu Back:")
626             ui_items_general(col, ui)
627
628             ui = theme.user_interface.wcol_menu_item
629             col.label(text="Menu Item:")
630             ui_items_general(col, ui)
631
632             ui = theme.user_interface.wcol_scroll
633             col.label(text="Scroll Bar:")
634             ui_items_general(col, ui)
635
636             ui = theme.user_interface.wcol_progress
637             col.label(text="Progress Bar:")
638             ui_items_general(col, ui)
639
640             ui = theme.user_interface.wcol_list_item
641             col.label(text="List Item:")
642             ui_items_general(col, ui)
643
644             ui = theme.user_interface.wcol_state
645             col.label(text="State:")
646
647             row = col.row()
648
649             subsplit = row.split(percentage=0.95)
650
651             padding = subsplit.split(percentage=0.15)
652             colsub = padding.column()
653             colsub = padding.column()
654             colsub.row().prop(ui, "inner_anim")
655             colsub.row().prop(ui, "inner_anim_sel")
656             colsub.row().prop(ui, "inner_driven")
657             colsub.row().prop(ui, "inner_driven_sel")
658
659             subsplit = row.split(percentage=0.85)
660
661             padding = subsplit.split(percentage=0.15)
662             colsub = padding.column()
663             colsub = padding.column()
664             colsub.row().prop(ui, "inner_key")
665             colsub.row().prop(ui, "inner_key_sel")
666             colsub.row().prop(ui, "blend")
667
668             col.separator()
669             col.separator()
670
671             ui = theme.user_interface
672             col.label("Icons:")
673
674             row = col.row()
675
676             subsplit = row.split(percentage=0.95)
677
678             padding = subsplit.split(percentage=0.15)
679             colsub = padding.column()
680             colsub = padding.column()
681             colsub.row().prop(ui, "icon_file")
682
683             subsplit = row.split(percentage=0.85)
684
685             padding = subsplit.split(percentage=0.15)
686             colsub = padding.column()
687             colsub = padding.column()
688             colsub.row().prop(ui, "icon_alpha")
689
690             col.separator()
691             col.separator()
692
693             ui = theme.user_interface.panel
694             col.label("Panels:")
695
696             row = col.row()
697
698             subsplit = row.split(percentage=0.95)
699
700             padding = subsplit.split(percentage=0.15)
701             colsub = padding.column()
702             colsub = padding.column()
703             rowsub = colsub.row()
704             rowsub.prop(ui, "show_header")
705             rowsub.label()
706
707             subsplit = row.split(percentage=0.85)
708
709             padding = subsplit.split(percentage=0.15)
710             colsub = padding.column()
711             colsub = padding.column()
712             colsub.row().prop(ui, "header")
713
714             layout.separator()
715             layout.separator()
716         elif theme.theme_area == 'BONE_COLOR_SETS':
717             col = split.column()
718
719             for i, ui in enumerate(theme.bone_color_sets):
720                 col.label(text="Color Set" + " %d:" % (i + 1))  # i starts from 0
721
722                 row = col.row()
723
724                 subsplit = row.split(percentage=0.95)
725
726                 padding = subsplit.split(percentage=0.15)
727                 colsub = padding.column()
728                 colsub = padding.column()
729                 colsub.row().prop(ui, "normal")
730                 colsub.row().prop(ui, "select")
731                 colsub.row().prop(ui, "active")
732
733                 subsplit = row.split(percentage=0.85)
734
735                 padding = subsplit.split(percentage=0.15)
736                 colsub = padding.column()
737                 colsub = padding.column()
738                 colsub.row().prop(ui, "show_colored_constraints")
739         else:
740             self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
741
742
743 class USERPREF_PT_file(Panel):
744     bl_space_type = 'USER_PREFERENCES'
745     bl_label = "Files"
746     bl_region_type = 'WINDOW'
747     bl_options = {'HIDE_HEADER'}
748
749     @classmethod
750     def poll(cls, context):
751         userpref = context.user_preferences
752         return (userpref.active_section == 'FILES')
753
754     def draw(self, context):
755         layout = self.layout
756
757         userpref = context.user_preferences
758         paths = userpref.filepaths
759         system = userpref.system
760
761         split = layout.split(percentage=0.7)
762
763         col = split.column()
764         col.label(text="File Paths:")
765
766         colsplit = col.split(percentage=0.95)
767         col1 = colsplit.split(percentage=0.3)
768
769         sub = col1.column()
770         sub.label(text="Fonts:")
771         sub.label(text="Textures:")
772         sub.label(text="Texture Plugins:")
773         sub.label(text="Sequence Plugins:")
774         sub.label(text="Render Output:")
775         sub.label(text="Scripts:")
776         sub.label(text="Sounds:")
777         sub.label(text="Temp:")
778         sub.label(text="Image Editor:")
779         sub.label(text="Animation Player:")
780
781         sub = col1.column()
782         sub.prop(paths, "font_directory", text="")
783         sub.prop(paths, "texture_directory", text="")
784         sub.prop(paths, "texture_plugin_directory", text="")
785         sub.prop(paths, "sequence_plugin_directory", text="")
786         sub.prop(paths, "render_output_directory", text="")
787         sub.prop(paths, "script_directory", text="")
788         sub.prop(paths, "sound_directory", text="")
789         sub.prop(paths, "temporary_directory", text="")
790         sub.prop(paths, "image_editor", text="")
791         subsplit = sub.split(percentage=0.3)
792         subsplit.prop(paths, "animation_player_preset", text="")
793         subsplit.prop(paths, "animation_player", text="")
794
795         col.separator()
796         col.separator()
797
798         colsplit = col.split(percentage=0.95)
799         sub = colsplit.column()
800         sub.label(text="Author:")
801         sub.prop(system, "author", text="")
802
803         col = split.column()
804         col.label(text="Save & Load:")
805         col.prop(paths, "use_relative_paths")
806         col.prop(paths, "use_file_compression")
807         col.prop(paths, "use_load_ui")
808         col.prop(paths, "use_filter_files")
809         col.prop(paths, "show_hidden_files_datablocks")
810         col.prop(paths, "hide_recent_locations")
811         col.prop(paths, "show_thumbnails")
812
813         col.separator()
814         col.separator()
815
816         col.prop(paths, "save_version")
817         col.prop(paths, "recent_files")
818         col.prop(paths, "use_save_preview_images")
819         col.label(text="Auto Save:")
820         col.prop(paths, "use_auto_save_temporary_files")
821         sub = col.column()
822         sub.active = paths.use_auto_save_temporary_files
823         sub.prop(paths, "auto_save_time", text="Timer (mins)")
824
825         col.separator()
826
827         col.label(text="Scripts:")
828         col.prop(system, "use_scripts_auto_execute")
829         col.prop(system, "use_tabs_as_spaces")
830
831
832 from .space_userpref_keymap import InputKeyMapPanel
833
834
835 class USERPREF_MT_ndof_settings(Menu):
836     # accessed from the window key-bindings in C (only)
837     bl_label = "3D Mouse Settings"
838
839     def draw(self, context):
840         layout = self.layout
841         input_prefs = context.user_preferences.inputs
842
843         layout.separator()
844         layout.prop(input_prefs, "ndof_sensitivity")
845
846         if context.space_data.type == 'VIEW_3D':
847             layout.separator()
848             layout.prop(input_prefs, "ndof_show_guide")
849
850             layout.separator()
851             layout.label(text="Orbit options")
852             if input_prefs.view_rotate_method == 'TRACKBALL':
853                 layout.prop(input_prefs, "ndof_roll_invert_axis")
854             layout.prop(input_prefs, "ndof_tilt_invert_axis")
855             layout.prop(input_prefs, "ndof_rotate_invert_axis")
856             layout.prop(input_prefs, "ndof_zoom_invert")
857
858             layout.separator()
859             layout.label(text="Pan options")
860             layout.prop(input_prefs, "ndof_panx_invert_axis")
861             layout.prop(input_prefs, "ndof_pany_invert_axis")
862             layout.prop(input_prefs, "ndof_panz_invert_axis")
863
864             layout.label(text="Zoom options")
865             layout.prop(input_prefs, "ndof_zoom_updown")
866
867             layout.separator()
868             layout.label(text="Fly options")
869             layout.prop(input_prefs, "ndof_fly_helicopter", icon='NDOF_FLY')
870             layout.prop(input_prefs, "ndof_lock_horizon", icon='NDOF_DOM')
871
872
873 class USERPREF_PT_input(Panel, InputKeyMapPanel):
874     bl_space_type = 'USER_PREFERENCES'
875     bl_label = "Input"
876
877     @classmethod
878     def poll(cls, context):
879         userpref = context.user_preferences
880         return (userpref.active_section == 'INPUT')
881
882     def draw_input_prefs(self, inputs, layout):
883         # General settings
884         row = layout.row()
885         col = row.column()
886
887         sub = col.column()
888         sub.label(text="Presets:")
889         subrow = sub.row(align=True)
890
891         subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
892         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
893         subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
894         sub.separator()
895
896         sub.label(text="Mouse:")
897         sub1 = sub.column()
898         sub1.active = (inputs.select_mouse == 'RIGHT')
899         sub1.prop(inputs, "use_mouse_emulate_3_button")
900         sub.prop(inputs, "use_mouse_continuous")
901         sub.prop(inputs, "drag_threshold")
902
903         sub.label(text="Select With:")
904         sub.row().prop(inputs, "select_mouse", expand=True)
905
906         sub = col.column()
907         sub.label(text="Double Click:")
908         sub.prop(inputs, "mouse_double_click_time", text="Speed")
909
910         sub.separator()
911
912         sub.prop(inputs, "use_emulate_numpad")
913
914         sub.separator()
915
916         sub.label(text="Orbit Style:")
917         sub.row().prop(inputs, "view_rotate_method", expand=True)
918
919         sub.label(text="Zoom Style:")
920         sub.row().prop(inputs, "view_zoom_method", text="")
921         if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
922             sub.row().prop(inputs, "view_zoom_axis", expand=True)
923             sub.prop(inputs, "invert_mouse_zoom")
924
925         #sub.prop(inputs, "use_mouse_mmb_paste")
926
927         #col.separator()
928
929         sub = col.column()
930         sub.label(text="Mouse Wheel:")
931         sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
932         #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
933
934         col.separator()
935         sub = col.column()
936         sub.label(text="NDOF Device:")
937         sub.prop(inputs, "ndof_sensitivity", text="NDOF Sensitivity")
938
939         col.prop(inputs, "tweak_threshold")
940
941         row.separator()
942
943     def draw(self, context):
944         layout = self.layout
945
946         #import time
947
948         #start = time.time()
949
950         userpref = context.user_preferences
951
952         inputs = userpref.inputs
953
954         split = layout.split(percentage=0.25)
955
956         # Input settings
957         self.draw_input_prefs(inputs, split)
958
959         # Keymap Settings
960         self.draw_keymaps(context, split)
961
962         #print("runtime", time.time() - start)
963
964
965 class USERPREF_MT_addons_dev_guides(Menu):
966     bl_label = "Development Guides"
967
968     # menu to open web-pages with addons development guides
969     def draw(self, context):
970         layout = self.layout
971         layout.operator("wm.url_open", text="API Concepts", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro"
972         layout.operator("wm.url_open", text="Addon Guidelines", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons"
973         layout.operator("wm.url_open", text="How to share your addon", icon='URL').url = "http://wiki.blender.org/index.php/Dev:Py/Sharing"
974
975
976 class USERPREF_PT_addons(Panel):
977     bl_space_type = 'USER_PREFERENCES'
978     bl_label = "Addons"
979     bl_region_type = 'WINDOW'
980     bl_options = {'HIDE_HEADER'}
981
982     _support_icon_mapping = {
983         'OFFICIAL': 'FILE_BLEND',
984         'COMMUNITY': 'POSE_DATA',
985         'TESTING': 'MOD_EXPLODE',
986         }
987
988     @classmethod
989     def poll(cls, context):
990         userpref = context.user_preferences
991         return (userpref.active_section == 'ADDONS')
992
993     @staticmethod
994     def is_user_addon(mod, user_addon_paths):
995         if not user_addon_paths:
996             user_script_path = bpy.utils.user_script_path()
997             if user_script_path is not None:
998                 user_addon_paths.append(os.path.join(user_script_path, "addons"))
999             user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons"))
1000
1001         for path in user_addon_paths:
1002             if bpy.path.is_subdir(mod.__file__, path):
1003                 return True
1004         return False
1005
1006     @staticmethod
1007     def draw_error(layout, message):
1008         lines = message.split("\n")
1009         box = layout.box()
1010         rowsub = box.row()
1011         rowsub.label(lines[0])
1012         rowsub.label(icon='ERROR')
1013         for l in lines[1:]:
1014             box.label(l)
1015
1016     def draw(self, context):
1017         layout = self.layout
1018
1019         userpref = context.user_preferences
1020         used_ext = {ext.module for ext in userpref.addons}
1021
1022         # collect the categories that can be filtered on
1023         addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(addon_utils.addons_fake_modules)]
1024
1025         split = layout.split(percentage=0.2)
1026         col = split.column()
1027         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
1028
1029         col.label(text="Supported Level")
1030         col.prop(context.window_manager, "addon_support", expand=True)
1031
1032         col.label(text="Categories")
1033         col.prop(context.window_manager, "addon_filter", expand=True)
1034
1035         col = split.column()
1036
1037         # set in addon_utils.modules(...)
1038         if addon_utils.error_duplicates:
1039             self.draw_error(col,
1040                             "Multiple addons using the same name found!\n"
1041                             "likely a problem with the script search path.\n"
1042                             "(see console for details)",
1043                             )
1044
1045         if addon_utils.error_encoding:
1046             self.draw_error(col,
1047                             "One or more addons do not have UTF-8 encoding\n"
1048                             "(see console for details)",
1049                             )
1050
1051         filter = context.window_manager.addon_filter
1052         search = context.window_manager.addon_search.lower()
1053         support = context.window_manager.addon_support
1054
1055         # initialized on demand
1056         user_addon_paths = []
1057
1058         for mod, info in addons:
1059             module_name = mod.__name__
1060
1061             is_enabled = module_name in used_ext
1062
1063             if info["support"] not in support:
1064                 continue
1065
1066             # check if addon should be visible with current filters
1067             if ((filter == "All") or
1068                 (filter == info["category"]) or
1069                 (filter == "Enabled" and is_enabled) or
1070                 (filter == "Disabled" and not is_enabled)):
1071
1072                 if search and search not in info["name"].lower():
1073                     if info["author"]:
1074                         if search not in info["author"].lower():
1075                             continue
1076                     else:
1077                         continue
1078
1079                 # Addon UI Code
1080                 box = col.column().box()
1081                 colsub = box.column()
1082                 row = colsub.row()
1083
1084                 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
1085
1086                 rowsub = row.row()
1087                 rowsub.active = is_enabled
1088                 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
1089                 if info["warning"]:
1090                     rowsub.label(icon='ERROR')
1091
1092                 # icon showing support level.
1093                 rowsub.label(icon=self._support_icon_mapping.get(info["support"], 'QUESTION'))
1094
1095                 if is_enabled:
1096                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1097                 else:
1098                     row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
1099
1100                 # Expanded UI (only if additional info is available)
1101                 if info["show_expanded"]:
1102                     if info["description"]:
1103                         split = colsub.row().split(percentage=0.15)
1104                         split.label(text="Description:")
1105                         split.label(text=info["description"])
1106                     if info["location"]:
1107                         split = colsub.row().split(percentage=0.15)
1108                         split.label(text="Location:")
1109                         split.label(text=info["location"])
1110                     if info["author"]:
1111                         split = colsub.row().split(percentage=0.15)
1112                         split.label(text="Author:")
1113                         split.label(text=info["author"])
1114                     if info["version"]:
1115                         split = colsub.row().split(percentage=0.15)
1116                         split.label(text="Version:")
1117                         split.label(text='.'.join(str(x) for x in info["version"]))
1118                     if info["warning"]:
1119                         split = colsub.row().split(percentage=0.15)
1120                         split.label(text="Warning:")
1121                         split.label(text='  ' + info["warning"], icon='ERROR')
1122
1123                     user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
1124                     tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)
1125
1126                     if tot_row:
1127                         split = colsub.row().split(percentage=0.15)
1128                         split.label(text="Internet:")
1129                         if info["wiki_url"]:
1130                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
1131                         if info["tracker_url"]:
1132                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
1133                         if user_addon:
1134                             split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__
1135
1136                         for i in range(4 - tot_row):
1137                             split.separator()
1138
1139         # Append missing scripts
1140         # First collect scripts that are used but have no script file.
1141         module_names = {mod.__name__ for mod, info in addons}
1142         missing_modules = {ext for ext in used_ext if ext not in module_names}
1143
1144         if missing_modules and filter in {"All", "Enabled"}:
1145             col.column().separator()
1146             col.column().label(text="Missing script files")
1147
1148             module_names = {mod.__name__ for mod, info in addons}
1149             for module_name in sorted(missing_modules):
1150                 is_enabled = module_name in used_ext
1151                 # Addon UI Code
1152                 box = col.column().box()
1153                 colsub = box.column()
1154                 row = colsub.row()
1155
1156                 row.label(text=module_name, icon='ERROR')
1157
1158                 if is_enabled:
1159                     row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1160
1161 if __name__ == "__main__":  # only for live edit.
1162     bpy.utils.register_module(__name__)