cleanup for addon python internals, fix filtering bug.
This commit is contained in:
@@ -418,6 +418,19 @@ class WM_OT_context_modal_mouse(bpy.types.Operator):
|
|||||||
return {'RUNNING_MODAL'}
|
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):
|
class WM_OT_doc_view(bpy.types.Operator):
|
||||||
'''Load online reference docs'''
|
'''Load online reference docs'''
|
||||||
bl_idname = "wm.doc_view"
|
bl_idname = "wm.doc_view"
|
||||||
@@ -556,6 +569,8 @@ classes = [
|
|||||||
WM_OT_context_cycle_enum,
|
WM_OT_context_cycle_enum,
|
||||||
WM_OT_context_cycle_int,
|
WM_OT_context_cycle_int,
|
||||||
WM_OT_context_modal_mouse,
|
WM_OT_context_modal_mouse,
|
||||||
|
|
||||||
|
WM_OT_url_open,
|
||||||
|
|
||||||
WM_OT_doc_view,
|
WM_OT_doc_view,
|
||||||
WM_OT_doc_edit,
|
WM_OT_doc_edit,
|
||||||
|
@@ -1385,6 +1385,8 @@ class USERPREF_PT_addons(bpy.types.Panel):
|
|||||||
bl_label = "Addons"
|
bl_label = "Addons"
|
||||||
bl_region_type = 'WINDOW'
|
bl_region_type = 'WINDOW'
|
||||||
bl_show_header = False
|
bl_show_header = False
|
||||||
|
|
||||||
|
_addon_blank = {"name": "", "author": "", "version": "", "blender": "", "location": "", "url": "", "category": ""}
|
||||||
|
|
||||||
def poll(self, context):
|
def poll(self, context):
|
||||||
userpref = context.user_preferences
|
userpref = context.user_preferences
|
||||||
@@ -1405,21 +1407,16 @@ class USERPREF_PT_addons(bpy.types.Panel):
|
|||||||
|
|
||||||
def _attributes(self, mod):
|
def _attributes(self, mod):
|
||||||
# collect, check and process all attributes of the add-on
|
# collect, check and process all attributes of the add-on
|
||||||
module_name = mod.__name__
|
|
||||||
if not hasattr(mod, 'expanded'):
|
if not hasattr(mod, 'expanded'):
|
||||||
mod.expanded = False
|
mod.expanded = False
|
||||||
|
|
||||||
info = 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", "")
|
|
||||||
|
|
||||||
return module_name, name, author, version, blender, location, url, category
|
info = self._addon_blank.copy()
|
||||||
|
info.update(getattr(mod, "bl_addon_info", {}))
|
||||||
|
|
||||||
|
if not info["name"]:
|
||||||
|
info["name"] = mod.__name__
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
@@ -1428,16 +1425,13 @@ class USERPREF_PT_addons(bpy.types.Panel):
|
|||||||
used_ext = {ext.module for ext in userpref.addons}
|
used_ext = {ext.module for ext in userpref.addons}
|
||||||
|
|
||||||
# collect the categories that can be filtered on
|
# collect the categories that can be filtered on
|
||||||
cats = []
|
addons = [(mod, self._attributes(mod)) for mod in self._addon_list()]
|
||||||
for mod in self._addon_list():
|
|
||||||
try:
|
|
||||||
if category not in cats:
|
|
||||||
cats.append(category)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
cats.sort()
|
cats = {info["category"] for mod, info in addons}
|
||||||
cats = ['All', 'Disabled', 'Enabled']+cats
|
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))],
|
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")
|
name="Category", attr="addon_filter", description="Filter add-ons by category")
|
||||||
@@ -1450,18 +1444,22 @@ class USERPREF_PT_addons(bpy.types.Panel):
|
|||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
filter = context.scene.addon_filter
|
filter = context.scene.addon_filter
|
||||||
search = context.scene.addon_search
|
search = context.scene.addon_search.lower()
|
||||||
|
|
||||||
for mod in self._addon_list():
|
for mod in self._addon_list():
|
||||||
module_name, name, author, version, blender, location, url, category = \
|
module_name = mod.__name__
|
||||||
self._attributes(mod)
|
info = self._attributes(mod)
|
||||||
|
|
||||||
# check if add-on should be visible with current filters
|
# 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')\
|
if filter != "All" and \
|
||||||
and not (module_name not in used_ext and filter=='Disabled'):
|
filter != info["category"] and \
|
||||||
|
not (module_name not in used_ext and filter == "Disabled"):
|
||||||
|
|
||||||
continue
|
continue
|
||||||
if search and name.lower().find(search.lower())<0:
|
|
||||||
if author:
|
if search and search not in info["name"].lower():
|
||||||
if author.lower().find(search.lower())<0:
|
if info["author"]:
|
||||||
|
if search not in info["author"].lower():
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
@@ -1475,38 +1473,35 @@ class USERPREF_PT_addons(bpy.types.Panel):
|
|||||||
# If there are Infos or UI is expanded
|
# If there are Infos or UI is expanded
|
||||||
if mod.expanded:
|
if mod.expanded:
|
||||||
row.operator("wm.addon_expand", icon="TRIA_DOWN").module = module_name
|
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
|
row.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
|
||||||
else:
|
else:
|
||||||
# Else, block UI
|
# Else, block UI
|
||||||
arrow = row.column()
|
arrow = row.column()
|
||||||
arrow.enabled = False
|
arrow.enabled = False
|
||||||
arrow.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
|
arrow.operator("wm.addon_expand", icon="TRIA_RIGHT").module = module_name
|
||||||
|
|
||||||
if name:
|
row.label(text=info["name"])
|
||||||
row.label(text=name)
|
|
||||||
else: #For now, can be removed when all addons, have a proper dict
|
|
||||||
row.label(text=module_name)
|
|
||||||
row.operator("wm.addon_disable" if module_name in used_ext else "wm.addon_enable").module = module_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)
|
# Expanded UI (only if additional infos are available)
|
||||||
if mod.expanded:
|
if mod.expanded:
|
||||||
if author:
|
if info["author"]:
|
||||||
split = column.row().split(percentage=0.15)
|
split = column.row().split(percentage=0.15)
|
||||||
split.label(text='Author:')
|
split.label(text='Author:')
|
||||||
split.label(text=author)
|
split.label(text=info["author"])
|
||||||
if version:
|
if info["version"]:
|
||||||
split = column.row().split(percentage=0.15)
|
split = column.row().split(percentage=0.15)
|
||||||
split.label(text='Version:')
|
split.label(text='Version:')
|
||||||
split.label(text=version)
|
split.label(text=info["version"])
|
||||||
if location:
|
if info["location"]:
|
||||||
split = column.row().split(percentage=0.15)
|
split = column.row().split(percentage=0.15)
|
||||||
split.label(text='Location:')
|
split.label(text='Location:')
|
||||||
split.label(text=location)
|
split.label(text=info["location"])
|
||||||
if url:
|
if info["url"]:
|
||||||
split = column.row().split(percentage=0.15)
|
split = column.row().split(percentage=0.15)
|
||||||
split.label(text="Internet:")
|
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()
|
||||||
split.separator()
|
split.separator()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user