[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37950] trunk/blender/release/scripts/ startup/bl_ui/space_userpref.py: Addon UI: button for removing addons which are installed to user/home paths, this is not displayed for system addons, or ones which come with blender.

Campbell Barton ideasman42 at gmail.com
Wed Jun 29 17:56:22 CEST 2011


Revision: 37950
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37950
Author:   campbellbarton
Date:     2011-06-29 15:56:22 +0000 (Wed, 29 Jun 2011)
Log Message:
-----------
Addon UI: button for removing addons which are installed to user/home paths, this is not displayed  for system addons, or ones which come with blender.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-06-29 14:29:52 UTC (rev 37949)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2011-06-29 15:56:22 UTC (rev 37950)
@@ -876,6 +876,19 @@
     def module_get(mod_name):
         return USERPREF_PT_addons._addons_fake_modules[mod_name]
 
+    @staticmethod
+    def is_user_addon(mod, user_addon_paths):
+        if not user_addon_paths:
+            user_script_path = bpy.utils.user_script_path()
+            if user_script_path is not None:
+                user_addon_paths.append(os.path.join(user_script_path(), "addons"))
+            user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons"))
+        
+        for path in user_addon_paths:
+            if bpy.path.is_subdir(mod.__file__, path):
+                return True
+        return False
+
     def draw(self, context):
         layout = self.layout
 
@@ -900,6 +913,9 @@
         search = context.window_manager.addon_search.lower()
         support = context.window_manager.addon_support
 
+        # initialized on demand
+        user_addon_paths = []
+
         for mod, info in addons:
             module_name = mod.__name__
 
@@ -969,19 +985,24 @@
                         split = colsub.row().split(percentage=0.15)
                         split.label(text="Warning:")
                         split.label(text='  ' + info["warning"], icon='ERROR')
-                    if info["wiki_url"] or info["tracker_url"]:
+
+                    user_addon = __class__.is_user_addon(mod, user_addon_paths)
+                    tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)
+
+                    if tot_row:
                         split = colsub.row().split(percentage=0.15)
                         split.label(text="Internet:")
                         if info["wiki_url"]:
                             split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
                         if info["tracker_url"]:
                             split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
+                        if user_addon:
+                            split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__
 
-                        if info["wiki_url"] and info["tracker_url"]:
+                        for i in range(4 - tot_row):
                             split.separator()
-                        else:
-                            split.separator()
-                            split.separator()
+                        
+                        
 
         # Append missing scripts
         # First collect scripts that are used but have no script file.
@@ -1186,6 +1207,54 @@
         return {'RUNNING_MODAL'}
 
 
+class WM_OT_addon_remove(bpy.types.Operator):
+    "Disable an addon"
+    bl_idname = "wm.addon_remove"
+    bl_label = "Remove Add-On"
+
+    module = StringProperty(name="Module", description="Module name of the addon to remove")
+
+    @staticmethod
+    def path_from_addon(module):
+        for mod in addon_utils.modules(USERPREF_PT_addons._addons_fake_modules):
+            if mod.__name__ == module:
+                filepath = mod.__file__
+                if os.path.exists(filepath):
+                    if os.path.splitext(os.path.basename(filepath))[0] == "__init__":
+                        return os.path.dirname(filepath), True
+                    else:
+                        return filepath, False
+        return None, False
+
+    def execute(self, context):
+        path, isdir = __class__.path_from_addon(self.module)
+        if path is None:
+            self.report('WARNING', "Addon path %r could not be found" % path)
+            return {'CANCELLED'}
+
+        # incase its enabled
+        addon_utils.disable(self.module)
+
+        import shutil
+        if isdir:
+            shutil.rmtree(path)
+        else:
+            os.remove(path)
+
+        context.area.tag_redraw()
+        return {'FINISHED'}
+
+    # lame confirmation check
+    def draw(self, context):
+        self.layout.label(text="Remove Addon: %r?" % self.module)
+        path, isdir = __class__.path_from_addon(self.module)
+        self.layout.label(text="Path: %r" % path)
+
+    def invoke(self, context, event):
+        wm = context.window_manager
+        return wm.invoke_props_dialog(self, width=600)
+
+
 class WM_OT_addon_expand(bpy.types.Operator):
     "Display more information on this add-on"
     bl_idname = "wm.addon_expand"




More information about the Bf-blender-cvs mailing list