use a dynamic enum for addons, annoyingly the enum was being generated from python...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 26 May 2011 18:11:59 +0000 (18:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 26 May 2011 18:11:59 +0000 (18:11 +0000)
Eventually it would be good to have the expanded buttons all using the same result from itemf().

release/scripts/startup/bl_ui/__init__.py
release/scripts/startup/bl_ui/space_userpref.py

index 2f933fb57716b1802274897f1580abaa3d2f1faf..bf63c6071b99695bcf068a30a94785f9cb7fafe3 100644 (file)
@@ -85,26 +85,26 @@ def register():
     from bpy.props import StringProperty, EnumProperty
     WindowManager = bpy.types.WindowManager
 
+    def addon_filter_items(self, context):
+        import addon_utils
+
+        items = [('All', "All", ""),
+                 ('Enabled', "Enabled", ""),
+                 ('Disabled', "Disabled", ""),
+                ]
+
+        items_unique = set()
+
+        for mod in addon_utils.modules(space_userpref.USERPREF_PT_addons._addons_fake_modules):
+            info = addon_utils.module_bl_info(mod)
+            items_unique.add(info["category"])
+
+        items.extend([(cat, cat, "") for cat in sorted(items_unique)])
+        return items
+
     WindowManager.addon_search = StringProperty(name="Search", description="Search within the selected filter")
     WindowManager.addon_filter = EnumProperty(
-            items=[('All', "All", ""),
-                   ('Enabled', "Enabled", ""),
-                   ('Disabled', "Disabled", ""),
-                   ('3D View', "3D View", ""),
-                   ('Add Curve', "Add Curve", ""),
-                   ('Add Mesh', "Add Mesh", ""),
-                   ('Animation', "Animation", ""),
-                   ('Development', "Development", ""),
-                   ('Game Engine', "Game Engine", ""),
-                   ('Import-Export', "Import-Export", ""),
-                   ('Mesh', "Mesh", ""),
-                   ('Object', "Object", ""),
-                   ('Render', "Render", ""),
-                   ('Rigging', "Rigging", ""),
-                   ('Text Editor', "Text Editor", ""),
-                   ('System', "System", ""),
-                   ('Other', "Other", ""),
-                   ],
+            items=addon_filter_items,
             name="Category",
             description="Filter add-ons by category",
             )
index d4ebae04c3423a4308682867d080447d8b9be062..e34755ae72eb7aff6fb8ab83d7f5dde3df3c160a 100644 (file)
@@ -889,7 +889,8 @@ class USERPREF_PT_addons(bpy.types.Panel):
         split = layout.split(percentage=0.2)
         col = split.column()
         col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
-        col.prop(context.window_manager, "addon_filter", expand=True)
+        col.label(text="Categories")
+        col.prop(context.window_manager, "addon_filter", text="")  # , expand=True, too slow with dynamic enum.
 
         col.label(text="Supported Level")
         col.prop(context.window_manager, "addon_support", expand=True)