diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2023-10-25 20:39:49 +0200 |
---|---|---|
committer | Jeff Long <willcode4@gmail.com> | 2023-12-15 10:04:29 -0500 |
commit | a53b3bd92bae5b6fba15c2538be7dd321a90f598 (patch) | |
tree | cc8ba6b07021b96f967ec8d21210bc2431811ad7 | |
parent | fec: add FEC_API to CCSDS Reed-Solomon functions (diff) | |
download | gnuradio-a53b3bd92bae5b6fba15c2538be7dd321a90f598.tar.xz gnuradio-a53b3bd92bae5b6fba15c2538be7dd321a90f598.zip |
GRC: enable setting of documentation URLs, relative or absolute in yaml
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
(cherry picked from commit d528c2074fe5473ab521801dfd3454680029c26c)
Signed-off-by: Jeff Long <willcode4@gmail.com>
-rw-r--r-- | grc/core/blocks/_build.py | 19 | ||||
-rw-r--r-- | grc/core/blocks/block.py | 1 | ||||
-rw-r--r-- | grc/core/schema_checker/block.py | 1 | ||||
-rw-r--r-- | grc/gui/PropsDialog.py | 27 |
4 files changed, 40 insertions, 8 deletions
diff --git a/grc/core/blocks/_build.py b/grc/core/blocks/_build.py index 6fd917118..310d55ae7 100644 --- a/grc/core/blocks/_build.py +++ b/grc/core/blocks/_build.py @@ -18,9 +18,20 @@ from ._flags import Flags from ._templates import MakoTemplates -def build(id, label='', category='', flags='', documentation='', - value=None, asserts=None, - parameters=None, inputs=None, outputs=None, templates=None, cpp_templates=None, **kwargs) -> Type[Block]: +def build(id, + label='', + category='', + flags='', + documentation='', + value=None, + asserts=None, + parameters=None, + inputs=None, + outputs=None, + templates=None, + cpp_templates=None, + doc_url=None, + **kwargs) -> Type[Block]: block_id = id cls = type(str(block_id), (Block,), {}) @@ -62,6 +73,8 @@ def build(id, label='', category='', flags='', documentation='', translations=cpp_templates.get('translations', []), declarations=cpp_templates.get('declarations', ''), ) + + cls.doc_url = doc_url if doc_url else "" # todo: MakoTemplates.compile() to check for errors cls.value = _single_mako_expr(value, block_id) diff --git a/grc/core/blocks/block.py b/grc/core/blocks/block.py index 4b36057a6..55a168784 100644 --- a/grc/core/blocks/block.py +++ b/grc/core/blocks/block.py @@ -43,6 +43,7 @@ class Block(Element): vtype = '' # This is only used for variables when we want C++ output flags = Flags('') documentation = {'': ''} + doc_url = '' value = None asserts = [] diff --git a/grc/core/schema_checker/block.py b/grc/core/schema_checker/block.py index 801c68b90..420773db9 100644 --- a/grc/core/schema_checker/block.py +++ b/grc/core/schema_checker/block.py @@ -64,6 +64,7 @@ BLOCK_SCHEME = expand( item_scheme=CPP_TEMPLATES_SCHEME), documentation=str, + doc_url=str, grc_source=str, file_format=Spec(types=int, required=True, item_scheme=None), diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py index 9e46e266d..1317bc5c9 100644 --- a/grc/gui/PropsDialog.py +++ b/grc/gui/PropsDialog.py @@ -11,6 +11,8 @@ from gi.repository import Gtk, Gdk, GObject, Pango from . import Actions, Utils, Constants from .Dialogs import SimpleTextDisplay +from urllib.parse import urljoin, urlparse + class PropsDialog(Gtk.Dialog): """ @@ -69,6 +71,7 @@ class PropsDialog(Gtk.Dialog): self._docs_box.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self._docs_vbox = Gtk.VBox(homogeneous=False, spacing=0) + # TODO: left align self._docs_box.add(self._docs_vbox) self._docs_link = Gtk.Label(use_markup=True) self._docs_vbox.pack_start(self._docs_link, False, False, 0) @@ -213,17 +216,31 @@ class PropsDialog(Gtk.Dialog): buf.delete(buf.get_start_iter(), buf.get_end_iter()) pos = buf.get_end_iter() + in_tree = self._block.category and self._block.category[0] == "Core" + # Add link to wiki page for this block, at the top, as long as it's not an OOT block if self._block.is_connection: self._docs_link.set_markup('Connection') - elif self._block.category and self._block.category[0] == "Core": - note = "Wiki Page for this Block: " + elif in_tree: + # For in-tree modules, use prefix as configured prefix = self._config.wiki_block_docs_url_prefix + else: + prefix = "" + + suffix = None + if self._block.doc_url: + suffix = self._block.doc_url + elif in_tree: suffix = self._block.label.replace(" ", "_") - href = f'<a href="{prefix+suffix}">Visit Wiki Page</a>' - self._docs_link.set_markup(href) + + if suffix: + url = urljoin(prefix, suffix) + icon = "🗗 " + if urlparse(url).scheme not in ("", "file"): + icon += "🌐" + self._docs_link.set_markup(f'<a href="{url}">{icon} Visit Documentation Page</a>') else: - self._docs_link.set_markup('Out of Tree Block') + self._docs_link.set_markup('Out of Tree Block, No documentation URL specified') docstrings = self._block.documentation.copy() if not docstrings: |