Phoenix Logo

phoenix_title wx.html.HtmlWindow

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 rich content pages (either local file or downloaded via HTTP protocol) in a window based on a subset of the HTML standard. 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 with raw HTML, LoadPage with a wx.FileSystem location or LoadFile with a filename.

styles Window Styles

This class supports the following styles:

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

events Events Emitted by this Class

Handlers bound for the following event types will receive one of the wx.html.HtmlCellEvent wx.html.HtmlLinkEvent parameters.

Note

If you want complete HTML/CSS support as well as a Javascript engine, see instead wx.html2.WebView.

Note

wx.html.HtmlWindow uses the wx.Image class for displaying images, as such you need to initialize the handlers for any image formats you use before loading a page. See wx.InitAllImageHandlers and wx.Image.AddHandler .


class_hierarchy Class Hierarchy

Inheritance diagram for class HtmlWindow:


method_summary Methods Summary

__init__ Default constructor.
AddFilter Adds input filter to the static list of available filters.
AppendToPage Appends HTML fragment to currently displayed text and refreshes the window.
GetInternalRepresentation Returns pointer to the top-level container.
GetOpenedAnchor Returns anchor within currently opened page (see wx.html.HtmlWindow.GetOpenedPage ).
GetOpenedPage Returns full location of the opened page.
GetOpenedPageTitle Returns title of the opened page or “” if the current page does not contain <TITLE> tag.
GetParser Returns a pointer to the current parser.
GetRelatedFrame Returns the related frame.
HistoryBack Moves back to the previous page.
HistoryCanBack Returns True if it is possible to go back in the history i.e.
HistoryCanForward Returns True if it is possible to go forward in the history i.e.
HistoryClear Clears history.
HistoryForward Moves to next page in history.
LoadFile Loads an HTML page from a file and displays it.
LoadPage Unlike SetPage this function first loads the HTML page from location and then displays it.
OnCellClicked This method is called when a mouse button is clicked inside wx.html.HtmlWindow.
OnCellMouseHover This method is called when a mouse moves over an HTML cell.
OnLinkClicked Called when user clicks on hypertext link.
OnOpeningURL Called when an URL is being opened (either when the user clicks on a link or an image is loaded).
OnSetTitle Called on parsing <TITLE> tag.
ReadCustomization This reads custom settings from Config.
SelectAll Selects all text in the window.
SelectLine Selects the line of text that pos points at.
SelectWord Selects the word at position pos.
SelectionToText Returns the current selection as plain text.
SetBorders This function sets the space between border of window and HTML contents.
SetFonts This function sets font sizes and faces.
SetPage Sets the source of a page and displays it, for example
SetRelatedFrame Sets the frame in which page title will be displayed.
SetRelatedStatusBar After calling SetRelatedFrame , this sets statusbar slot where messages will be displayed.
SetStandardFonts Sets default font sizes and/or default font size.
ToText Returns content of currently displayed page as plain text.
WriteCustomization Saves custom settings into Config.

api Class API



class wx.html.HtmlWindow(ScrolledWindow)

Possible constructors:

HtmlWindow()

HtmlWindow(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
           style=HW_DEFAULT_STYLE, name="htmlWindow")

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


Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.



__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=HW_DEFAULT_STYLE, name=”htmlWindow”)

Constructor.

The parameters are the same as Scrolled.__init__ constructor.

Parameters:





static 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:filter (wx.html.HtmlFilter) –


AppendToPage(self, source)

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

Parameters:source (string) – HTML code fragment
Return type:bool
Returns:False if an error occurred, True otherwise.


GetInternalRepresentation(self)

Returns pointer to the top-level container.

Return type: wx.html.HtmlContainerCell


GetOpenedAnchor(self)

Returns anchor within currently opened page (see wx.html.HtmlWindow.GetOpenedPage ).

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

Return type:string


GetOpenedPage(self)

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.

Return type:string


GetOpenedPageTitle(self)

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

Return type:string


GetParser(self)

Returns a pointer to the current parser.

Return type: wx.html.HtmlWinParser


GetRelatedFrame(self)

Returns the related frame.

Return type:Frame


HistoryBack(self)

Moves back to the previous page.

Only pages displayed using LoadPage are stored in history list.

Return type:bool


HistoryCanBack(self)

Returns True if it is possible to go back in the history i.e.

HistoryBack won’t fail.

Return type:bool


HistoryCanForward(self)

Returns True if it is possible to go forward in the history i.e.

HistoryForward won’t fail.

Return type:bool


HistoryClear(self)

Clears history.



HistoryForward(self)

Moves to next page in history.

Only pages displayed using LoadPage are stored in history list.

Return type:bool


LoadFile(self, filename)

