[Bf-translations-svn] SVN commit: /data/svn/bf-translations [697] trunk/po/tools/_update_msg.py: Fix to have access to py ops properties without that dummy hack I had to use (patch http://projects.blender.org/tracker/download.php/9/498/29666/18807/ bpy_rna.patch ).

bf-translations at blender.org bf-translations at blender.org
Thu Jun 7 19:35:58 CEST 2012


Revision: 697
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=697
Author:   mont29
Date:     2012-06-07 17:35:47 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
Fix to have access to py ops properties without that dummy hack I had to use (patch http://projects.blender.org/tracker/download.php/9/498/29666/18807/bpy_rna.patch ).

There is still at least two problems with py operators, imho:
*you find under bpy.types the Operator sub-classes of py ops, while for C ops you get OperatorProperties subclasses (which is much more useful!).
*When you register a py op (through bpy.utils.register_xxx), its OperatorProperties sub-class isn't "created" (i.e. not found by bpy.types.OperatorProperties.__subclasses__()), you have to e.g. run bpy.ops.foo.py_op_bar.get_rna() for it to become available!

But RNA is complex, py/C binding is complex, so when both are mixed together... /me runs.

Modified Paths:
--------------
    trunk/po/tools/_update_msg.py

Modified: trunk/po/tools/_update_msg.py
===================================================================
--- trunk/po/tools/_update_msg.py	2012-06-06 20:30:32 UTC (rev 696)
+++ trunk/po/tools/_update_msg.py	2012-06-07 17:35:47 UTC (rev 697)
@@ -63,24 +63,22 @@
         # extend with all internal operators
         # note that this uses internal api introspection functions
         # all possible operator names
-        op_names = list(sorted(set(
-            [cls.bl_rna.identifier for cls in
-             bpy.types.OperatorProperties.__subclasses__()] +
-            [cls.bl_rna.identifier for cls in
-             bpy.types.Operator.__subclasses__()] +
-            [cls.bl_rna.identifier for cls in
-             bpy.types.OperatorMacro.__subclasses__()]
-            )))
+        op_ids = set(cls.bl_rna.identifier for cls in
+                     bpy.types.OperatorProperties.__subclasses__()) | \
+                 set(cls.bl_rna.identifier for cls in
+                     bpy.types.Operator.__subclasses__()) | \
+                 set(cls.bl_rna.identifier for cls in
+                     bpy.types.OperatorMacro.__subclasses__())
 
         get_instance = __import__("_bpy").ops.get_instance
         path_resolve = type(bpy.context).__base__.path_resolve
-        for idname in op_names:
+        for idname in op_ids:
             op = get_instance(idname)
             if 'INTERNAL' in path_resolve(op, "bl_options"):
                 blacklist_rna_class.append(idname)
 
         # ---------------------------------------------------------------------
-        # Collect builtin classes we dont need to doc
+        # Collect builtin classes we don't need to doc
         blacklist_rna_class.append("Property")
         blacklist_rna_class.extend(
                 [cls.__name__ for cls in
@@ -104,9 +102,9 @@
     blacklist_rna_class = classBlackList()
 
     def filterRNA(bl_rna):
-        id = bl_rna.identifier
-        if id in blacklist_rna_class:
-            print("  skipping", id)
+        rid = bl_rna.identifier
+        if rid in blacklist_rna_class:
+            print("  skipping", rid)
             return True
         return False
 
@@ -341,19 +339,23 @@
         used_ext = {ext.module for ext in userpref.addons}
         support = {"OFFICIAL"}
         # collect the categories that can be filtered on
-        addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(addon_utils.addons_fake_modules)]
+        addons = [(mod, addon_utils.module_bl_info(mod)) for mod in
+                  addon_utils.modules(addon_utils.addons_fake_modules)]
 
         for mod, info in addons:
-            if mod in used_ext or info["support"] not in support:
+            module_name = mod.__name__
+            if module_name in used_ext or info["support"] not in support:
                 continue
-            module_name = mod.__name__
+            print("    Enabling module ", module_name)
             bpy.ops.wm.addon_enable(module=module_name)
 
         # XXX There are currently some problems with bpy/rna... *Very* tricky to solve!
         #     So this is a hack to make all newly added operator visible by
         #     bpy.types.OperatorProperties.__subclasses__()
-        for el in dir(bpy.types):
-            getattr(bpy.types, el)
+        for cat in dir(bpy.ops):
+            cat = getattr(bpy.ops, cat)
+            for op in dir(cat):
+                getattr(cat, op).get_rna()
 
     # check for strings like ": %d"
     ignore = ("%d", "%f", "%s", "%r",  # string formatting



More information about the Bf-translations-svn mailing list