[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47341] trunk/blender: experenental manual linking from the UI.

Campbell Barton ideasman42 at gmail.com
Fri Jun 1 22:38:41 CEST 2012


Revision: 47341
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47341
Author:   campbellbarton
Date:     2012-06-01 20:38:40 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
experenental manual linking from the UI. realize this is an issue which is not agreed on so probably this will be disabled for release.

the data is stored here so more dev can commit:

./release/scripts/addons/modules/rna_wiki_reference.py

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/wm.py
    trunk/blender/source/blender/editors/interface/interface_handlers.c

Modified: trunk/blender/release/scripts/startup/bl_operators/wm.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/wm.py	2012-06-01 20:28:53 UTC (rev 47340)
+++ trunk/blender/release/scripts/startup/bl_operators/wm.py	2012-06-01 20:38:40 UTC (rev 47341)
@@ -799,6 +799,87 @@
         return {'FINISHED'}
 
 
+
+def _wm_doc_get_id(doc_id, do_url=True, url_prefix=""):
+    id_split = doc_id.split('.')
+    url = rna = None
+
+    if len(id_split) == 1:  # rna, class
+        if do_url:
+            url = '%s/bpy.types.%s.html' % (url_prefix, id_split[0])
+        else:
+            rna = 'bpy.types.%s' % id_split[0]
+
+    elif len(id_split) == 2:  # rna, class.prop
+        class_name, class_prop = id_split
+
+        if hasattr(bpy.types, class_name.upper() + '_OT_' + class_prop):
+            if do_url:
+                url = ("%s/bpy.ops.%s.html#bpy.ops.%s.%s" % (url_prefix, class_name, class_name, class_prop))
+            else:
+                rna = "bpy.ops.%s.%s" % (class_name, class_prop)
+        else:
+
+            # detect if this is a inherited member and use that name instead
+            rna_parent = getattr(bpy.types, class_name).bl_rna
+            rna_prop = rna_parent.properties[class_prop]
+            rna_parent = rna_parent.base
+            while rna_parent and rna_prop == rna_parent.properties.get(class_prop):
+                class_name = rna_parent.identifier
+                rna_parent = rna_parent.base
+
+            if do_url:
+                url = ("%s/bpy.types.%s.html#bpy.types.%s.%s" % (url_prefix, class_name, class_name, class_prop))
+            else:
+                rna = ("bpy.types.%s.%s" % (class_name, class_prop))
+    
+    return url if do_url else rna
+
+
+class WM_OT_doc_view_manual(Operator):
+    '''Load online manual'''
+    bl_idname = "wm.doc_view_manual"
+    bl_label = "View Manual"
+
+    doc_id = doc_id
+
+    @staticmethod
+    def _find_reference(rna_id, url_mapping):
+        import re
+        for key, value in sorted(url_mapping.items()):
+            match = re.match(key, rna_id)
+            if match:
+                return value
+        return None
+
+    def execute(self, context):
+        rna_id = _wm_doc_get_id(self.doc_id, do_url=False)
+        if rna_id is None:
+            return {'PASS_THROUGH'}
+
+        import rna_wiki_reference
+        # rna_ref = rna_wiki_reference.url_mapping.get(rna_id)
+        rna_ref = self._find_reference(rna_id, rna_wiki_reference.url_manual_mapping)
+
+        if rna_ref is None:
+            self.report({'WARNING'}, "No reference available '%s', "
+                                     "Update info in %r" %
+                                     (self.doc_id, rna_wiki_reference.__file__))
+
+        import sys
+        del sys.modules["rna_wiki_reference"]
+
+        if rna_ref is None:
+            return {'CANCELLED'}
+        else:
+            url = rna_wiki_reference.url_manual_prefix + rna_ref
+
+        import webbrowser
+        webbrowser.open(url)
+
+        return {'FINISHED'}
+
+
 class WM_OT_doc_view(Operator):
     '''Load online reference docs'''
     bl_idname = "wm.doc_view"
@@ -812,39 +893,10 @@
         _prefix = ("http://www.blender.org/documentation/blender_python_api_%s" %
                    "_".join(str(v) for v in bpy.app.version))
 
-    def _nested_class_string(self, class_string):
-        ls = []
-        class_obj = getattr(bpy.types, class_string, None).bl_rna
-        while class_obj:
-            ls.insert(0, class_obj)
-            class_obj = class_obj.nested
-        return '.'.join(class_obj.identifier for class_obj in ls)
-
     def execute(self, context):
         id_split = self.doc_id.split('.')
-        if len(id_split) == 1:  # rna, class
-            url = '%s/bpy.types.%s.html' % (self._prefix, id_split[0])
-        elif len(id_split) == 2:  # rna, class.prop
-            class_name, class_prop = id_split
-
-            if hasattr(bpy.types, class_name.upper() + '_OT_' + class_prop):
-                url = ("%s/bpy.ops.%s.html#bpy.ops.%s.%s" %
-                       (self._prefix, class_name, class_name, class_prop))
-            else:
-
-                # detect if this is a inherited member and use that name instead
-                rna_parent = getattr(bpy.types, class_name).bl_rna
-                rna_prop = rna_parent.properties[class_prop]
-                rna_parent = rna_parent.base
-                while rna_parent and rna_prop == rna_parent.properties.get(class_prop):
-                    class_name = rna_parent.identifier
-                    rna_parent = rna_parent.base
-
-                #~ class_name_full = self._nested_class_string(class_name)
-                url = ("%s/bpy.types.%s.html#bpy.types.%s.%s" %
-                       (self._prefix, class_name, class_name, class_prop))
-
-        else:
+        url = _wm_doc_get_id(self.doc_id, do_url=True, url_prefix=self._prefix)
+        if url is None:
             return {'PASS_THROUGH'}
 
         import webbrowser

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-06-01 20:28:53 UTC (rev 47340)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-06-01 20:38:40 UTC (rev 47341)
@@ -4597,6 +4597,11 @@
 			BLI_snprintf(buf, sizeof(buf), "%s.%s",
 			             RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
 
+			WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
+			RNA_string_set(&ptr_props, "doc_id", buf);
+			uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+			            ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+
 			WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
 			RNA_string_set(&ptr_props, "doc_id", buf);
 			uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Python Documentation"),
@@ -4614,18 +4619,26 @@
 		else if (but->optype) {
 			WM_operator_py_idname(buf, but->optype->idname);
 
+
+			WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
+			RNA_string_set(&ptr_props, "doc_id", buf);
+			uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+			            ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+
 			WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
 			RNA_string_set(&ptr_props, "doc_id", buf);
 			uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Python Documentation"),
 			            ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
 
-
+			/* XXX inactive option, not for public! */
+#if 0
 			WM_operator_properties_create(&ptr_props, "WM_OT_doc_edit");
 			RNA_string_set(&ptr_props, "doc_id", buf);
 			RNA_string_set(&ptr_props, "doc_new", but->optype->description);
 
 			uiItemFullO(layout, "WM_OT_doc_edit", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Submit Description"),
 			            ICON_NONE, ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
+#endif
 		}
 	}
 




More information about the Bf-blender-cvs mailing list