Loads an HTML page from a file and displays it.

Parameters:filename (string) –
Return type:bool
Returns:False if an error occurred, True otherwise

See also

LoadPage



LoadPage(self, location)

Unlike SetPage this function first loads the HTML page from location and then displays it.

Parameters:location (string) – The address of the document. See the FileSystem Overview for details on the address format and wx.FileSystem for a description of how the file is opened.
Return type:bool
Returns:False if an error occurred, True otherwise

See also

LoadFile



OnCellClicked(self, cell, x, y, 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.

Overloading this method is deprecated; intercept the event instead.

Parameters:
  • cell (wx.html.HtmlCell) – The cell inside which the mouse was clicked, always a simple (i.e. non-container) cell
  • x (int) – The logical x coordinate of the click point
  • y (int) – The logical y coordinate of the click point
  • event (wx.MouseEvent) – The mouse event containing other information about the click
Return type:

bool

Returns:

True if a link was clicked, False otherwise.



OnCellMouseHover(self, cell, x, y)

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

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

Overloading this method is deprecated; intercept the event instead.

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


OnLinkClicked(self, 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.

Overloading this method is deprecated; intercept the event instead.

Also see wx.html.HtmlLinkInfo.

Parameters:link (wx.html.HtmlLinkInfo) –


OnOpeningURL(self, 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 HTML_OPEN . This method is called by wx.html.HtmlParser.OpenURL .

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

Parameters:
  • type (HtmlURLType) – Indicates type of the resource. Is one of

    • 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) – Pointer to String variable that must be filled with an URL if OnOpeningURL returns HTML_REDIRECT .
Return type:

wx.html.HtmlOpeningStatus

  • wx.html.HTML_OPEN: Open the URL.
  • wx.html.HTML_BLOCK: Deny access to the URL, wx.html.HtmlParser.OpenURL will return None.
  • 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.


OnSetTitle(self, title)

Called on parsing <TITLE> tag.

Parameters:title (string) –


ReadCustomization(self, cfg, path="")

This reads custom settings from Config.

It uses the path ‘path’ if given, otherwise it saves info into currently selected path. The values are stored in sub-path wx.html.HtmlWindow. Read values: all things set by SetFonts , SetBorders .

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


SelectAll(self)

Selects all text in the window.

See also

SelectLine , SelectWord



SelectLine(self, pos)

Selects the line of text that pos points at.

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

Parameters:pos (wx.Point) –

See also

SelectAll , SelectWord



SelectWord(self, pos)

Selects the word at position pos.

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

Parameters:pos (wx.Point) –

See also

SelectAll , SelectLine



SelectionToText(self)

Returns the current selection as plain text.

Returns an empty string if no text is currently selected.

Return type:string


SetBorders(self, b)

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

See image:

_images/htmlwin_border.png

Parameters:b (int) – indentation from borders in pixels


SetFonts(self, normal_face, fixed_face, sizes)

This function sets font sizes and faces.

See wx.html.HtmlDCRenderer.SetFonts for detailed description.

Parameters:
  • normal_face (string) –
  • fixed_face (string) –
  • sizes (list of integers) –

See also

SetSize()



SetPage(self, source)

Sets the source of a page and displays it, for example:

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

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

Parameters:source (string) – The HTML to be displayed.
Return type:bool
Returns:False if an error occurred, True otherwise.


SetRelatedFrame(self, frame, format)

Sets the frame in which page title will be displayed.

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

Parameters:
  • frame (wx.Frame) –
  • format (string) –


SetRelatedStatusBar(self, *args, **kw)

overload Overloaded Implementations:



SetRelatedStatusBar (self, index)

After calling SetRelatedFrame , this sets statusbar slot where messages will be displayed.

(Default is -1 = no messages.)

Parameters:index (int) – Statusbar slot number (0..n)



SetRelatedStatusBar (self, statusbar, index=0)

Sets the associated statusbar where messages will be displayed.

Call this instead of SetRelatedFrame if you want statusbar updates only, no changing of the frame title.

Parameters:
  • statusbar (wx.StatusBar) – Statusbar pointer
  • index (int) – Statusbar slot number (0..n)

New in version 2.9.0.





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

Sets default font sizes and/or default font size.

See wx.html.HtmlDCRenderer.SetStandardFonts for detailed description.

Parameters:
  • size (int) –
  • normal_face (string) –
  • fixed_face (string) –

See also

SetFonts



ToText(self)

Returns content of currently displayed page as plain text.

Return type:string


WriteCustomization(self, cfg, path="")

Saves custom settings into 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.html.HtmlWindow.

Saved values: all things set by SetFonts , SetBorders .

Parameters:
  • cfg (wx.ConfigBase) – 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 and SetRelatedFrame