1 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17 # ##### END GPL LICENSE BLOCK #####
24 from bpy.props import StringProperty, BoolProperty, EnumProperty
25 from blf import gettext as _
27 def ui_items_general(col, context):
28 """ General UI Theme Settings (User Interface)
33 subsplit = row.split(percentage=0.95)
35 padding = subsplit.split(percentage=0.15)
36 colsub = padding.column()
37 colsub = padding.column()
38 colsub.row().prop(context, "outline")
39 colsub.row().prop(context, "item", slider=True)
40 colsub.row().prop(context, "inner", slider=True)
41 colsub.row().prop(context, "inner_sel", slider=True)
43 subsplit = row.split(percentage=0.85)
45 padding = subsplit.split(percentage=0.15)
46 colsub = padding.column()
47 colsub = padding.column()
48 colsub.row().prop(context, "text")
49 colsub.row().prop(context, "text_sel")
50 colsub.prop(context, "show_shaded")
51 subsub = colsub.column(align=True)
52 subsub.active = context.show_shaded
53 subsub.prop(context, "shadetop")
54 subsub.prop(context, "shadedown")
59 def opengl_lamp_buttons(column, lamp):
60 split = column.split(percentage=0.1)
62 split.prop(lamp, "use", text="", icon='OUTLINER_OB_LAMP' if lamp.use else 'LAMP_DATA')
67 row.label(text="Diffuse:")
68 row.prop(lamp, "diffuse_color", text="")
70 row.label(text="Specular:")
71 row.prop(lamp, "specular_color", text="")
75 col.prop(lamp, "direction", text="")
78 class USERPREF_HT_header(bpy.types.Header):
79 bl_space_type = 'USER_PREFERENCES'
81 def draw(self, context):
83 layout.template_header(menus=False)
85 userpref = context.user_preferences
87 layout.operator_context = 'EXEC_AREA'
88 layout.operator("wm.save_homefile", text="Save As Default")
90 layout.operator_context = 'INVOKE_DEFAULT'
92 if userpref.active_section == 'INPUT':
93 layout.operator("wm.keyconfig_export")
94 layout.operator("wm.keyconfig_import")
95 elif userpref.active_section == 'ADDONS':
96 layout.operator("wm.addon_install")
97 layout.menu("USERPREF_MT_addons_dev_guides", text=" Addons Developer Guides", icon='INFO')
98 elif userpref.active_section == 'THEMES':
99 layout.operator("ui.reset_default_theme")
102 class USERPREF_PT_tabs(bpy.types.Panel):
104 bl_space_type = 'USER_PREFERENCES'
105 bl_region_type = 'WINDOW'
106 bl_options = {'HIDE_HEADER'}
108 def draw(self, context):
111 userpref = context.user_preferences
113 layout.prop(userpref, "active_section", expand=True)
116 class USERPREF_MT_interaction_presets(bpy.types.Menu):
118 preset_subdir = "interaction"
119 preset_operator = "script.execute_preset"
120 draw = bpy.types.Menu.draw_preset
123 class USERPREF_MT_appconfigs(bpy.types.Menu):
124 bl_label = "AppPresets"
125 preset_subdir = "keyconfig"
126 preset_operator = "wm.appconfig_activate"
128 def draw(self, context):
129 props = self.layout.operator("wm.appconfig_default", text=_("Blender (default)"))
131 # now draw the presets
132 bpy.types.Menu.draw_preset(self, context)
135 class USERPREF_MT_splash(bpy.types.Menu):
138 def draw(self, context):
140 split = layout.split()
144 row.label(_("Interaction:"))
146 # text = bpy.path.display_name(context.window_manager.keyconfigs.active.name)
148 # text = "Blender (default)"
149 row.menu("USERPREF_MT_appconfigs", text=_("Preset"))
152 class USERPREF_PT_interface(bpy.types.Panel):
153 bl_space_type = 'USER_PREFERENCES'
154 bl_label = "Interface"
155 bl_region_type = 'WINDOW'
156 bl_options = {'HIDE_HEADER'}
159 def poll(cls, context):
160 userpref = context.user_preferences
161 return (userpref.active_section == 'INTERFACE')
163 def draw(self, context):
166 userpref = context.user_preferences
172 col.label(text="Display:")
173 col.prop(view, "show_tooltips")
174 col.prop(view, "show_tooltips_python")
175 col.prop(view, "show_object_info", text="Object Info")
176 col.prop(view, "show_large_cursors")
177 col.prop(view, "show_view_name", text="View Name")
178 col.prop(view, "show_playback_fps", text="Playback FPS")
179 col.prop(view, "use_global_scene")
180 col.prop(view, "object_origin_size")
186 col.prop(view, "show_mini_axis", text="Display Mini Axis")
188 sub.active = view.show_mini_axis
189 sub.prop(view, "mini_axis_size", text="Size")
190 sub.prop(view, "mini_axis_brightness", text="Brightness")
197 col.label(text="View Manipulation:")
198 col.prop(view, "use_mouse_auto_depth")
199 col.prop(view, "use_zoom_to_mouse")
200 col.prop(view, "use_rotate_around_active")
201 col.prop(view, "use_global_pivot")
202 col.prop(view, "use_camera_lock_parent")
206 col.prop(view, "use_auto_perspective")
207 col.prop(view, "smooth_view")
208 col.prop(view, "rotation_angle")
213 col.label(text="2D Viewports:")
214 col.prop(view, "view2d_grid_spacing_min", text="Minimum Grid Spacing")
215 col.prop(view, "timecode_style")
221 #Toolbox doesn't exist yet
222 #col.label(text="Toolbox:")
223 #col.prop(view, "show_column_layout")
224 #col.label(text="Open Toolbox Delay:")
225 #col.prop(view, "open_left_mouse_delay", text="Hold LMB")
226 #col.prop(view, "open_right_mouse_delay", text="Hold RMB")
227 col.prop(view, "show_manipulator")
229 sub.active = view.show_manipulator
230 sub.prop(view, "manipulator_size", text="Size")
231 sub.prop(view, "manipulator_handle_size", text="Handle Size")
232 sub.prop(view, "manipulator_hotspot", text="Hotspot")
238 col.label(text="Menus:")
239 col.prop(view, "use_mouse_over_open")
240 col.label(text="Menu Open Delay:")
241 col.prop(view, "open_toplevel_delay", text="Top Level")
242 col.prop(view, "open_sublevel_delay", text="Sub Level")
246 col.prop(view, "show_splash")
249 class USERPREF_PT_edit(bpy.types.Panel):
250 bl_space_type = 'USER_PREFERENCES'
252 bl_region_type = 'WINDOW'
253 bl_options = {'HIDE_HEADER'}
256 def poll(cls, context):
257 userpref = context.user_preferences
258 return (userpref.active_section == 'EDITING')
260 def draw(self, context):
263 userpref = context.user_preferences
269 col.label(text="Link Materials To:")
270 col.prop(edit, "material_link", text="")
276 col.label(text="New Objects:")
277 col.prop(edit, "use_enter_edit_mode")
278 col.label(text="Align To:")
279 col.prop(edit, "object_align", text="")
285 col.label(text="Undo:")
286 col.prop(edit, "use_global_undo")
287 col.prop(edit, "undo_steps", text="Steps")
288 col.prop(edit, "undo_memory_limit", text="Memory Limit")
294 col.label(text="Grease Pencil:")
295 col.prop(edit, "grease_pencil_manhattan_distance", text="Manhattan Distance")
296 col.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
297 #col.prop(edit, "use_grease_pencil_simplify_stroke", text="Simplify Stroke")
298 col.prop(edit, "grease_pencil_eraser_radius", text="Eraser Radius")
299 col.prop(edit, "use_grease_pencil_smooth_stroke", text="Smooth Stroke")
303 col.label(text="Playback:")
304 col.prop(edit, "use_negative_frames")
310 col.label(text="Keyframing:")
311 col.prop(edit, "use_visual_keying")
312 col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
316 col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
320 # sub.active = edit.use_keyframe_insert_auto # incorrect, timeline can enable
321 sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
325 col.label(text="New F-Curve Defaults:")
326 col.prop(edit, "keyframe_new_interpolation_type", text="Interpolation")
327 col.prop(edit, "keyframe_new_handle_type", text="Handles")
328 col.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
334 col.label(text="Transform:")
335 col.prop(edit, "use_drag_immediately")
341 col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
347 col.label(text="Duplicate Data:")
348 col.prop(edit, "use_duplicate_mesh", text="Mesh")
349 col.prop(edit, "use_duplicate_surface", text="Surface")
350 col.prop(edit, "use_duplicate_curve", text="Curve")
351 col.prop(edit, "use_duplicate_text", text="Text")
352 col.prop(edit, "use_duplicate_metaball", text="Metaball")
353 col.prop(edit, "use_duplicate_armature", text="Armature")
354 col.prop(edit, "use_duplicate_lamp", text="Lamp")
355 col.prop(edit, "use_duplicate_material", text="Material")
356 col.prop(edit, "use_duplicate_texture", text="Texture")
357 #col.prop(edit, "use_duplicate_fcurve", text="F-Curve")
358 col.prop(edit, "use_duplicate_action", text="Action")
359 col.prop(edit, "use_duplicate_particle", text="Particle")
362 class USERPREF_PT_system(bpy.types.Panel):
363 bl_space_type = 'USER_PREFERENCES'
365 bl_region_type = 'WINDOW'
366 bl_options = {'HIDE_HEADER'}
369 def poll(cls, context):
370 userpref = context.user_preferences
371 return (userpref.active_section == 'SYSTEM')
373 def draw(self, context):
376 userpref = context.user_preferences
377 system = userpref.system
379 split = layout.split()
382 column = split.column()
383 colsplit = column.split(percentage=0.85)
385 col = colsplit.column()
386 col.label(text="General:")
387 col.prop(system, "dpi")
388 col.prop(system, "frame_server_port")
389 col.prop(system, "scrollback", text="Console Scrollback")
390 col.prop(system, "author", text="Author")
391 col.prop(system, "use_scripts_auto_execute")
392 col.prop(system, "use_tabs_as_spaces")
398 col.label(text="Sound:")
399 col.row().prop(system, "audio_device", expand=True)
401 sub.active = system.audio_device != 'NONE'
402 #sub.prop(system, "use_preview_images")
403 sub.prop(system, "audio_channels", text="Channels")
404 sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
405 sub.prop(system, "audio_sample_rate", text="Sample Rate")
406 sub.prop(system, "audio_sample_format", text="Sample Format")
412 col.label(text="Screencast:")
413 col.prop(system, "screencast_fps")
414 col.prop(system, "screencast_wait_time")
419 #column = split.column()
420 #colsplit = column.split(percentage=0.85)
422 # No translation in 2.5 yet
423 #col.prop(system, "language")
424 #col.label(text="Translate:")
425 #col.prop(system, "use_translate_tooltips", text="Tooltips")
426 #col.prop(system, "use_translate_buttons", text="Labels")
427 #col.prop(system, "use_translate_toolbox", text="Toolbox")
431 #col.prop(system, "use_textured_fonts")
434 column = split.column()
435 colsplit = column.split(percentage=0.85)
437 col = colsplit.column()
438 col.label(text="OpenGL:")
439 col.prop(system, "gl_clip_alpha", slider=True)
440 col.prop(system, "use_mipmaps")
441 col.prop(system, "use_vertex_buffer_objects")
442 #Anti-aliasing is disabled as it breaks broder/lasso select
443 #col.prop(system, "use_antialiasing")
444 col.label(text="Window Draw Method:")
445 col.prop(system, "window_draw_method", text="")
446 col.label(text="Text Draw Options:")
447 col.prop(system, "use_text_antialiasing")
448 col.label(text="Textures:")
449 col.prop(system, "gl_texture_limit", text="Limit Size")
450 col.prop(system, "texture_time_out", text="Time Out")
451 col.prop(system, "texture_collection_rate", text="Collection Rate")
457 col.label(text="Sequencer:")
458 col.prop(system, "prefetch_frames")
459 col.prop(system, "memory_cache_limit")
462 column = split.column()
464 column.label(text="Solid OpenGL lights:")
466 split = column.split(percentage=0.1)
468 split.label(text="Colors:")
469 split.label(text="Direction:")
471 lamp = system.solid_lights[0]
472 opengl_lamp_buttons(column, lamp)
474 lamp = system.solid_lights[1]
475 opengl_lamp_buttons(column, lamp)
477 lamp = system.solid_lights[2]
478 opengl_lamp_buttons(column, lamp)
484 column.label(text="Color Picker Type:")
485 column.row().prop(system, "color_picker_type", text="")
491 column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
492 sub = column.column()
493 sub.active = system.use_weight_color_range
494 sub.template_color_ramp(system, "weight_color_range", expand=True)
497 class USERPREF_PT_theme(bpy.types.Panel):
498 bl_space_type = 'USER_PREFERENCES'
500 bl_region_type = 'WINDOW'
501 bl_options = {'HIDE_HEADER'}
504 def _theme_generic(split, themedata):
508 subsplit = row.split(percentage=0.95)
510 padding1 = subsplit.split(percentage=0.15)
513 subsplit = row.split(percentage=0.85)
515 padding2 = subsplit.split(percentage=0.15)
518 colsub_pair = padding1.column(), padding2.column()
522 for i, prop in enumerate(themedata.rna_type.properties):
523 attr = prop.identifier
524 if attr == "rna_type":
527 props_type.setdefault((prop.type, prop.subtype), []).append(prop.identifier)
529 for props_type, props_ls in sorted(props_type.items()):
530 for i, attr in enumerate(props_ls):
531 colsub_pair[i % 2].row().prop(themedata, attr)
534 def poll(cls, context):
535 userpref = context.user_preferences
536 return (userpref.active_section == 'THEMES')
538 def draw(self, context):
541 theme = context.user_preferences.themes[0]
543 split_themes = layout.split(percentage=0.2)
544 split_themes.prop(theme, "theme_area", expand=True)
546 split = layout.split(percentage=0.4)
551 split = split_themes.split()
553 if theme.theme_area == 'USER_INTERFACE':
556 ui = theme.user_interface.wcol_regular
557 col.label(text="Regular:")
558 ui_items_general(col, ui)
560 ui = theme.user_interface.wcol_tool
561 col.label(text="Tool:")
562 ui_items_general(col, ui)
564 ui = theme.user_interface.wcol_radio
565 col.label(text="Radio Buttons:")
566 ui_items_general(col, ui)
568 ui = theme.user_interface.wcol_text
569 col.label(text="Text:")
570 ui_items_general(col, ui)
572 ui = theme.user_interface.wcol_option
573 col.label(text="Option:")
574 ui_items_general(col, ui)
576 ui = theme.user_interface.wcol_toggle
577 col.label(text="Toggle:")
578 ui_items_general(col, ui)
580 ui = theme.user_interface.wcol_num
581 col.label(text="Number Field:")
582 ui_items_general(col, ui)
584 ui = theme.user_interface.wcol_numslider
585 col.label(text="Value Slider:")
586 ui_items_general(col, ui)
588 ui = theme.user_interface.wcol_box
589 col.label(text="Box:")
590 ui_items_general(col, ui)
592 ui = theme.user_interface.wcol_menu
593 col.label(text="Menu:")
594 ui_items_general(col, ui)
596 ui = theme.user_interface.wcol_pulldown
597 col.label(text="Pulldown:")
598 ui_items_general(col, ui)
600 ui = theme.user_interface.wcol_menu_back
601 col.label(text="Menu Back:")
602 ui_items_general(col, ui)
604 ui = theme.user_interface.wcol_menu_item
605 col.label(text="Menu Item:")
606 ui_items_general(col, ui)
608 ui = theme.user_interface.wcol_scroll
609 col.label(text="Scroll Bar:")
610 ui_items_general(col, ui)
612 ui = theme.user_interface.wcol_progress
613 col.label(text="Progress Bar:")
614 ui_items_general(col, ui)
616 ui = theme.user_interface.wcol_list_item
617 col.label(text="List Item:")
618 ui_items_general(col, ui)
620 ui = theme.user_interface.wcol_state
621 col.label(text="State:")
625 subsplit = row.split(percentage=0.95)
627 padding = subsplit.split(percentage=0.15)
628 colsub = padding.column()
629 colsub = padding.column()
630 colsub.row().prop(ui, "inner_anim")
631 colsub.row().prop(ui, "inner_anim_sel")
632 colsub.row().prop(ui, "inner_driven")
633 colsub.row().prop(ui, "inner_driven_sel")
635 subsplit = row.split(percentage=0.85)
637 padding = subsplit.split(percentage=0.15)
638 colsub = padding.column()
639 colsub = padding.column()
640 colsub.row().prop(ui, "inner_key")
641 colsub.row().prop(ui, "inner_key_sel")
642 colsub.row().prop(ui, "blend")
644 ui = theme.user_interface
648 split = col.split(percentage=0.93)
649 split.prop(ui, "icon_file")
653 elif theme.theme_area == 'BONE_COLOR_SETS':
656 for i, ui in enumerate(theme.bone_color_sets):
657 col.label(text="Color Set %d:" % (i + 1)) # i starts from 0
661 subsplit = row.split(percentage=0.95)
663 padding = subsplit.split(percentage=0.15)
664 colsub = padding.column()
665 colsub = padding.column()
666 colsub.row().prop(ui, "normal")
667 colsub.row().prop(ui, "select")
668 colsub.row().prop(ui, "active")
670 subsplit = row.split(percentage=0.85)
672 padding = subsplit.split(percentage=0.15)
673 colsub = padding.column()
674 colsub = padding.column()
675 colsub.row().prop(ui, "show_colored_constraints")
677 self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
680 class USERPREF_PT_file(bpy.types.Panel):
681 bl_space_type = 'USER_PREFERENCES'
683 bl_region_type = 'WINDOW'
684 bl_options = {'HIDE_HEADER'}
687 def poll(cls, context):
688 userpref = context.user_preferences
689 return (userpref.active_section == 'FILES')
691 def draw(self, context):
694 userpref = context.user_preferences
695 paths = userpref.filepaths
697 split = layout.split(percentage=0.7)
700 col.label(text="File Paths:")
702 colsplit = col.split(percentage=0.95)
703 col1 = colsplit.split(percentage=0.3)
706 sub.label(text="Fonts:")
707 sub.label(text="Textures:")
708 sub.label(text="Texture Plugins:")
709 sub.label(text="Sequence Plugins:")
710 sub.label(text="Render Output:")
711 sub.label(text="Scripts:")
712 sub.label(text="Sounds:")
713 sub.label(text="Temp:")
714 sub.label(text="Image Editor:")
715 sub.label(text="Animation Player:")
718 sub.prop(paths, "font_directory", text="")
719 sub.prop(paths, "texture_directory", text="")
720 sub.prop(paths, "texture_plugin_directory", text="")
721 sub.prop(paths, "sequence_plugin_directory", text="")
722 sub.prop(paths, "render_output_directory", text="")
723 sub.prop(paths, "script_directory", text="")
724 sub.prop(paths, "sound_directory", text="")
725 sub.prop(paths, "temporary_directory", text="")
726 sub.prop(paths, "image_editor", text="")
727 subsplit = sub.split(percentage=0.3)
728 subsplit.prop(paths, "animation_player_preset", text="")
729 subsplit.prop(paths, "animation_player", text="")
732 col.label(text="Save & Load:")
733 col.prop(paths, "use_relative_paths")
734 col.prop(paths, "use_file_compression")
735 col.prop(paths, "use_load_ui")
736 col.prop(paths, "use_filter_files")
737 col.prop(paths, "show_hidden_files_datablocks")
738 col.prop(paths, "hide_recent_locations")
739 col.prop(paths, "show_thumbnails")
744 col.prop(paths, "save_version")
745 col.prop(paths, "recent_files")
746 col.prop(paths, "use_save_preview_images")
747 col.label(text="Auto Save:")
748 col.prop(paths, "use_auto_save_temporary_files")
750 sub.active = paths.use_auto_save_temporary_files
751 sub.prop(paths, "auto_save_time", text="Timer (mins)")
753 from bl_ui.space_userpref_keymap import InputKeyMapPanel
756 class USERPREF_PT_input(bpy.types.Panel, InputKeyMapPanel):
757 bl_space_type = 'USER_PREFERENCES'
761 def poll(cls, context):
762 userpref = context.user_preferences
763 return (userpref.active_section == 'INPUT')
765 def draw_input_prefs(self, inputs, layout):
771 sub.label(text="Presets:")
772 subrow = sub.row(align=True)
774 subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
775 subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
776 subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
779 sub.label(text="Mouse:")
781 sub1.active = (inputs.select_mouse == 'RIGHT')
782 sub1.prop(inputs, "use_mouse_emulate_3_button")
783 sub.prop(inputs, "use_mouse_continuous")
784 sub.prop(inputs, "drag_threshold")
786 sub.label(text="Select With:")
787 sub.row().prop(inputs, "select_mouse", expand=True)
790 sub.label(text="Double Click:")
791 sub.prop(inputs, "mouse_double_click_time", text="Speed")
795 sub.prop(inputs, "use_emulate_numpad")
799 sub.label(text="Orbit Style:")
800 sub.row().prop(inputs, "view_rotate_method", expand=True)
802 sub.label(text="Zoom Style:")
803 sub.row().prop(inputs, "view_zoom_method", text="")
804 if inputs.view_zoom_method in {'DOLLY', 'CONTINUE'}:
805 sub.row().prop(inputs, "view_zoom_axis", expand=True)
806 sub.prop(inputs, "invert_mouse_zoom")
808 #sub.prop(inputs, "use_mouse_mmb_paste")
813 sub.label(text="Mouse Wheel:")
814 sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
815 #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
818 ''' not implemented yet
820 sub.label(text="NDOF Device:")
821 sub.prop(inputs, "ndof_pan_speed", text="Pan Speed")
822 sub.prop(inputs, "ndof_rotate_speed", text="Orbit Speed")
827 def draw(self, context):
834 userpref = context.user_preferences
836 inputs = userpref.inputs
838 split = layout.split(percentage=0.25)
841 self.draw_input_prefs(inputs, split)
844 self.draw_keymaps(context, split)
846 #print("runtime", time.time() - start)
849 class USERPREF_MT_addons_dev_guides(bpy.types.Menu):
850 bl_label = "Addons develoment guides"
852 # menu to open webpages with addons development guides
853 def draw(self, context):
855 layout.operator('wm.url_open', text='API Concepts'
856 ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro'
857 layout.operator('wm.url_open', text='Addons guidelines',
858 ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons'
859 layout.operator('wm.url_open', text='How to share your addon',
860 ).url = 'http://wiki.blender.org/index.php/Dev:Py/Sharing'
863 class USERPREF_PT_addons(bpy.types.Panel):
864 bl_space_type = 'USER_PREFERENCES'
866 bl_region_type = 'WINDOW'
867 bl_options = {'HIDE_HEADER'}
869 _addons_fake_modules = {}
872 def poll(cls, context):
873 userpref = context.user_preferences
874 return (userpref.active_section == 'ADDONS')
877 def module_get(mod_name):
878 return USERPREF_PT_addons._addons_fake_modules[mod_name]
880 def draw(self, context):
883 userpref = context.user_preferences
884 used_ext = {ext.module for ext in userpref.addons}
886 # collect the categories that can be filtered on
887 addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)]
889 split = layout.split(percentage=0.2)
891 col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
892 col.label(text="Categories")
893 col.prop(context.window_manager, "addon_filter", text="") # , expand=True, too slow with dynamic enum.
895 col.label(text="Supported Level")
896 col.prop(context.window_manager, "addon_support", expand=True)
900 filter = context.window_manager.addon_filter
901 search = context.window_manager.addon_search.lower()
902 support = context.window_manager.addon_support
904 for mod, info in addons:
905 module_name = mod.__name__
907 is_enabled = module_name in used_ext
909 if info["support"] not in support:
912 # check if add-on should be visible with current filters
913 if (filter == "All") or \
914 (filter == info["category"]) or \
915 (filter == "Enabled" and is_enabled) or \
916 (filter == "Disabled" and not is_enabled):
918 if search and search not in info["name"].lower():
920 if search not in info["author"].lower():
926 box = col.column().box()
927 colsub = box.column()
930 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
933 rowsub.active = is_enabled
934 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
936 rowsub.label(icon='ERROR')
938 # icon showing support level.
939 if info["support"] == 'OFFICIAL':
940 rowsub.label(icon='FILE_BLEND')
941 elif info["support"] == 'COMMUNITY':
942 rowsub.label(icon='POSE_DATA')
944 rowsub.label(icon='QUESTION')
947 row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
949 row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
951 # Expanded UI (only if additional infos are available)
952 if info["show_expanded"]:
953 if info["description"]:
954 split = colsub.row().split(percentage=0.15)
955 split.label(text='Description:')
956 split.label(text=info["description"])
958 split = colsub.row().split(percentage=0.15)
959 split.label(text='Location:')
960 split.label(text=info["location"])
962 split = colsub.row().split(percentage=0.15)
963 split.label(text='Author:')
964 split.label(text=info["author"])
966 split = colsub.row().split(percentage=0.15)
967 split.label(text='Version:')
968 split.label(text='.'.join(str(x) for x in info["version"]))
970 split = colsub.row().split(percentage=0.15)
971 split.label(text="Warning:")
972 split.label(text=' ' + info["warning"], icon='ERROR')
973 if info["wiki_url"] or info["tracker_url"]:
974 split = colsub.row().split(percentage=0.15)
975 split.label(text="Internet:")
977 split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
978 if info["tracker_url"]:
979 split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
981 if info["wiki_url"] and info["tracker_url"]:
987 # Append missing scripts
988 # First collect scripts that are used but have no script file.
989 module_names = {mod.__name__ for mod, info in addons}
990 missing_modules = {ext for ext in used_ext if ext not in module_names}
992 if missing_modules and filter in {"All", "Enabled"}:
993 col.column().separator()
994 col.column().label(text="Missing script files")
996 module_names = {mod.__name__ for mod, info in addons}
997 for module_name in sorted(missing_modules):
998 is_enabled = module_name in used_ext
1000 box = col.column().box()
1001 colsub = box.column()
1004 row.label(text=module_name, icon='ERROR')
1007 row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1010 class WM_OT_addon_enable(bpy.types.Operator):
1012 bl_idname = "wm.addon_enable"
1013 bl_label = "Enable Add-On"
1015 module = StringProperty(name="Module", description="Module name of the addon to enable")
1017 def execute(self, context):
1018 mod = addon_utils.enable(self.module)
1021 # check if add-on is written for current blender version, or raise a warning
1022 info = addon_utils.module_bl_info(mod)
1024 if info.get("blender", (0, 0, 0)) > bpy.app.version:
1025 self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
1028 return {'CANCELLED'}
1031 class WM_OT_addon_disable(bpy.types.Operator):
1033 bl_idname = "wm.addon_disable"
1034 bl_label = "Disable Add-On"
1036 module = StringProperty(name="Module", description="Module name of the addon to disable")
1038 def execute(self, context):
1039 addon_utils.disable(self.module)
1043 class WM_OT_addon_install(bpy.types.Operator):
1045 bl_idname = "wm.addon_install"
1046 bl_label = "Install Add-On..."
1048 overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True)
1049 target = EnumProperty(
1051 items=(('DEFAULT', "Default", ""),
1052 ('PREFS', "User Prefs", "")))
1054 filepath = StringProperty(name="File Path", description="File path to write file to")
1055 filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
1056 filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
1057 filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'})
1060 def _module_remove(path_addons, module):
1061 module = os.path.splitext(module)[0]
1062 for f in os.listdir(path_addons):
1063 f_base = os.path.splitext(f)[0]
1064 if f_base == module:
1065 f_full = os.path.join(path_addons, f)
1067 if os.path.isdir(f_full):
1072 def execute(self, context):
1077 pyfile = self.filepath
1079 if self.target == 'DEFAULT':
1080 # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
1081 path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
1083 path_addons = bpy.context.user_preferences.filepaths.script_directory
1085 path_addons = os.path.join(path_addons, "addons")
1088 self.report({'ERROR'}, "Failed to get addons path")
1089 return {'CANCELLED'}
1091 # create dir is if missing.
1092 if not os.path.exists(path_addons):
1093 os.makedirs(path_addons)
1095 # Check if we are installing from a target path,
1096 # doing so causes 2+ addons of same name or when the same from/to
1097 # location is used, removal of the file!
1099 pyfile_dir = os.path.dirname(pyfile)
1100 for addon_path in addon_utils.paths():
1101 if os.path.samefile(pyfile_dir, addon_path):
1102 self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
1103 return {'CANCELLED'}
1106 # done checking for exceptional case
1108 addon_files_old = set(os.listdir(path_addons))
1109 addons_old = {mod.__name__ for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)}
1111 #check to see if the file is in compressed format (.zip)
1112 if zipfile.is_zipfile(pyfile):
1114 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1116 traceback.print_exc()
1117 return {'CANCELLED'}
1120 for f in file_to_extract.namelist():
1121 __class__._module_remove(path_addons, f)
1123 for f in file_to_extract.namelist():
1124 path_dest = os.path.join(path_addons, os.path.basename(f))
1125 if os.path.exists(path_dest):
1126 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1127 return {'CANCELLED'}
1129 try: # extract the file to "addons"
1130 file_to_extract.extractall(path_addons)
1132 # zip files can create this dir with metadata, don't need it
1133 macosx_dir = os.path.join(path_addons, '__MACOSX')
1134 if os.path.isdir(macosx_dir):
1135 shutil.rmtree(macosx_dir)
1138 traceback.print_exc()
1139 return {'CANCELLED'}
1142 path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1145 __class__._module_remove(path_addons, os.path.basename(pyfile))
1146 elif os.path.exists(path_dest):
1147 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1148 return {'CANCELLED'}
1150 #if not compressed file just copy into the addon path
1152 shutil.copyfile(pyfile, path_dest)
1155 traceback.print_exc()
1156 return {'CANCELLED'}
1158 addons_new = {mod.__name__ for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)} - addons_old
1159 addons_new.discard("modules")
1161 # disable any addons we may have enabled previously and removed.
1162 # this is unlikely but do just incase. bug [#23978]
1163 for new_addon in addons_new:
1164 addon_utils.disable(new_addon)
1166 # possible the zip contains multiple addons, we could disallow this
1167 # but for now just use the first
1168 for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1169 if mod.__name__ in addons_new:
1170 info = addon_utils.module_bl_info(mod)
1172 # show the newly installed addon.
1173 context.window_manager.addon_filter = 'All'
1174 context.window_manager.addon_search = info["name"]
1177 # incase a new module path was created to install this addon.
1178 bpy.utils.refresh_script_paths()
1180 # TODO, should not be a warning.
1181 # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1184 def invoke(self, context, event):
1185 wm = context.window_manager
1186 wm.fileselect_add(self)
1187 return {'RUNNING_MODAL'}
1190 class WM_OT_addon_expand(bpy.types.Operator):
1191 "Display more information on this add-on"
1192 bl_idname = "wm.addon_expand"
1195 module = StringProperty(name="Module", description="Module name of the addon to expand")
1197 def execute(self, context):
1198 module_name = self.module
1200 # unlikely to fail, module should have already been imported
1202 # mod = __import__(module_name)
1203 mod = USERPREF_PT_addons.module_get(module_name)
1206 traceback.print_exc()
1207 return {'CANCELLED'}
1209 info = addon_utils.module_bl_info(mod)
1210 info["show_expanded"] = not info["show_expanded"]
1213 if __name__ == "__main__": # only for live edit.
1214 bpy.utils.register_module(__name__)