There seems to be somewhat of a lack of HTML rendering for tkinter. While there is http://tkhtml.tcl.tk/ which looks like it is actively maintained and https://sourceforge.net/projects/grail/ which looks like it is not, they would be external dependencies and I know of no easy way how I could include them seamlessly as part of my project’s source code. So in order to provide moddiutils.tk.help.HelpBrowser as self-contained, integral part of patchmaster, I needed to write my own.
The tk.html subpackage of moddiutils contains an HTML viewer widget for tkinter, moddiutils.tk.html.Html. It inherits from tkinter.Text and provides a moddiutils.xml.Handler interface to fill it with a document.
The whole thing is strictly geared towards displaying help pages that are under the program author’s control, not for browsing random external web pages. This, together with it being very much incomplete yet means:
No JavaScript. No CSS. No attributes except href. Only image formats supported by tk (i.e. no PNG, no JPEG). Almost no tags to begin with (see below).
The actually supported HTML syntax is somewhat of a moving target, as I’m still experimenting with different parsers. What does work and is expected to continue to work is UTF-8 encoded xhtml without the use of entity references besides lt, amp and #…. Like this:
<?xml version='1.0' encoding='utf-8'?> <html><body> <h1>File Commander Help</h1> <p><a href='https://de.lipsum.com/'>Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit. Praesent vel odio dolor. Phasellus quis enim pulvinar, eleifend purus ut, congue tellus. Maecenas interdum est sit amet tristique efficitur. Mauris pretium <em>aliquam</em> egestas. Vestibulum vel placerat nulla. Sed sit amet nunc feugiat, convallis nisi sed, venenatis urna. Nam convallis ex magna, ut auctor tortor dapibus non. Aliquam eleifend, felis sit amet consectetur scelerisque, nunc nisl lobortis justo, eu convallis ligula dolor a ex. Sed ornare fringilla ex, ac rhoncus odio faucibus scelerisque. Sed vitae arcu tempor, condimentum sapien in, sagittis tortor. Pellentesque laoreet facilisis fermentum.</p> <p>&lt;: <<br/> &amp;: &<br/> &#9829;: ♥</p> </body></html>
As of 2019-08-17 moddiutils.tk.html.Html supports (more or less) these tags:
With the primary goal of stroking my ego so it becomes bigger (MY EGO!! Control your dirty mind!) and the secondary goal of providing a convenient testbed for moddiutils.tk.html.Html I have implemented a real (ah, well, “real”) webbrowser called “slotermeyer”. Being based on moddiutils.tk.html.Html it shares its limitations and quirks and then some.
You can run it from the directory containing the moddiutils directory (or from PYTHONPATH) as
python3 -m moddiutils.tk.html.slotermeyer
Optionally you can provide a file or URL to display as a parameter.