wx.html.HtmlWindow

Inheritance diagram for wx.html.HtmlWindow:



Description

wx.html.HtmlWindow is probably the only class you will directly use unless you want to do something special (like adding new tag handlers or MIME filters).

The purpose of this class is to display HTML pages (either local file or downloaded via HTTP protocol) in a window. The width of the window is constant – given in the constructor – and virtual height is changed dynamically depending on page size. Once the window is created you can set its content by calling SetPage, LoadPage or LoadFile.

Derived From

Window Styles

Window Style Description
wx.html.HW_SCROLLBAR_NEVER Never display scrollbars, not even when the page is larger than the window.
wx.html.HW_SCROLLBAR_AUTO Display scrollbars only if page’s size exceeds window’s size.
wx.html.HW_NO_SELECTION Don’t allow the user to select text.

Event Handling

Event Name Description
wx.html.EVT_HTML_CELL_CLICKED(id, func) A wx.html.HtmlCell was clicked.
wx.html.EVT_HTML_CELL_HOVER(id, func) The mouse passed over a wx.html.HtmlCell.
wx.html.EVT_HTML_LINK_CLICKED(id, func) A wx.html.HtmlCell which contains an hyperlink was clicked.

Class API

Methods

__init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.html.HW_DEFAULT_STYLE, name="htmlWindow")

Constructor. All the parameters are the same as wx.ScrolledWindow constructor, except style.

For style, see Window Styles.

Parameters:


Returns:

wx.html.HtmlWindow


AddFilter(filter)

