[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4282] trunk/py/scripts/addons/rigify: Rigify: removed "from rigfy import X" statements where possible.

Nathan Vegdahl cessen at cessen.com
Sat Feb 16 09:12:03 CET 2013


Revision: 4282
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4282
Author:   cessen
Date:     2013-02-16 08:12:03 +0000 (Sat, 16 Feb 2013)
Log Message:
-----------
Rigify: removed "from rigfy import X" statements where possible.

This makes it much easier for e.g. someone to branch Rigify for
custom purposes, since there won't be weird name conflicts.

Also changed from using __import__() for dynamic imports to using
importlib.import_module().  This simplifies the code and should
be more robust.

Finally, misc pep8 cleanups.

Modified Paths:
--------------
    trunk/py/scripts/addons/rigify/__init__.py
    trunk/py/scripts/addons/rigify/generate.py
    trunk/py/scripts/addons/rigify/metarig_menu.py
    trunk/py/scripts/addons/rigify/rigs/basic/copy.py
    trunk/py/scripts/addons/rigify/rigs/basic/copy_chain.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/deform.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/fk.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/ik.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py
    trunk/py/scripts/addons/rigify/rigs/finger.py
    trunk/py/scripts/addons/rigify/rigs/misc/delta.py
    trunk/py/scripts/addons/rigify/rigs/neck_short.py
    trunk/py/scripts/addons/rigify/rigs/palm.py
    trunk/py/scripts/addons/rigify/rigs/spine.py
    trunk/py/scripts/addons/rigify/ui.py
    trunk/py/scripts/addons/rigify/utils.py

Added Paths:
-----------
    trunk/py/scripts/addons/rigify/rig_lists.py

Modified: trunk/py/scripts/addons/rigify/__init__.py
===================================================================
--- trunk/py/scripts/addons/rigify/__init__.py	2013-02-15 18:46:36 UTC (rev 4281)
+++ trunk/py/scripts/addons/rigify/__init__.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -38,75 +38,13 @@
     imp.reload(ui)
     imp.reload(utils)
     imp.reload(metarig_menu)
+    imp.reload(rig_lists)
 else:
-    from . import generate, ui, utils, metarig_menu
+    from . import utils, rig_lists, generate, ui, metarig_menu
 
 import bpy
-import os
 
 
-def get_rig_list(path):
-    """ Recursively searches for rig types, and returns a list.
-    """
-    rigs = []
-    MODULE_DIR = os.path.dirname(__file__)
-    RIG_DIR_ABS = os.path.join(MODULE_DIR, utils.RIG_DIR)
-    SEARCH_DIR_ABS = os.path.join(RIG_DIR_ABS, path)
-    files = os.listdir(SEARCH_DIR_ABS)
-    files.sort()
-
-    for f in files:
-        is_dir = os.path.isdir(os.path.join(SEARCH_DIR_ABS, f))  # Whether the file is a directory
-        if f[0] in {".", "_"}:
-            pass
-        elif f.count(".") >= 2 or (is_dir and "." in f):
-            print("Warning: %r, filename contains a '.', skipping" % os.path.join(SEARCH_DIR_ABS, f))
-        else:
-            if is_dir:
-                # Check directories
-                module_name = os.path.join(path, f).replace(os.sep, ".")
-                try:
-                    rig = utils.get_rig_type(module_name)
-                except ImportError as e:
-                    print("Rigify: " + str(e))
-                else:
-                    # Check if it's a rig itself
-                    if not hasattr(rig, "Rig"):
-                        # Check for sub-rigs
-                        ls = get_rig_list(os.path.join(path, f, ""))  # "" adds a final slash
-                        rigs.extend(["%s.%s" % (f, l) for l in ls])
-                    else:
-                        rigs += [f]
-
-            elif f.endswith(".py"):
-                # Check straight-up python files
-                t = f[:-3]
-                module_name = os.path.join(path, t).replace(os.sep, ".")
-                try:
-                    utils.get_rig_type(module_name).Rig
-                except (ImportError, AttributeError):
-                    pass
-                else:
-                    rigs += [t]
-    rigs.sort()
-    return rigs
-
-
-rig_list = get_rig_list("")
-
-
-collection_list = []
-for r in rig_list:
-    a = r.split(".")
-    if len(a) >= 2 and a[0] not in collection_list:
-        collection_list += [a[0]]
-
-
-col_enum_list = [("All", "All", ""), ("None", "None", "")]
-for c in collection_list:
-    col_enum_list += [(c, c, "")]
-
-
 class RigifyName(bpy.types.PropertyGroup):
     name = bpy.props.StringProperty()
 
