I have made a lot of progress on re-implementing *Viewrendered2 *in the QT5 
era, and I wanted to share where I am with it.

To quickly summarize what VR2 added to *viewrendered *for @rst 
(Restructured Text) trees:
   - It can render an entire @rst tree, rather than a singe node.
   - It can export the rendering to an external browser.
   - It can display syntax-colorized code blocks that are marked with a 
"@language python" directive.  This can be easier than using the ''.. 
code:: python" RsT syntax.
   - It can display only the code blocks, without any non-code text.
   - It can execute the code in a node or the entire tree, and display any 
output below the code block.

Unfortunately, VR2 only worked with Qt4.  I've been working on getting it 
to use Qt5.  I'm calling my version *viewrendered3*.  I decided to start 
from *viewrendered*, since EKR has gotten it integrated into the new 
QT5/docks GUI framework, and I thought it would be too hard to modify VR2 
to make all that work.  So here's what I've gotten working so far. This is 
all for a single node, since I'm not walking the tree yet. 

   1. Renders code blocks marked with the @language python directive.
   2. Renders MathJax math in the rendering pane (this was non-obvious to 
get going).
   3. Has the toolbar and menu of the original VR2.  The only part of that 
which is hooked up so far is the "Export" button.
   4. Renders images with local file locations (this turned out to be kind 
of tricky).
  
For non-@rst nodes, it works the same as *viewrendered*, since it uses the 
same code.  In fact, wherever possible I'm delegating to the VR code, to 
minimize the chances of getting out of sync with it.  I'm using delegation 
rather than inheritance because it seemed I had fewer problems when I 
wanted to override certain code.

To get item 2, MathJax, working, I had to change from the default QTextBrowser 
to a QWebEngineView, because it has to execute MathJax script, and the 
QTextBrowser 
doesn't seem to, even though it does display an HTML string.  So I have to 
swap in the web browser widget (QWebEngineView*)* for @rst nodes.   In the 
code it's called a QtWebKitWidgets.QWebView, but by EKR's import magic, 
it's really a QWebEngineView.

To get item 4 working, I had to discover that the setHtml() method actually 
passes in the html as a data: url.  You can't have relative locations (like 
for an image) because a  data: url doesn't really have a location per se.  
So I took the route of saving the HTML string to a temporary file, which I 
had to do anyway for sending the rendering to an external browser.  The 
*QWebEngineView 
*can load the local file without trouble.

So it's been painful, but progress is good.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/12072ab2-7bed-4bac-9918-6e13eea36dc5%40googlegroups.com.

Reply via email to