Menu

moddiutils.tk.html

Stefan Meinlschmidt
Attachments

moddiutils.tk.html

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.

Limitations

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).

What works, more or less

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>&amp;lt;: &lt;<br/>
       &amp;amp;: &amp;<br/>
       &amp;#9829;: &#9829;</p>
</body></html>

As of 2019-08-17 moddiutils.tk.html.Html supports (more or less) these tags:

  • a href='...'
  • em
  • strong
  • h1–h6
  • p
  • br
  • tt
  • ul
  • ol
  • li
  • img src='...' (GIF, PBM, PPM only)

ME 1337 HAXOR, ME WRITE BR0WSER FOR TEH INTARWEBS!!!1

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.


Related

Wiki: Home
Wiki: moddiutils

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.