Adds input filter to the static list of available filters. These filters are present by default:

  • text/html MIME type
  • image/* MIME types
  • Plain Text filter (this filter is used if no other filter matches)

Parameters:


AppendToPage(source)

Appends HTML fragment to currently displayed text and refreshes the window.

Returns False if an error occurred, True otherwise.

Parameters:

  • source (string): HTML code fragment.

Returns:

bool


GetDefaultHTMLCursor(type)

Parameters:

  • type (int)

Returns:

wx.Cursor


GetInternalRepresentation()

Returns pointer to the top-level container.


Returns:

wx.html.HtmlContainerCell


GetOpenedAnchor()

Returns anchor within currently opened page (see GetOpenedPage).

If no page is opened or if the displayed page wasn’t produced by call to LoadPage, empty string is returned.


Returns:

string


GetOpenedPage()

Returns full location of the opened page.

If no page is opened or if the displayed page wasn’t produced by call to LoadPage, empty string is returned.


Returns:

string


GetOpenedPageTitle()

Returns title of the opened page or “” if current page does not contain <TITLE> tag.


Returns:

string


GetParser()
No docstrings available for this method.

GetRelatedFrame()

Returns the related frame.


Returns:

wx.Frame


HasAnchor(anchor)

Parameters:

  • anchor (string)

Returns:

bool


HistoryBack()

Moves back to the previous page.

Each page displayed using LoadPage is stored in history list.


Returns:

bool


HistoryCanBack()

Returns True if it is possible to go back in the history (i.e. HistoryBack won’t fail).


Returns:

bool


HistoryCanForward()

Returns True if it is possible to go forward in the history (i.e. HistoryForward won’t fail).


Returns:

bool


HistoryClear()
Clears history.

HistoryForward()

Moves to next page in history.


Returns:

bool


LoadFile(filename)

Loads HTML page from file and displays it.

Returns False if an error occurred, True otherwise.

Parameters:

  • filename (string)

Returns:

bool

See also

LoadPage


LoadPage(location)

Unlike SetPage this function first loads HTML page from location and then displays it. For example:

htmlWin.LoadPage("help/myproject/index.htm")

Returns False if an error occurred, True otherwise.

Parameters:

  • location (string): The address of document. See wx.FileSystem for details on address format and behaviour of “opener”.

Returns:

bool

See also

LoadFile


OnCellClicked(cell, event)

This method is called when a mouse button is clicked inside wx.html.HtmlWindow.

The default behaviour is to emit a wx.html.HtmlCellEvent and, if the event was not processed or skipped, call OnLinkClicked if the cell contains an hypertext link.

Parameters:

  • cell (wx.html.HtmlCell): The cell inside which the mouse was clicked, always a simple (i.e. non-container) cell.
  • event (int): The mouse event containing other information about the click.

Returns:

bool

Warning

Overloading this method is deprecated; intercept the event instead.


OnCellMouseHover(cell, x, y)

This method is called when a mouse moves over an HTML cell.

Default behaviour is to emit a wx.html.HtmlCellEvent.

Parameters:

  • cell (wx.html.HtmlCell): The cell inside which the mouse is currently, always a simple (i.e. non-container) cell.
  • x, y (int): The logical coordinates of the click point.

Warning

Overloading this method is deprecated; intercept the event instead.


OnLinkClicked(link)

Called when user clicks on hypertext link.

Default behaviour is to emit a wx.html.HtmlLinkEvent and, if the event was not processed or skipped, call LoadPage and do nothing else.

Parameters:

Warning

Overloading this method is deprecated; intercept the event instead.


OnOpeningURL(type, url, redirect)

Called when an URL is being opened (either when the user clicks on a link or an image is loaded).

The URL will be opened only if OnOpeningURL returns wx.html.HTML_OPEN.

You can override OnOpeningURL to selectively block some URLs (e.g. for security reasons) or to redirect them elsewhere.

Default behaviour is to always return wx.html.HTML_OPEN, but if overloaded the possible return values are:

Return Values Description
wx.html.HTML_OPEN Open the URL.
wx.html.HTML_BLOCK Deny access to the URL.
wx.html.HTML_REDIRECT Don’t open url, redirect to another URL. OnOpeningURL must fill redirect with the new URL. OnOpeningURL will be called again on returned URL.

Parameters:

  • type (int): Indicates type of the resource. Is one of:

    Resource Flag

    Description

    wx.html.HTML_URL_PAGE

    Opening a HTML page.

    wx.html.HTML_URL_IMAGE

    Opening an image.

    wx.html.HTML_URL_OTHER

    Opening a resource that doesn’t fall into any other category.

  • url (string): URL being opened.

  • redirect (string): string that must be filled with an URL if OnOpeningURL returns wx.html.HTML_REDIRECT.


Returns:

int


OnSetTitle(title)

Called on parsing <TITLE> tag.

Parameters:

  • title (string)

ReadCustomization(cfg, path="")

This reads custom settings from wx.Config.

It uses the path path if given, otherwise it saves info into currently selected path. The values are stored in sub-path wx.HtmlWindow.

Read values: all things set by SetFonts, SetBorders.

Parameters:

  • cfg (wx.ConfigBase): wx.Config from which you want to read the configuration.
  • path (string): Optional path in config tree. If not given current path is used.

ScrollToAnchor(anchor)

Parameters:

  • anchor (string)

Returns:

bool


SelectAll()
Selects all text in the window.

SelectLine(pos)

Selects the line of text that pos points at.

Parameters:

Note

Note that pos is relative to the top of displayed page, not to window’s origin, use CalcUnscrolledPosition to convert physical coordinate.

See also

SelectAll, SelectWord


SelectWord(pos)

Selects the word at position pos.

Parameters:

Note

Note that pos is relative to the top of displayed page, not to window’s origin, use CalcUnscrolledPosition to convert physical coordinate.

See also

SelectAll, SelectLine


SelectionToText()

Returns current selection as plain text.

Returns empty string if no text is currently selected.


Returns:

string


SetBackgroundImage(bmpBg)

Parameters:


SetBorders(b)

This function sets the space between border of window and HTML contents. See image:


../_images/border.png

Parameters:

  • b (int): indentation from borders in pixels.

SetFonts(normal_face, fixed_face, sizes=None)

This function sets font sizes and faces.

Default font sizes are defined by constants wx.html.HTML_FONT_SIZE_1, wx.html.HTML_FONT_SIZE_2, ..., wx.html.HTML_FONT_SIZE_7. Note that they differ among platforms.

Default face names are empty strings.

Parameters:

  • normal_face (string): This is face name for normal (i.e. non-fixed) font. It can be either empty string (then the default face is chosen) or platform-specific face name. Examples are “helvetica” under Unix or “Times New Roman” under Windows.
  • fixed_face (string): As above but for fixed face.
  • sizes (int): This is an array of 7 integers items. The values represent size of font with HTML size from -2 to +4 (<FONT SIZE=-2> to <FONT SIZE=+4>). Default sizes are used if sizes is None

SetPage(source)

Sets HTML page and display it. This won’t load the page!! It will display the source. See example:

htmlWin.SetPage("<html><body>Hello, world!</body></html>")

If you want to load a document from some location use LoadPage instead.

Returns False if an error occurred, True otherwise.

Parameters:

  • source (string): The HTML document source to be displayed.

Returns:

bool


SetRelatedFrame(frame, format)

Sets the frame in which page title will be displayed.

format is format of frame title, e.g. “HtmlHelp : %s”. It must contain exactly one %s. This %s is substituted with HTML page title.

Parameters:


SetRelatedStatusBar(bar)

After calling SetRelatedFrame, this sets statusbar slot where messages will be displayed. (Default is -1 = no messages.)

Parameters:


SetStandardFonts(size=-1, normal_face="", fixed_face="")

Parameters:

  • size (int)
  • normal_face (string)
  • fixed_face (string)

ToText()

Returns content of currently displayed page as plain text.


Returns:

string


WriteCustomization(cfg, path="")

Saves custom settings into wx.Config.

It uses the path path if given, otherwise it saves info into currently selected path. Regardless of whether the path is given or not, the function creates sub-path wx.HtmlWindow.

Saved values: all things set by SetFonts, SetBorders.

Parameters:

  • cfg (wx.ConfigBase): wx.Config to which you want to save the configuration.
  • path (string): Optional path in config tree. If not given, the current path is used.

Properties

InternalRepresentation
See GetInternalRepresentation
OpenedAnchor
See GetOpenedAnchor
OpenedPage
See GetOpenedPage
OpenedPageTitle
See GetOpenedPageTitle
Parser
See GetParser
RelatedFrame
See GetRelatedFrame