[Bf-extensions-cvs] [fa9e1d79] master: Rigify: Addon Prefs & Feature Sets UI

Demeter Dzadik noreply at git.blender.org
Sun Nov 8 05:32:27 CET 2020


Commit: fa9e1d797972ae7a13bd6dc7849625c24fcf108a
Author: Demeter Dzadik
Date:   Sun Nov 8 05:31:13 2020 +0100
Branches: master
https://developer.blender.org/rBAfa9e1d797972ae7a13bd6dc7849625c24fcf108a

Rigify: Addon Prefs & Feature Sets UI

This patch removes the two drop-down menus from the Rigify addon preferences, replacing it with a checkbox and a UIList.

Before:
{F8766280}

After:
{F8791382}

There is also a small bit of new functionality. The following keys are now recognized in the rigify_info dictionary, similar to Blender addons:
`'link', 'doc_url', 'tracker_url', 'description', 'author', 'version', 'warning'.`
They will be displayed underneath the UIList when the feature set is the active one in the list.

**Ideas for future**
I think this UI better enables us to do some cool things in the future:
- Disable feature sets without uninstalling them.
- Have a base set of feature sets in the list that aren't actually installed. Instead, selecting them would just reveal a button that opens their repository URL. This could be used for officially supported but external feature sets, such as what Legacy should be.

Feedback welcome.

Reviewed By: angavrilov

Differential Revision: https://developer.blender.org/D8519

===================================================================

M	rigify/__init__.py
M	rigify/feature_set_list.py

===================================================================

diff --git a/rigify/__init__.py b/rigify/__init__.py
index 9254e49d..d9fb680d 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -140,6 +140,11 @@ from bpy.props import (
 )
 
 
+class RigifyFeatureSets(bpy.types.PropertyGroup):
+    name: bpy.props.StringProperty()
+    module_name: bpy.props.StringProperty()
+
+
 class RigifyPreferences(AddonPreferences):
     # this must match the addon name, use '__package__'
     # when defining this in a submodule of a python package.
@@ -230,70 +235,101 @@ class RigifyPreferences(AddonPreferences):
             # Re-register rig parameters
             register_rig_parameters()
 
+            # Update feature set list
+            self.rigify_feature_sets.clear()
+            for s in set_list:
+                list_entry = self.rigify_feature_sets.add()
+                list_entry.name = feature_set_list.get_ui_name(s)
+                list_entry.module_name = s
+
     legacy_mode: BoolProperty(
-        name='Rigify Legacy Mode',
-        description='Select if you want to use Rigify in legacy mode',
+        name='Legacy Mode',
+        description='When enabled the add-on will run in legacy mode using the old 2.76b feature set',
         default=False,
         update=update_legacy
     )
 
-    show_expanded: BoolProperty()
-
-    show_rigs_folder_expanded: BoolProperty()
+    rigify_feature_sets: bpy.props.CollectionProperty(type=RigifyFeatureSets)
+    active_feature_set_index: IntProperty()
 
     def draw(self, context):
         layout = self.layout
-        column = layout.column()
-        box = column.box()
-
-        # first stage
-        expand = getattr(self, 'show_expanded')
-        icon = 'TRIA_DOWN' if expand else 'TRIA_RIGHT'
-        col = box.column()
-        row = col.row()
-        sub = row.row()
-        sub.context_pointer_set('addon_prefs', self)
-        sub.alignment = 'LEFT'
-        op = sub.operator('wm.context_toggle', text='', icon=icon,
-                          emboss=False)
-        op.data_path = 'addon_prefs.show_expanded'
-        sub.label(text='{}: {}'.format('Rigify', 'Enable Legacy Mode'))
-        sub = row.row()
-        sub.alignment = 'RIGHT'
-        sub.prop(self, 'legacy_mode')
-
-        if expand:
-            split = col.row().split(factor=0.15)
-            split.label(text='Description:')
-            split.label(text='When enabled the add-on will run in legacy mode using the old 2.76b feature set.')
-
-        box = column.box()
-        rigs_expand = getattr(self, 'show_rigs_folder_expanded')
-        icon = 'TRIA_DOWN' if rigs_expand else 'TRIA_RIGHT'
-        col = box.column()
-        row = col.row()
-        sub = row.row()
-        sub.context_pointer_set('addon_prefs', self)
-        sub.alignment = 'LEFT'
-        op = sub.operator('wm.context_toggle', text='', icon=icon,
-                          emboss=False)
-        op.data_path = 'addon_prefs.show_rigs_folder_expanded'
-        sub.label(text='{}: {}'.format('Rigify', 'External feature sets'))
-        if rigs_expand:
-            for fs in feature_set_list.get_installed_list():
-                row = col.split(factor=0.8)
-                row.label(text=feature_set_list.get_ui_name(fs))
-                op = row.operator("wm.rigify_remove_feature_set", text="Remove", icon='CANCEL')
-                op.featureset = fs
-            row = col.row(align=True)
-            row.operator("wm.rigify_add_feature_set", text="Install Feature Set from File...", icon='FILEBROWSER')
-
-            split = col.row().split(factor=0.15)
-            split.label(text='Description:')
-            split.label(text='External feature sets (rigs, metarigs, ui layouts)')
+
+        layout.prop(self, 'legacy_mode')
+
+        if self.legacy_mode:
+            return
+
+
+        layout.label(text="Feature Sets:")
+
+        layout.operator("wm.rigify_add_feature_set", text="Install Feature Set from File...", icon='FILEBROWSER')
 
         row = layout.row()