@@ -136,12 +74,12 @@
     bpy.types.Armature.rigify_layers = bpy.props.CollectionProperty(type=RigifyArmatureLayer)
 
     IDStore = bpy.types.WindowManager
-    IDStore.rigify_collection = bpy.props.EnumProperty(items=col_enum_list, default="All", name="Rigify Active Collection", description="The selected rig collection")
+    IDStore.rigify_collection = bpy.props.EnumProperty(items=rig_lists.col_enum_list, default="All", name="Rigify Active Collection", description="The selected rig collection")
     IDStore.rigify_types = bpy.props.CollectionProperty(type=RigifyName)
     IDStore.rigify_active_type = bpy.props.IntProperty(name="Rigify Active Type", description="The selected rig type")
 
     # Add rig parameters
-    for rig in rig_list:
+    for rig in rig_lists.rig_list:
         r = utils.get_rig_type(rig).Rig
         try:
             r.add_parameters(RigifyParameters)

Modified: trunk/py/scripts/addons/rigify/generate.py
===================================================================
--- trunk/py/scripts/addons/rigify/generate.py	2013-02-15 18:46:36 UTC (rev 4281)
+++ trunk/py/scripts/addons/rigify/generate.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -24,15 +24,15 @@
 import traceback
 import sys
 from rna_prop_ui import rna_idprop_ui_prop_get
-from rigify.utils import MetarigError, new_bone, get_rig_type
-from rigify.utils import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, WGT_PREFIX, ROOT_NAME, make_original_name
-from rigify.utils import RIG_DIR
-from rigify.utils import create_root_widget
-from rigify.utils import random_id
-from rigify.utils import copy_attributes
-from rigify.rig_ui_template import UI_SLIDERS, layers_ui, UI_REGISTER
-from rigify import rigs
 
+from .utils import MetarigError, new_bone, get_rig_type
+from .utils import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, WGT_PREFIX, ROOT_NAME, make_original_name
+from .utils import RIG_DIR
+from .utils import create_root_widget
+from .utils import random_id
+from .utils import copy_attributes
+from .rig_ui_template import UI_SLIDERS, layers_ui, UI_REGISTER
+
 RIG_MODULE = "rigs"
 ORG_LAYER = [n == 31 for n in range(0, 32)]  # Armature layer that original bones should be moved to.
 MCH_LAYER = [n == 30 for n in range(0, 32)]  # Armature layer that mechanism bones should be moved to.

Modified: trunk/py/scripts/addons/rigify/metarig_menu.py
===================================================================
--- trunk/py/scripts/addons/rigify/metarig_menu.py	2013-02-15 18:46:36 UTC (rev 4281)
+++ trunk/py/scripts/addons/rigify/metarig_menu.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -22,6 +22,7 @@
 from string import capwords
 
 import bpy
+
 from . import utils
 
 

