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
This commit is contained in:
Campbell Barton 2012-06-01 20:38:40 +00:00
parent e94e7b4c7e
commit 0dc84e64e7
2 changed files with 95 additions and 33 deletions

@ -799,6 +799,85 @@ class WM_OT_path_open(Operator):
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):
from re import match
for pattern, url_suffix in url_mapping:
if match(pattern, rna_id):
return url_suffix
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 = 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 +891,9 @@ class WM_OT_doc_view(Operator):
_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

@ -4597,6 +4597,11 @@ static int ui_but_menu(bContext *C, uiBut *but)
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 @@ static int ui_but_menu(bContext *C, uiBut *but)
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
}
}