-        row.label(text="End of Rigify Preferences")
+        row.template_list(
+            "UI_UL_list",
+            "rigify_feature_sets",
+            self, "rigify_feature_sets",
+            self, 'active_feature_set_index'
+        )
+
+        # Clamp active index to ensure it's in bounds.
+        self.active_feature_set_index = max(0, min(self.active_feature_set_index, len(self.rigify_feature_sets)-1))
+        active_fs = self.rigify_feature_sets[self.active_feature_set_index]
+
+        if active_fs:
+            draw_feature_set_prefs(layout, context, active_fs)
+
+
+def draw_feature_set_prefs(layout, context, featureset: RigifyFeatureSets):
+    info = feature_set_list.get_info_dict(featureset.module_name)
+
+    description = featureset.name
+    if 'description' in info:
+        description = info['description']
+
+    col = layout.column()
+    split_factor = 0.15
+
+    split = col.row().split(factor=split_factor)
+    split.label(text="Description:")
+    split.label(text=description)
+
+    mod = feature_set_list.get_module_safe(featureset.module_name)
+    if mod:
+        split = col.row().split(factor=split_factor)
+        split.label(text="File:")
+        split.label(text=mod.__file__, translate=False)
+
+    if 'author' in info:
+        split = col.row().split(factor=split_factor)
+        split.label(text="Author:")
+        split.label(text=info["author"])
+
+    if 'version' in info:
+        split = col.row().split(factor=split_factor)
+        split.label(text="Version:")
+        split.label(text=".".join(str(x) for x in info['version']), translate=False)
+    if 'warning' in info:
+        split = col.row().split(factor=split_factor)
+        split.label(text="Warning:")
+        split.label(text="  " + info['warning'], icon='ERROR')
+
+    split = col.row().split(factor=split_factor)
+    split.label(text="Internet:")
+    row = split.row()
+    if 'link' in info:
+        op = row.operator('wm.url_open', text="Repository", icon='URL')
+        op.url = info['link']
+    if 'doc_url' in info:
+        op = row.operator('wm.url_open', text="Documentation", icon='HELP')
+        op.url = info['doc_url']
+    if 'tracker_url' in info:
+        op = row.operator('wm.url_open', text="Report a Bug", icon='URL')
+        op.url = info['tracker_url']
+
+    op = row.operator("wm.rigify_remove_feature_set", text="Remove", icon='CANCEL')
+    op.featureset = featureset.module_name
 
 
 class RigifyName(bpy.types.PropertyGroup):
@@ -474,6 +510,7 @@ classes = (
     RigifyColorSet,
     RigifySelectionColors,
     RigifyArmatureLayer,
+    RigifyFeatureSets,
     RigifyPreferences,
 )
 
diff --git a/rigify/feature_set_list.py b/rigify/feature_set_list.py
index 0204f86a..a50bd010 100644
--- a/rigify/feature_set_list.py
+++ b/rigify/feature_set_list.py
@@ -220,9 +220,11 @@ class DATA_OT_rigify_add_feature_set(bpy.types.Operator):
             # Call the register callback of the new set
             call_register_function(fixed_dirname, True)
 
-        addon_prefs.machin = bpy.props.EnumProperty(items=(('a',)*3, ('b',)*3, ('c',)*3),)
+            addon_prefs.update_external_rigs()
+
+            new_index = addon_prefs.rigify_feature_sets.find(get_ui_name(fixed_dirname))
+            addon_prefs.active_feature_set_index = new_index
 
-        addon_prefs.update_external_rigs()
         return {'FINISHED'}
 
 
@@ -254,8 +256,11 @@ class DATA_OT_rigify_remove_feature_set(bpy.types.Operator):
                 rmtree(set_path)
 
         addon_prefs.update_external_rigs(force=True)
+        addon_prefs.active_feature_set_index = 0
+
         return {'FINISHED'}
 
+
 def register():
     bpy.utils.register_class(DATA_OT_rigify_add_feature_set)
     bpy.utils.register_class(DATA_OT_rigify_remove_feature_set)



More information about the Bf-extensions-cvs mailing list