The wx.html
library provides classes for parsing and displaying HTML.
It is not intended to be a high-end HTML browser. If you are looking for something like that try http://www.mozilla.org/.
wxhtml
can be used as a generic rich text viewer - for example to display a nice About Box (like those of GNOME apps) or to display the result of database searching. There is a wx.FileSystem
class which allows you to use your own virtual file systems.
HtmlWindow
supports tag handlers. This means that you can easily extend html
library with new, unsupported tags. Not only that, you can even use your own application-specific tags!
There is a generic HtmlParser
class, independent of HtmlWindow
.
Class HtmlWindow
(derived from wx.ScrolledWindow
) is used to display HTML documents.
It has two important methods: LoadPage
and SetPage
. LoadPage loads and displays HTML file while SetPage displays directly the passed string. See the example:
mywin.LoadPage("test.htm") mywin.SetPage("htmlbody" \ "h1Error/h1" \ "Some error occurred :-H)" \ "/body/hmtl")Setting up HtmlWindow¶
Because HtmlWindow
is derived from wx.ScrolledWindow
and not from wx.Frame
, it doesnât have visible frame. But the user usually wants to see the title of HTML page displayed somewhere and the frameâs titlebar is the ideal place for it.
HtmlWindow
provides 2 methods in order to handle this: SetRelatedFrame
and SetRelatedStatusBar
. See the example:
html = wx.html.HtmlWindow(self) html.SetRelatedFrame(self, "HTML : %%s") html.SetRelatedStatusBar(0)
The first command associates the HTML object with its parent frame (this points to wx.Frame
object there) and sets the format of the title. Page title âHello, world!â will be displayed as âHTML : Hello, world!â in this example.
The second command sets which frameâs status bar should be used to display browserâs messages (such as âLoadingâ¦â or âDoneâ or hypertext links).
Customizing HtmlWindow¶You can customize HtmlWindow
by setting font size, font face and borders (space between border of window and displayed HTML). Related functions:
WriteCustomization
The last two functions are used to store user customization info wx.ConfigBase
stuff (for example in the registry under Windows, or in a dotfile under Unix).
The wx.html
library provides printing facilities with several levels of complexity. The easiest way to print an HTML document is to use the HtmlEasyPrinting
class.
It lets you print HTML documents with only one command and you donât have to worry about deriving from the wx.Printout
class at all. It is only a simple wrapper around the HtmlPrintout
, normal wxPython printout class.
And finally there is the low level class HtmlDCRenderer
which you can use to render HTML into a rectangular area on any DC.
It supports rendering into multiple rectangles with the same width. (The most common use of this is placing one rectangle on each page or printing into two columns.)
Help Files Format¶wx.html
library can be used to show an help manual to the user; in fact, it supports natively (through HtmlHelpController
) a reduced version of MS HTML Workshop format.
A book consists of three files: the header file, the contents file and the index file.
You can make a regular zip archive of these files, plus the HTML and any image files, for HTML (or helpview) to read; and the ".zip"
file can optionally be renamed to ".htb"
.
Contents file has HTML syntax and it can be parsed by regular HTML parser. It contains exactly one list (<ul>
⦠</ul>
statement):
<ul> <li><object type="text/sitemap"> <param name="Name" value="@topic name@"> <param name="ID" value=@numeric_id@> <param name="Local" value="@filename.htm@"> </object></li> <li><object type="text/sitemap"> <param name="Name" value="@topic name@"> <param name="ID" value=@numeric_id@> <param name="Local" value="@filename.htm@"> </object></li> </ul>
You can modify value attributes of param tags. The topic name is name of chapter/topic as is displayed in contents, filename.htm is the HTML page name (relative to the ".hhp"
file) and numeric_id is optional - it is used only when you use Display
.
Items in the list may be nested - one <li>
statement may contain a <ul>
sub-statement:
<ul> <li><object type="text/sitemap"> <param name="Name" value="Top node"> <param name="Local" value="top.htm"> </object></li> <ul> <li><object type="text/sitemap"> <param name="Name" value="subnode in topnode"> <param name="Local" value="subnode1.htm"> </object></li> </ul> <li><object type="text/sitemap"> <param name="Name" value="Another Top"> <param name="Local" value="top2.htm"> </object></li> </ul>Index file (.hhk)¶
Index files have same format as contents files except that ID params are ignored and sublists are not allowed.
Input Filters¶The wx.html
library provides a mechanism for reading and displaying files of many different file formats.
LoadPage
can load not only HTML files but any known file. To make a file type known to HtmlWindow
you must create a HtmlFilter
filter and register it using AddFilter
.
This article describes mechanism used by HtmlWinParser
and HtmlWindow
to parse and display HTML documents.
You can divide any text (or HTML) into small fragments. Letâs call these fragments cells. Cell is for example one word, horizontal line, image or any other part of document. Each cell has width and height (except special âmagicâ cells with zero dimensions - e.g. colour changers or font changers). See HtmlCell
.
Container is kind of cell that may contain sub-cells. Its size depends on number and sizes of its sub-cells (and also depends on width of window). See HtmlContainerCell
, Layout
. This image shows the cells and containers:
HtmlWinParser
provides a user-friendly way of managing containers. It is based on the idea of opening and closing containers.
Use OpenContainer
to open new a container within an already opened container. This new container is a sub-container of the old one. (If you want to create a new container with the same depth level you can call CloseContainer()
; OpenContainer()
; ).
Use CloseContainer
to close the container. This doesnât create a new container with same depth level but it returns âcontrolâ to the parent container. See explanation:
There clearly must be same number of calls to OpenContainer as to CloseContainer.
Example¶This code creates a new paragraph (container at same depth level) with âHello, world!â:
myParser.CloseContainer() c = myParser.OpenContainer() myParser.AddText("Hello, ") myParser.AddText("world!") myParser.CloseContainer() myParser.OpenContainer()
and here is image of the situation:
You can see that there was an opened container before the code was executed. We closed it, created our own container, then closed our container and opened new container.
The result was that we had same depth level after executing. This is general rule that should be followed by tag handlers: leave depth level of containers unmodified (in other words, number of OpenContainer and CloseContainer calls should be same within HandleTag
âs body).
Note
Notice that it would be usually better to use InsertCell
instead of adding text to the parser directly.
The wx.html
library provides architecture of pluggable tag handlers. Tag handler is class that understands particular HTML tag (or tags) and is able to interpret it.
HtmlWinParser
has a static table of modules. Each module contains one or more tag handlers. Each time a new HtmlWinParser
object is constructed all modules are scanned and handlers are added to HtmlParserâs list of available handlers.
Common tag handlerâs HandleTag
method works in four steps:
Save state of parent parser into local variables
Change parser state according to tagâs params
Parse text between the tag and paired ending tag (if present)
Restore original parser state
See HtmlWinParser
for methods for modifying parserâs state. In general you can do things like opening/closing containers, changing colors, fonts etcâ¦
See the wx.lib.wxpTag
on how to provide your own tag handlers.
The handler is derived from HtmlWinTagHandler
(or directly from HtmlTagHandler
).
html
¶
wx.html
is not a full implementation of HTML standard. Instead, it supports most common tags so that it is possible to display simple HTML documents with it. (For example it works fine with pages created in Netscape Composer or generated by tex2rtf).
Following tables list all tags known to wx.html
, together with supported parameters.
A tag has general form of tagname
param_1 param_2 ⦠param_n where param_i is either paramname="paramvalue"
or paramname=paramvalue
- these two are equivalent. Unless stated otherwise, wx.html
is case- insensitive.
We will use these substitutions in tags descriptions:
[alignment]
CENTER
LEFT
RIGHT
JUSTIFY
[v_alignment]
TOP
BOTTOM
CENTER
[color]
HTML 4.0-compliant colour specification
[fontsize]
-2
-1
+0
+1
+2
+3
+4
1
2
3
4
5
6
7
[pixels]
integer value that represents dimension in pixels
[percent]
i%
where i is integer
[url]
an URL
[string]
text string
[coords]
c(1),c(2),c(3),â¦,c(n)
where c(i) is integer
List of supported tags¶A
NAME=[string]
HREF=[url]
TARGET=[target window spec]
ADDRESS
AREA
SHAPE=POLY
SHAPE=CIRCLE
SHAPE=RECT
COORDS=[coords]
HREF=[url]
BIG
BLOCKQUOTE
BODY
TEXT=[color]
LINK=[color]
BGCOLOR=[color]
BR
ALIGN=[alignment]
CENTER
CITE
CODE
DD
DIV
ALIGN=[alignment]
DL
DT
EM
FONT
COLOR=[color]
SIZE=[fontsize]
FACE=[comma-separated list of facenames]
HR
ALIGN=[alignment]
SIZE=[pixels]
WIDTH=[percent|pixels]
NOSHADE
H1
H2
H3
H4
H5
H6
I
IMG
SRC=[url]
WIDTH=[percent|pixels]
HEIGHT=[pixels]
ALIGN=TEXTTOP
ALIGN=CENTER
ALIGN=ABSCENTER
ALIGN=BOTTOM
USEMAP=[url]
KBD
LI
MAP
NAME=[string]
META
HTTP-EQUIV=âContent-Typeâ
CONTENT=[string]
OL
P
ALIGN=[alignment]
PRE
SAMP
SMALL
SPAN
STRIKE
STRONG
SUB
SUP
TABLE
ALIGN=[alignment]
WIDTH=[percent|pixels]
BORDER=[pixels]
VALIGN=[v_alignment]
BGCOLOR=[color]
CELLSPACING=[pixels]
CELLPADDING=[pixels]
TD
ALIGN=[alignment]
VALIGN=[v_alignment]
BGCOLOR=[color]
WIDTH=[percent|pixels]
COLSPAN=[pixels]
ROWSPAN=[pixels]
NOWRAP
TH
ALIGN=[alignment]
VALIGN=[v_alignment]
BGCOLOR=[color]
WIDTH=[percent|pixels]
COLSPAN=[pixels]
ROWSPAN=[pixels]
TITLE
TR
ALIGN=[alignment]
VALIGN=[v_alignment]
BGCOLOR=[color]
TT
U
UL
List of supported styles¶wx.html
doesnât really have CSS support but it does support a few simple styles: you can use "text-align"
, "width"
, "vertical-align"
and "background"
with all elements and for SPAN
elements a few other styles are additionally recognized:
color
font-family
font-size
(only in point units)
font-style
(only âobliqueâ, âitalicâ and ânormalâ values are supported)
font-weight
(only âboldâ and ânormalâ values are supported)
text-decoration
(only âunderlineâ value is supported)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4