.. include:: headings.inc .. _html overview: ================================== |phoenix_title| **HTML Overview** ================================== The :mod:`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/. :mod:`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 :class:`wx.FileSystem` class which allows you to use your own virtual file systems. :class:`~wx.html.HtmlWindow` supports tag handlers. This means that you can easily extend :mod:`html` library with new, unsupported tags. Not only that, you can even use your own application-specific tags! There is a generic :class:`~wx.html.HtmlParser` class, independent of :class:`~wx.html.HtmlWindow`. .. _html quick start: HTML quick start ---------------- Displaying HTML ~~~~~~~~~~~~~~~~ Class :class:`~wx.html.HtmlWindow` (derived from :class:`wx.ScrolledWindow`) is used to display HTML documents. It has two important methods: :meth:`~wx.html.HtmlWindow.LoadPage` and :meth:`~wxhtml.HtmlWindow.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 :class:`~wx.html.HtmlWindow` is derived from :class:`wx.ScrolledWindow` and not from :class:`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. :class:`~wx.html.HtmlWindow` provides 2 methods in order to handle this: :meth:`~wx.html.HtmlWindow.SetRelatedFrame` and :meth:`~wx.html.HtmlWindow.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 :class:`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 :class:`~wx.html.HtmlWindow` by setting font size, font face and borders (space between border of window and displayed HTML). Related functions: - :meth:`~wx.html.HtmlWindow.SetFonts` - :meth:`~wx.html.HtmlWindow.SetBorders` - :meth:`~wx.html.HtmlWindow.ReadCustomization` - :meth:`~wx,html.HtmlWindow.WriteCustomization` The last two functions are used to store user customization info :class:`wx.ConfigBase` stuff (for example in the registry under Windows, or in a dotfile under Unix). HTML Printing -------------- The :mod:`wx.html` library provides printing facilities with several levels of complexity. The easiest way to print an HTML document is to use the :class:`~wx.html.HtmlEasyPrinting` class. It lets you print HTML documents with only one command and you don't have to worry about deriving from the :class:`wx.Printout` class at all. It is only a simple wrapper around the :class:`~wx.html.HtmlPrintout`, normal wxPython printout class. And finally there is the low level class :class:`~wx.html.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: Help Files Format ------------------ :mod:`wx.html` library can be used to show an help manual to the user; in fact, it supports natively (through :class:`~wx.html.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"``. .. _.hhp files: .. _.hhp file: Header file (.hhp) ~~~~~~~~~~~~~~~~~~~ .. highlight:: rst The header file must contain these lines (and may contain additional lines which are ignored):: Contents file=filename.hhc Index file=filename.hhk Title=title of your book Default topic=default page to be displayed.htm All filenames (including the Default topic) are relative to the location of the ``".hhp"`` file. .. note:: For localization, in addition the ``".hhp"`` file may contain the line:: Charset=rfc_charset which specifies what charset (e.g. "iso8859_1") was used in contents and index files. Please note that this line is incompatible with MS HTML Help Workshop and it would either silently remove it or complain with some error. Contents file (.hhc) ~~~~~~~~~~~~~~~~~~~~~ .. highlight:: html Contents file has HTML syntax and it can be parsed by regular HTML parser. It contains exactly one list (```` statement):: 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 :meth:`~wx.html.HtmlHelpController.Display`. Items in the list may be nested - one ``
  • `` statement may contain a ``