Added: trunk/py/scripts/addons/rigify/rig_lists.py
===================================================================
--- trunk/py/scripts/addons/rigify/rig_lists.py	                        (rev 0)
+++ trunk/py/scripts/addons/rigify/rig_lists.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -0,0 +1,83 @@
+#====================== BEGIN GPL LICENSE BLOCK ======================
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#======================= END GPL LICENSE BLOCK ========================
+
+import os
+
+from . import utils
+
+
+def get_rig_list(path):
+    """ Recursively searches for rig types, and returns a list.
+    """
+    rigs = []
+    MODULE_DIR = os.path.dirname(__file__)
+    RIG_DIR_ABS = os.path.join(MODULE_DIR, utils.RIG_DIR)
+    SEARCH_DIR_ABS = os.path.join(RIG_DIR_ABS, path)
+    files = os.listdir(SEARCH_DIR_ABS)
+    files.sort()
+
+    for f in files:
+        is_dir = os.path.isdir(os.path.join(SEARCH_DIR_ABS, f))  # Whether the file is a directory
+        if f[0] in {".", "_"}:
+            pass
+        elif f.count(".") >= 2 or (is_dir and "." in f):
+            print("Warning: %r, filename contains a '.', skipping" % os.path.join(SEARCH_DIR_ABS, f))
+        else:
+            if is_dir:
+                # Check directories
+                module_name = os.path.join(path, f).replace(os.sep, ".")
+                try:
+                    rig = utils.get_rig_type(module_name)
+                except ImportError as e:
+                    print("Rigify: " + str(e))
+                else:
+                    # Check if it's a rig itself
+                    if not hasattr(rig, "Rig"):
+                        # Check for sub-rigs
+                        ls = get_rig_list(os.path.join(path, f, ""))  # "" adds a final slash
+                        rigs.extend(["%s.%s" % (f, l) for l in ls])
+                    else:
+                        rigs += [f]
+
+            elif f.endswith(".py"):
+                # Check straight-up python files
+                t = f[:-3]
+                module_name = os.path.join(path, t).replace(os.sep, ".")
+                try:
+                    utils.get_rig_type(module_name).Rig
+                except (ImportError, AttributeError):
+                    pass
+                else:
+                    rigs += [t]
+    rigs.sort()
+    return rigs
+
+
+def get_collection_list(rig_list):
+    collection_list = []
+    for r in rig_list:
+        a = r.split(".")
+        if len(a) >= 2 and a[0] not in collection_list:
+            collection_list += [a[0]]
+    return collection_list
+
+
+# Public variables
+rig_list = get_rig_list("")
+collection_list = get_collection_list(rig_list)
+col_enum_list = [("All", "All", ""), ("None", "None", "")] + [(c, c, "") for c in collection_list]

Modified: trunk/py/scripts/addons/rigify/rigs/basic/copy.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/basic/copy.py	2013-02-15 18:46:36 UTC (rev 4281)
+++ trunk/py/scripts/addons/rigify/rigs/basic/copy.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -19,11 +19,12 @@
 # <pep8 compliant>
 
 import bpy
-from rigify.utils import copy_bone
-from rigify.utils import strip_org, make_deformer_name
-from rigify.utils import create_bone_widget
 
+from ...utils import copy_bone
+from ...utils import strip_org, make_deformer_name
+from ...utils import create_bone_widget
 
+
 class Rig:
     """ A "copy" rig.  All it does is duplicate the original bone and
         constrain it.

Modified: trunk/py/scripts/addons/rigify/rigs/basic/copy_chain.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/basic/copy_chain.py	2013-02-15 18:46:36 UTC (rev 4281)
+++ trunk/py/scripts/addons/rigify/rigs/basic/copy_chain.py	2013-02-16 08:12:03 UTC (rev 4282)
@@ -19,13 +19,14 @@
 # <pep8 compliant>
 
 import bpy
-from rigify.utils import MetarigError
-from rigify.utils import copy_bone
-from rigify.utils import connected_children_names
-from rigify.utils import strip_org, make_deformer_name
-from rigify.utils import create_bone_widget
 
+from ...utils import MetarigError
+from ...utils import copy_bone
+from ...utils import connected_children_names
+from ...utils import strip_org, make_deformer_name
+from ...utils import create_bone_widget
 
+
 class Rig:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list