[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27496] trunk/blender/release/scripts: cleanup for addon python internals, fix filtering bug.
Campbell Barton
ideasman42 at gmail.com
Sun Mar 14 21:07:15 CET 2010
Revision: 27496
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27496
Author: campbellbarton
Date: 2010-03-14 21:07:15 +0100 (Sun, 14 Mar 2010)
Log Message:
-----------
cleanup for addon python internals, fix filtering bug.
Modified Paths:
--------------
trunk/blender/release/scripts/op/wm.py
trunk/blender/release/scripts/ui/space_userpref.py
Modified: trunk/blender/release/scripts/op/wm.py
===================================================================
--- trunk/blender/release/scripts/op/wm.py 2010-03-14 19:38:36 UTC (rev 27495)
+++ trunk/blender/release/scripts/op/wm.py 2010-03-14 20:07:15 UTC (rev 27496)
@@ -418,6 +418,19 @@
return {'RUNNING_MODAL'}
+class WM_OT_url_open(bpy.types.Operator):
+ "Open the Blender Wiki in the Webbrowser"
+ bl_idname = "wm.url_open"
+ bl_label = ""
+
+ url = StringProperty(name="URL", description="URL to open")
+
+ def execute(self, context):
+ import webbrowser
+ webbrowser.open(self.properties.url)
+ return {'FINISHED'}
+
+
class WM_OT_doc_view(bpy.types.Operator):
'''Load online reference docs'''
bl_idname = "wm.doc_view"
@@ -556,6 +569,8 @@
WM_OT_context_cycle_enum,
WM_OT_context_cycle_int,
WM_OT_context_modal_mouse,
+
+ WM_OT_url_open,
WM_OT_doc_view,
WM_OT_doc_edit,
Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py 2010-03-14 19:38:36 UTC (rev 27495)
+++ trunk/blender/release/scripts/ui/space_userpref.py 2010-03-14 20:07:15 UTC (rev 27496)
@@ -1385,6 +1385,8 @@
bl_label = "Addons"
bl_region_type = 'WINDOW'
bl_show_header = False
+
+ _addon_blank = {"name": "", "author": "", "version": "", "blender": "", "location": "", "url": "", "category": ""}
def poll(self, context):
userpref = context.user_preferences
@@ -1405,21 +1407,16 @@
def _attributes(self, mod):
# collect, check and process all attributes of the add-on
- module_name = mod.__name__
if not hasattr(mod, 'expanded'):
mod.expanded = False
-
- info = getattr(mod, "bl_addon_info", {})
+
+ info = self._addon_blank.copy()
+ info.update(getattr(mod, "bl_addon_info", {}))
- name = info.get("name", "")
- author = info.get("author", "")
- version = info.get("version", "")
- blender = info.get("blender", "")
- location = info.get("location", "")
- url = info.get("url", "")
- category = info.get("category", "")
+ if not info["name"]:
+ info["name"] = mod.__name__
- return module_name, name, author, version, blender, location, url, category
+ return info
def draw(self, context):
layout = self.layout
@@ -1428,16 +1425,13 @@
used_ext = {ext.module for ext in userpref.addons}
# collect the categories that can be filtered on
- cats = []
- for mod in self._addon_list():
- try:
- if category not in cats:
- cats.append(category)
- except:
- pass
+ addons = [(mod, self._attributes(mod)) for mod in self._addon_list()]
- cats.sort()
- cats = ['All', 'Disabled', 'Enabled']+cats
+ cats = {info["category"] for mod, info in addons}
+ cats.add("")
+ cats.remove("")
+
+ cats = ['All', 'Disabled', 'Enabled'] + sorted(cats)
bpy.types.Scene.EnumProperty(items=[(cats[i],cats[i],str(i)) for i in range(len(cats))],
name="Category", attr="addon_filter", description="Filter add-ons by category")
@@ -1450,18 +1444,22 @@
layout.separator()
filter = context.scene.addon_filter
- search = context.scene.addon_search
+ search = context.scene.addon_search.lower()
+
for mod in self._addon_list():
- module_name, name, author, version, blender, location, url, category = \
- self._attributes(mod)
+ module_name = mod.__name__
+ info = self._attributes(mod)
# check if add-on should be visible with current filters
- if filter!='All' and filter!=category and not (module_name in used_ext and filter=='Enabled')\
- and not (module_name not in used_ext and filter=='Disabled'):
+ if filter != "All" and \
+ filter != info["category"] and \
+ not (module_name not in used_ext and filter == "Disabled"):
+
continue
- if search and name.lower().find(search.lower())<0:
- if author:
- if author.lower().find(search.lower())<0:
+
+ if search and search not in info["name"].lower():
+ if info["author"]:
+ if search not in info["author"].lower():
continue
else:
continue
@@ -1475,38 +1473,35 @@
# If there are Infos or UI is expanded
if mod.expanded:
row.operator("wm.addon_expand", icon="TRIA_DOWN").module = module_name
- elif author or version or url or location:
+ elif info["author"] or info["version"] or info["url"] or info["location"]:
row.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
else:
# Else, block UI
arrow = row.column()
arrow.enabled = False
arrow.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
-
- if name:
- row.label(text=name)
- else: #For now, can be removed when all addons, have a proper dict
- row.label(text=module_name)
+
+ row.label(text=info["name"])
row.operator("wm.addon_disable" if module_name in used_ext else "wm.addon_enable").module = module_name
# Expanded UI (only if additional infos are available)
if mod.expanded:
- if author:
+ if info["author"]:
split = column.row().split(percentage=0.15)
split.label(text='Author:')
- split.label(text=author)
- if version:
+ split.label(text=info["author"])
+ if info["version"]:
split = column.row().split(percentage=0.15)
split.label(text='Version:')
- split.label(text=version)
- if location:
+ split.label(text=info["version"])
+ if info["location"]:
split = column.row().split(percentage=0.15)
split.label(text='Location:')
- split.label(text=location)
- if url:
+ split.label(text=info["location"])
+ if info["url"]:
split = column.row().split(percentage=0.15)
split.label(text="Internet:")
- split.operator("wm.addon_links", text="Link to the Wiki").link = url
+ split.operator("wm.addon_links", text="Link to the Wiki").link = info["url"]
split.separator()
split.separator()
More information about the Bf-blender-cvs
mailing list