Thomas,
Below I've pasted a leo subtree containing a demo @button which will display html hyperlinks to nodes inside a QTextBrowser.
To use it copy the xml and in a leo outline, "paste as node". Create a script button from it and after clicking the button, a new pane should appear containing hyperlinks to the selected node and each of its subtree nodes. Clicking on those hyperlinks will move the selection to the node corresponding to the clicked link.
QT dock-based display only.
I thought I'd share in case it helps you along with what you are doing. The code is a little rough around the edges, but since it is a complete working example, it might be useful to you.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo:
http://leoeditor.com/leo_toc.html -->
<leo_file xmlns:leo="
http://leoeditor.com/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2"/>
<vnodes>
<v t="btheado.20200226212619.1"><vh>@button node linked html</vh>
<v t="btheado.20200226212619.10"><vh>display_widget_in_leo_pane()</vh></v>
<v t="btheado.20200226212619.11"><vh>display_html</vh></v>
<v t="btheado.20200226214559.1"><vh>node_link</vh></v>
<v t="btheado.20200226212619.12"><vh>display_node_linked_html</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="btheado.20200226212619.1">@language python
from PyQt5 import QtCore, QtWidgets
@others
# Just some sample node links, one on each line
html = "\n".join([
node_link(p) + "<br/>"
for p in p.self_and_subtree()
])
# Display the html in a docked widget
display_node_linked_html(c, html)
</t>
<t tx="btheado.20200226212619.10">def display_widget_in_leo_pane(g, c, w, name):
"""
w is the widget to display
name is the name the widget should appear in pane menu
"""
dw = c.frame.top
c.user_dict.setdefault('btheado_docks', {})
dock_dict = c.user_dict['btheado_docks']
dock = dock_dict.get(name)
if not dock:
dock = g.app.gui.create_dock_widget(
closeable=True, moveable=True, height=50, name=name)
dock_dict[name] = dock
dw.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
dock.setWidget(w)
dock.show()
#
g.es(dock.widget())
</t>
<t tx="btheado.20200226212619.11">def display_html(html, name = 'test html'):
w = QtWidgets.QTextBrowser()
w.setHtml(html)
display_widget_in_leo_pane(g, c, w, name)
return w</t>
<t tx="btheado.20200226212619.12">def display_node_linked_html(c, html):
def link_clicked(url):
if url.isRelative():
if url.path().startswith('node/'):
gnx = url.path().split("/")[-1]
target = next((
p
for p in c.all_unique_positions()
if p.v.gnx == gnx
), None)
if target:
w.setSource(QtCore.QUrl())
c.selectPosition(target)
# Without this, there is possibility of the
# position not being displayed and subsequent
# expand of the node not showing all descendants
c.redraw()
else:
g.es(f"Could not find node with gnx: {gnx}")
else:
g.es(f"Don't know how to handle url: {url.toString()}")
else:
g.es(f"Don't know how to handle url: {url.toString()}")
w = display_html(html)
w.anchorClicked.connect(link_clicked)</t>
<t tx="btheado.20200226214559.1">def node_link(p):
return f"""
<a style="color: violet; text-decoration: none;"
href="node/{p.v.gnx}">{p.h}</a>
"""</t>
</tnodes>
</leo_file>