ability to register your own online manual callbacks - useful for 3rd party addon developers, who may want to link to their own URL's.

This commit is contained in:
Campbell Barton 2012-08-25 14:07:51 +00:00
parent 71d1b09708
commit a7ec09aef9
2 changed files with 52 additions and 17 deletions

@ -33,6 +33,7 @@ __all__ = (
"refresh_script_paths",
"register_class",
"register_module",
"register_manual_map",
"resource_path",
"script_path_user",
"script_path_pref",
@ -56,7 +57,6 @@ import addon_utils as _addon_utils
_script_module_dirs = "startup", "modules"
def _test_import(module_name, loaded_modules):
use_time = _bpy.app.debug_python
@ -595,3 +595,40 @@ def unregister_module(module, verbose=False):
traceback.print_exc()
if verbose:
print("done.\n")
# -----------------------------------------------------------------------------
# Manual lookups, each function has to return a basepath and a sequence
# of...
# we start with the built-in default mapping
def _blender_default_map():
import sys
import rna_wiki_reference as ref_mod
ret = (ref_mod.url_manual_prefix, ref_mod.url_manual_mapping)
# avoid storing in memory
del sys.modules["rna_wiki_reference"]
return ret
# hooks for doc lookups
_manual_map = [_blender_default_map]
def register_manual_map(manual_hook):
_manual_map.append(manual_hook)
def unregister_manual_map(manual_hook):
_manual_map.remove(manual_hook)
def manual_map():
# reverse so default is called last
for cb in reversed(_manual_map):
try:
prefix, url_manual_mapping = cb()
except:
print("Error calling %r" % cb)
import traceback
traceback.print_exc()
continue
yield prefix, url_manual_mapping

@ -862,26 +862,24 @@ class WM_OT_doc_view_manual(Operator):
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)
url = None
if rna_ref is None:
self.report({'WARNING'}, "No reference available '%s', "
"Update info in %r" %
(self.doc_id, rna_wiki_reference.__file__))
for prefix, url_manual_mapping in bpy.utils.manual_map():
rna_ref = self._find_reference(rna_id, url_manual_mapping)
if rna_ref is not None:
url = prefix + rna_ref
break
import sys
del sys.modules["rna_wiki_reference"]
if rna_ref is None:
if url is None:
self.report({'WARNING'}, "No reference available %r, "
"Update info in 'rna_wiki_reference.py' "
" or callback to bpy.utils.manual_map()" %
self.doc_id)
return {'CANCELLED'}
else:
url = rna_wiki_reference.url_manual_prefix + rna_ref
import webbrowser
webbrowser.open(url)
return {'FINISHED'}
import webbrowser
webbrowser.open(url)
return {'FINISHED'}
class WM_OT_doc_view(Operator):