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
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")
205 col.prop(view, "use_auto_perspective")
206 col.prop(view, "smooth_view")
207 col.prop(view, "rotation_angle")
212 col.label(text="2D Viewports:")
213 col.prop(view, "view2d_grid_spacing_min", text="Minimum Grid Spacing")
214 col.prop(view, "timecode_style")
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")
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")
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")
245 col.prop(view, "show_splash")
248 class USERPREF_PT_edit(bpy.types.Panel):
249 bl_space_type = 'USER_PREFERENCES'
251 bl_region_type = 'WINDOW'
252 bl_options = {'HIDE_HEADER'}
255 def poll(cls, context):
256 userpref = context.user_preferences
257 return (userpref.active_section == 'EDITING')
259 def draw(self, context):
262 userpref = context.user_preferences
268 col.label(text="Link Materials To:")
269 col.prop(edit, "material_link", text="")
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="")
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")
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")
302 col.label(text="Playback:")
303 col.prop(edit, "use_negative_frames")
309 col.label(text="Keyframing:")
310 col.prop(edit, "use_visual_keying")
311 col.prop(edit, "use_keyframe_insert_needed", text="Only Insert Needed")
315 col.prop(edit, "use_auto_keying", text="Auto Keyframing:")
319 # sub.active = edit.use_keyframe_insert_auto # incorrect, timeline can enable
320 sub.prop(edit, "use_keyframe_insert_available", text="Only Insert Available")
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")
333 col.label(text="Transform:")
334 col.prop(edit, "use_drag_immediately")
340 col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
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")
361 class USERPREF_PT_system(bpy.types.Panel):
362 bl_space_type = 'USER_PREFERENCES'
364 bl_region_type = 'WINDOW'
365 bl_options = {'HIDE_HEADER'}
368 def poll(cls, context):
369 userpref = context.user_preferences
370 return (userpref.active_section == 'SYSTEM')
372 def draw(self, context):
375 userpref = context.user_preferences
376 system = userpref.system
378 split = layout.split()
381 column = split.column()
382 colsplit = column.split(percentage=0.85)
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 col.prop(system, "author", text="Author")
390 col.prop(system, "use_scripts_auto_execute")
391 col.prop(system, "use_tabs_as_spaces")
397 col.label(text="Sound:")
398 col.row().prop(system, "audio_device", expand=True)
400 sub.active = system.audio_device != 'NONE'
401 #sub.prop(system, "use_preview_images")
402 sub.prop(system, "audio_channels", text="Channels")
403 sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
404 sub.prop(system, "audio_sample_rate", text="Sample Rate")
405 sub.prop(system, "audio_sample_format", text="Sample Format")
411 col.label(text="Screencast:")
412 col.prop(system, "screencast_fps")
413 col.prop(system, "screencast_wait_time")
418 #column = split.column()
419 #colsplit = column.split(percentage=0.85)
421 # No translation in 2.5 yet
422 #col.prop(system, "language")
423 #col.label(text="Translate:")
424 #col.prop(system, "use_translate_tooltips", text="Tooltips")
425 #col.prop(system, "use_translate_buttons", text="Labels")
426 #col.prop(system, "use_translate_toolbox", text="Toolbox")
430 #col.prop(system, "use_textured_fonts")
433 column = split.column()
434 colsplit = column.split(percentage=0.85)
436 col = colsplit.column()
437 col.label(text="OpenGL:")
438 col.prop(system, "gl_clip_alpha", slider=True)
439 col.prop(system, "use_mipmaps")
440 col.prop(system, "use_vertex_buffer_objects")
441 #Anti-aliasing is disabled as it breaks broder/lasso select
442 #col.prop(system, "use_antialiasing")
443 col.label(text="Window Draw Method:")
444 col.prop(system, "window_draw_method", text="")
445 col.label(text="Text Draw Options:")
446 col.prop(system, "use_text_antialiasing")
447 col.label(text="Textures:")
448 col.prop(system, "gl_texture_limit", text="Limit Size")
449 col.prop(system, "texture_time_out", text="Time Out")
450 col.prop(system, "texture_collection_rate", text="Collection Rate")
456 col.label(text="Sequencer:")
457 col.prop(system, "prefetch_frames")
458 col.prop(system, "memory_cache_limit")
461 column = split.column()
463 column.label(text="Solid OpenGL lights:")
465 split = column.split(percentage=0.1)
467 split.label(text="Colors:")
468 split.label(text="Direction:")
470 lamp = system.solid_lights[0]
471 opengl_lamp_buttons(column, lamp)
473 lamp = system.solid_lights[1]
474 opengl_lamp_buttons(column, lamp)
476 lamp = system.solid_lights[2]
477 opengl_lamp_buttons(column, lamp)
483 column.label(text="Color Picker Type:")
484 column.row().prop(system, "color_picker_type", text="")
490 column.prop(system, "use_weight_color_range", text="Custom Weight Paint Range")
491 sub = column.column()
492 sub.active = system.use_weight_color_range
493 sub.template_color_ramp(system, "weight_color_range", expand=True)
496 class USERPREF_PT_theme(bpy.types.Panel):
497 bl_space_type = 'USER_PREFERENCES'
499 bl_region_type = 'WINDOW'
500 bl_options = {'HIDE_HEADER'}
503 def _theme_generic(split, themedata):
507 subsplit = row.split(percentage=0.95)
509 padding1 = subsplit.split(percentage=0.15)
512 subsplit = row.split(percentage=0.85)
514 padding2 = subsplit.split(percentage=0.15)
517 colsub_pair = padding1.column(), padding2.column()
521 for i, prop in enumerate(themedata.rna_type.properties):
522 attr = prop.identifier
523 if attr == "rna_type":
526 props_type.setdefault((prop.type, prop.subtype), []).append(prop.identifier)
528 for props_type, props_ls in sorted(props_type.items()):
529 for i, attr in enumerate(props_ls):
530 colsub_pair[i % 2].row().prop(themedata, attr)
533 def poll(cls, context):
534 userpref = context.user_preferences
535 return (userpref.active_section == 'THEMES')
537 def draw(self, context):
540 theme = context.user_preferences.themes[0]
542 split_themes = layout.split(percentage=0.2)
543 split_themes.prop(theme, "theme_area", expand=True)
545 split = layout.split(percentage=0.4)
550 split = split_themes.split()
552 if theme.theme_area == 'USER_INTERFACE':
555 ui = theme.user_interface.wcol_regular
556 col.label(text="Regular:")
557 ui_items_general(col, ui)
559 ui = theme.user_interface.wcol_tool
560 col.label(text="Tool:")
561 ui_items_general(col, ui)
563 ui = theme.user_interface.wcol_radio
564 col.label(text="Radio Buttons:")
565 ui_items_general(col, ui)
567 ui = theme.user_interface.wcol_text
568 col.label(text="Text:")
569 ui_items_general(col, ui)
571 ui = theme.user_interface.wcol_option
572 col.label(text="Option:")
573 ui_items_general(col, ui)
575 ui = theme.user_interface.wcol_toggle
576 col.label(text="Toggle:")
577 ui_items_general(col, ui)
579 ui = theme.user_interface.wcol_num
580 col.label(text="Number Field:")
581 ui_items_general(col, ui)
583 ui = theme.user_interface.wcol_numslider
584 col.label(text="Value Slider:")
585 ui_items_general(col, ui)
587 ui = theme.user_interface.wcol_box
588 col.label(text="Box:")
589 ui_items_general(col, ui)
591 ui = theme.user_interface.wcol_menu
592 col.label(text="Menu:")
593 ui_items_general(col, ui)
595 ui = theme.user_interface.wcol_pulldown
596 col.label(text="Pulldown:")
597 ui_items_general(col, ui)
599 ui = theme.user_interface.wcol_menu_back
600 col.label(text="Menu Back:")
601 ui_items_general(col, ui)
603 ui = theme.user_interface.wcol_menu_item
604 col.label(text="Menu Item:")
605 ui_items_general(col, ui)
607 ui = theme.user_interface.wcol_scroll
608 col.label(text="Scroll Bar:")
609 ui_items_general(col, ui)
611 ui = theme.user_interface.wcol_progress
612 col.label(text="Progress Bar:")
613 ui_items_general(col, ui)
615 ui = theme.user_interface.wcol_list_item
616 col.label(text="List Item:")
617 ui_items_general(col, ui)
619 ui = theme.user_interface.wcol_state
620 col.label(text="State:")
624 subsplit = row.split(percentage=0.95)
626 padding = subsplit.split(percentage=0.15)
627 colsub = padding.column()
628 colsub = padding.column()
629 colsub.row().prop(ui, "inner_anim")
630 colsub.row().prop(ui, "inner_anim_sel")
631 colsub.row().prop(ui, "inner_driven")
632 colsub.row().prop(ui, "inner_driven_sel")
634 subsplit = row.split(percentage=0.85)
636 padding = subsplit.split(percentage=0.15)
637 colsub = padding.column()
638 colsub = padding.column()
639 colsub.row().prop(ui, "inner_key")
640 colsub.row().prop(ui, "inner_key_sel")
641 colsub.row().prop(ui, "blend")
643 ui = theme.user_interface
647 split = col.split(percentage=0.93)
648 split.prop(ui, "icon_file")
652 elif theme.theme_area == 'BONE_COLOR_SETS':
655 for i, ui in enumerate(theme.bone_color_sets):
656 col.label(text="Color Set %d:" % (i + 1)) # i starts from 0
660 subsplit = row.split(percentage=0.95)
662 padding = subsplit.split(percentage=0.15)
663 colsub = padding.column()
664 colsub = padding.column()
665 colsub.row().prop(ui, "normal")
666 colsub.row().prop(ui, "select")
667 colsub.row().prop(ui, "active")
669 subsplit = row.split(percentage=0.85)
671 padding = subsplit.split(percentage=0.15)
672 colsub = padding.column()
673 colsub = padding.column()
674 colsub.row().prop(ui, "show_colored_constraints")
676 self._theme_generic(split, getattr(theme, theme.theme_area.lower()))
679 class USERPREF_PT_file(bpy.types.Panel):
680 bl_space_type = 'USER_PREFERENCES'
682 bl_region_type = 'WINDOW'
683 bl_options = {'HIDE_HEADER'}
686 def poll(cls, context):
687 userpref = context.user_preferences
688 return (userpref.active_section == 'FILES')
690 def draw(self, context):
693 userpref = context.user_preferences
694 paths = userpref.filepaths
696 split = layout.split(percentage=0.7)
699 col.label(text="File Paths:")
701 colsplit = col.split(percentage=0.95)
702 col1 = colsplit.split(percentage=0.3)
705 sub.label(text="Fonts:")
706 sub.label(text="Textures:")
707 sub.label(text="Texture Plugins:")
708 sub.label(text="Sequence Plugins:")
709 sub.label(text="Render Output:")
710 sub.label(text="Scripts:")
711 sub.label(text="Sounds:")
712 sub.label(text="Temp:")
713 sub.label(text="Image Editor:")
714 sub.label(text="Animation Player:")
717 sub.prop(paths, "font_directory", text="")
718 sub.prop(paths, "texture_directory", text="")
719 sub.prop(paths, "texture_plugin_directory", text="")
720 sub.prop(paths, "sequence_plugin_directory", text="")
721 sub.prop(paths, "render_output_directory", text="")
722 sub.prop(paths, "script_directory", text="")
723 sub.prop(paths, "sound_directory", text="")
724 sub.prop(paths, "temporary_directory", text="")
725 sub.prop(paths, "image_editor", text="")
726 subsplit = sub.split(percentage=0.3)
727 subsplit.prop(paths, "animation_player_preset", text="")
728 subsplit.prop(paths, "animation_player", text="")
731 col.label(text="Save & Load:")
732 col.prop(paths, "use_relative_paths")
733 col.prop(paths, "use_file_compression")
734 col.prop(paths, "use_load_ui")
735 col.prop(paths, "use_filter_files")
736 col.prop(paths, "show_hidden_files_datablocks")
737 col.prop(paths, "hide_recent_locations")
738 col.prop(paths, "show_thumbnails")
743 col.prop(paths, "save_version")
744 col.prop(paths, "recent_files")
745 col.prop(paths, "use_save_preview_images")
746 col.label(text="Auto Save:")
747 col.prop(paths, "use_auto_save_temporary_files")
749 sub.active = paths.use_auto_save_temporary_files
750 sub.prop(paths, "auto_save_time", text="Timer (mins)")
752 from bl_ui.space_userpref_keymap import InputKeyMapPanel
755 class USERPREF_PT_input(InputKeyMapPanel):
756 bl_space_type = 'USER_PREFERENCES'
760 def poll(cls, context):
761 userpref = context.user_preferences
762 return (userpref.active_section == 'INPUT')
764 def draw_input_prefs(self, inputs, layout):
770 sub.label(text="Presets:")
771 subrow = sub.row(align=True)
773 subrow.menu("USERPREF_MT_interaction_presets", text=bpy.types.USERPREF_MT_interaction_presets.bl_label)
774 subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMIN')
775 subrow.operator("wm.interaction_preset_add", text="", icon='ZOOMOUT').remove_active = True
778 sub.label(text="Mouse:")
780 sub1.active = (inputs.select_mouse == 'RIGHT')
781 sub1.prop(inputs, "use_mouse_emulate_3_button")
782 sub.prop(inputs, "use_mouse_continuous")
783 sub.prop(inputs, "drag_threshold")
785 sub.label(text="Select With:")
786 sub.row().prop(inputs, "select_mouse", expand=True)
789 sub.label(text="Double Click:")
790 sub.prop(inputs, "mouse_double_click_time", text="Speed")
794 sub.prop(inputs, "use_emulate_numpad")
798 sub.label(text="Orbit Style:")
799 sub.row().prop(inputs, "view_rotate_method", expand=True)
801 sub.label(text="Zoom Style:")
802 sub.row().prop(inputs, "view_zoom_method", text="")
803 if inputs.view_zoom_method == 'DOLLY':
804 sub.row().prop(inputs, "view_zoom_axis", expand=True)
805 sub.prop(inputs, "invert_mouse_wheel_zoom")
807 #sub.prop(inputs, "use_mouse_mmb_paste")
812 sub.label(text="Mouse Wheel:")
813 sub.prop(inputs, "invert_zoom_wheel", text="Invert Wheel Zoom Direction")
814 #sub.prop(view, "wheel_scroll_lines", text="Scroll Lines")
817 ''' not implemented yet
819 sub.label(text="NDOF Device:")
820 sub.prop(inputs, "ndof_pan_speed", text="Pan Speed")
821 sub.prop(inputs, "ndof_rotate_speed", text="Orbit Speed")
826 def draw(self, context):
833 userpref = context.user_preferences
835 inputs = userpref.inputs
837 split = layout.split(percentage=0.25)
840 self.draw_input_prefs(inputs, split)
843 self.draw_keymaps(context, split)
845 #print("runtime", time.time() - start)
848 class USERPREF_MT_addons_dev_guides(bpy.types.Menu):
849 bl_label = "Addons develoment guides"
851 # menu to open webpages with addons development guides
852 def draw(self, context):
854 layout.operator('wm.url_open', text='API Concepts'
855 ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro'
856 layout.operator('wm.url_open', text='Addons guidelines',
857 ).url = 'http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons'
858 layout.operator('wm.url_open', text='How to share your addon',
859 ).url = 'http://wiki.blender.org/index.php/Dev:Py/Sharing'
862 class USERPREF_PT_addons(bpy.types.Panel):
863 bl_space_type = 'USER_PREFERENCES'
865 bl_region_type = 'WINDOW'
866 bl_options = {'HIDE_HEADER'}
868 _addons_fake_modules = {}
871 def poll(cls, context):
872 userpref = context.user_preferences
873 return (userpref.active_section == 'ADDONS')
876 def module_get(mod_name):
877 return USERPREF_PT_addons._addons_fake_modules[mod_name]
879 def draw(self, context):
882 userpref = context.user_preferences
883 used_ext = {ext.module for ext in userpref.addons}
885 # collect the categories that can be filtered on
886 addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules)]
888 split = layout.split(percentage=0.2)
890 col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
891 col.prop(context.window_manager, "addon_filter", expand=True)
893 col.label(text="Supported Level")
894 col.prop(context.window_manager, "addon_support", expand=True)
898 filter = context.window_manager.addon_filter
899 search = context.window_manager.addon_search.lower()
900 support = context.window_manager.addon_support
902 for mod, info in addons:
903 module_name = mod.__name__
905 is_enabled = module_name in used_ext
907 if info["support"] not in support:
910 # check if add-on should be visible with current filters
911 if (filter == "All") or \
912 (filter == info["category"]) or \
913 (filter == "Enabled" and is_enabled) or \
914 (filter == "Disabled" and not is_enabled):
916 if search and search not in info["name"].lower():
918 if search not in info["author"].lower():
924 box = col.column().box()
925 colsub = box.column()
928 row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name
931 rowsub.active = is_enabled
932 rowsub.label(text='%s: %s' % (info['category'], info["name"]))
934 rowsub.label(icon='ERROR')
936 # icon showing support level.
937 if info["support"] == 'OFFICIAL':
938 rowsub.label(icon='FILE_BLEND')
939 elif info["support"] == 'COMMUNITY':
940 rowsub.label(icon='POSE_DATA')
942 rowsub.label(icon='QUESTION')
945 row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
947 row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name
949 # Expanded UI (only if additional infos are available)
950 if info["show_expanded"]:
951 if info["description"]:
952 split = colsub.row().split(percentage=0.15)
953 split.label(text='Description:')
954 split.label(text=info["description"])
956 split = colsub.row().split(percentage=0.15)
957 split.label(text='Location:')
958 split.label(text=info["location"])
960 split = colsub.row().split(percentage=0.15)
961 split.label(text='Author:')
962 split.label(text=info["author"])
964 split = colsub.row().split(percentage=0.15)
965 split.label(text='Version:')
966 split.label(text='.'.join(str(x) for x in info["version"]))
968 split = colsub.row().split(percentage=0.15)
969 split.label(text="Warning:")
970 split.label(text=' ' + info["warning"], icon='ERROR')
971 if info["wiki_url"] or info["tracker_url"]:
972 split = colsub.row().split(percentage=0.15)
973 split.label(text="Internet:")
975 split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
976 if info["tracker_url"]:
977 split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
979 if info["wiki_url"] and info["tracker_url"]:
985 # Append missing scripts
986 # First collect scripts that are used but have no script file.
987 module_names = {mod.__name__ for mod, info in addons}
988 missing_modules = {ext for ext in used_ext if ext not in module_names}
990 if missing_modules and filter in {"All", "Enabled"}:
991 col.column().separator()
992 col.column().label(text="Missing script files")
994 module_names = {mod.__name__ for mod, info in addons}
995 for module_name in sorted(missing_modules):
996 is_enabled = module_name in used_ext
998 box = col.column().box()
999 colsub = box.column()
1002 row.label(text=module_name, icon='ERROR')
1005 row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
1008 class WM_OT_addon_enable(bpy.types.Operator):
1010 bl_idname = "wm.addon_enable"
1011 bl_label = "Enable Add-On"
1013 module = StringProperty(name="Module", description="Module name of the addon to enable")
1015 def execute(self, context):
1016 mod = addon_utils.enable(self.module)
1019 # check if add-on is written for current blender version, or raise a warning
1020 info = addon_utils.module_bl_info(mod)
1022 if info.get("blender", (0, 0, 0)) > bpy.app.version:
1023 self.report("WARNING','This script was written for a newer version of Blender and might not function (correctly).\nThe script is enabled though.")
1026 return {'CANCELLED'}
1029 class WM_OT_addon_disable(bpy.types.Operator):
1031 bl_idname = "wm.addon_disable"
1032 bl_label = "Disable Add-On"
1034 module = StringProperty(name="Module", description="Module name of the addon to disable")
1036 def execute(self, context):
1037 addon_utils.disable(self.module)
1041 class WM_OT_addon_install(bpy.types.Operator):
1043 bl_idname = "wm.addon_install"
1044 bl_label = "Install Add-On..."
1046 overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True)
1048 filepath = StringProperty(name="File Path", description="File path to write file to")
1049 filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
1050 filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
1051 filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'})
1054 def _module_remove(path_addons, module):
1055 module = os.path.splitext(module)[0]
1056 for f in os.listdir(path_addons):
1057 f_base = os.path.splitext(f)[0]
1058 if f_base == module:
1059 f_full = os.path.join(path_addons, f)
1061 if os.path.isdir(f_full):
1066 def execute(self, context):
1071 pyfile = self.filepath
1073 # dont use bpy.utils.script_paths("addons") because we may not be able to write to it.
1074 path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
1077 self.report({'ERROR'}, "Failed to get addons path")
1078 return {'CANCELLED'}
1080 # Check if we are installing from a target path,
1081 # doing so causes 2+ addons of same name or when the same from/to
1082 # location is used, removal of the file!
1084 pyfile_dir = os.path.dirname(pyfile)
1085 for addon_path in addon_utils.paths():
1086 if os.path.samefile(pyfile_dir, addon_path):
1087 self.report({'ERROR'}, "Source file is in the addon search path: %r" % addon_path)
1088 return {'CANCELLED'}
1091 # done checking for exceptional case
1093 contents = set(os.listdir(path_addons))
1095 #check to see if the file is in compressed format (.zip)
1096 if zipfile.is_zipfile(pyfile):
1098 file_to_extract = zipfile.ZipFile(pyfile, 'r')
1100 traceback.print_exc()
1101 return {'CANCELLED'}
1104 for f in file_to_extract.namelist():
1105 __class__._module_remove(path_addons, f)
1107 for f in file_to_extract.namelist():
1108 path_dest = os.path.join(path_addons, os.path.basename(f))
1109 if os.path.exists(path_dest):
1110 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1111 return {'CANCELLED'}
1113 try: # extract the file to "addons"
1114 file_to_extract.extractall(path_addons)
1116 # zip files can create this dir with metadata, don't need it
1117 macosx_dir = os.path.join(path_addons, '__MACOSX')
1118 if os.path.isdir(macosx_dir):
1119 shutil.rmtree(macosx_dir)
1122 traceback.print_exc()
1123 return {'CANCELLED'}
1126 path_dest = os.path.join(path_addons, os.path.basename(pyfile))
1129 __class__._module_remove(path_addons, os.path.basename(pyfile))
1130 elif os.path.exists(path_dest):
1131 self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
1132 return {'CANCELLED'}
1134 #if not compressed file just copy into the addon path
1136 shutil.copyfile(pyfile, path_dest)
1139 traceback.print_exc()
1140 return {'CANCELLED'}
1142 # disable any addons we may have enabled previously and removed.
1143 # this is unlikely but do just incase. bug [#23978]
1144 addons_new = set(os.listdir(path_addons)) - contents
1145 for new_addon in addons_new:
1146 addon_utils.disable(os.path.splitext(new_addon)[0])
1148 # possible the zip contains multiple addons, we could disallow this
1149 # but for now just use the first
1150 for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
1151 if mod.__name__ in addons_new:
1152 info = addon_utils.module_bl_info(mod)
1154 # show the newly installed addon.
1155 context.window_manager.addon_filter = 'All'
1156 context.window_manager.addon_search = info["name"]
1159 # TODO, should not be a warning.
1160 # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)
1163 def invoke(self, context, event):
1164 wm = context.window_manager
1165 wm.fileselect_add(self)
1166 return {'RUNNING_MODAL'}
1169 class WM_OT_addon_expand(bpy.types.Operator):
1170 "Display more information on this add-on"
1171 bl_idname = "wm.addon_expand"
1174 module = StringProperty(name="Module", description="Module name of the addon to expand")
1176 def execute(self, context):
1177 module_name = self.module
1179 # unlikely to fail, module should have already been imported
1181 # mod = __import__(module_name)
1182 mod = USERPREF_PT_addons.module_get(module_name)
1185 traceback.print_exc()
1186 return {'CANCELLED'}
1188 info = addon_utils.module_bl_info(mod)
1189 info["show_expanded"] = not info["show_expanded"]
1192 if __name__ == "__main__": # only for live edit.
1193 bpy.utils.register_module(__name__)