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.
wx.html.HtmlWindow uses the wx.Image class for displaying images, so you need to initialize the handlers for any image formats you use before loading a page. See wx.InitAllImageHandlers
and wx.Image.AddHandler
.
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 Emitted by this Class¶
Handlers bound for the following event types will receive one of the wx.html.HtmlCellEvent wx.html.HtmlLinkEvent parameters.
EVT_HTML_CELL_CLICKED: A wx.html.HtmlCell was clicked.
EVT_HTML_CELL_HOVER: The mouse passed over a wx.html.HtmlCell.
EVT_HTML_LINK_CLICKED: A wx.html.HtmlCell which contains a hyperlink was clicked.
Note
If you want complete HTML/CSS support as well as a Javascript engine, consider using wx.html2.WebView instead.
See also
Class Hierarchy¶
Methods Summary¶
Default constructor. |
|
Adds an input filter to the static list of available filters. |
|
Appends HTML fragment to currently displayed text and refreshes the window. |
|
Retrieves the default cursor for a given HTMLCursor type. |
|
Returns pointer to the top-level container. |
|
Returns anchor within currently opened page (see |
|
Returns full location of the opened page. |
|
Returns title of the opened page or “” if the current page does not contain < |
|
Returns a pointer to the current parser. |
|
Returns the related frame. |
|
Moves back to the previous page. |
|
Returns |
|
Returns |
|
Clears history. |
|
Moves to next page in history. |
|
Loads an HTML page from a file and displays it. |
|
Unlike |
|
This method is called when a mouse button is clicked inside wx.html.HtmlWindow. |
|
This method is called when a mouse moves over an HTML cell. |
|
Called when user clicks on hypertext link. |
|
Called when an URL is being opened (either when the user clicks on a link or an image is loaded). |
|
Called on parsing < |
|
This reads custom settings from Config. |
|
Selects all text in the window. |
|
Selects the line of text that pos points at. |
|
Selects the word at position pos. |
|
Returns the current selection as plain text. |
|
This function sets the space between border of window and HTML contents. |
|
Sets the default cursor for a given HTMLCursor type. |
|
This function sets font sizes and faces. |
|
Sets the source of a page and displays it, for example |
|
Sets the frame in which page title will be displayed. |
|
After calling |
|
Sets default font sizes and/or default font size. |
|
Returns content of currently displayed page as plain text. |
|
Saves custom settings into Config. |
Properties Summary¶
See |
|
See |
|
See |
|
See |
Class API¶
- class wx.html.HtmlWindow(ScrolledWindow, HtmlWindowInterface)¶
Possible constructors:
HtmlWindow() -> None HtmlWindow(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=HW_DEFAULT_STYLE, name="htmlWindow") -> None
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)¶
-
__init__ (self)
Default constructor.
- Return type:
None
__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:
- Return type:
None
- static AddFilter(filter)¶
Adds an input filter to the static list of available filters.
These filters are present by default:
text/html text/plain image/*
The plain text filter will be used if no other filter matches.
- Parameters:
filter (wx.html.HtmlFilter)
- Return type:
None
- 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.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
VisualAttributes
- static GetDefaultHTMLCursor(type)¶
Retrieves the default cursor for a given HTMLCursor type.
- Parameters:
type (HTMLCursor) – HTMLCursor type to retrieve.
- Return type:
Cursor
Added in version 4.1/wxWidgets-3.1.0.
- GetInternalRepresentation(self)¶
Returns pointer to the top-level container.
- Return type:
- 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:
str
- 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:
str
- GetOpenedPageTitle(self)¶
Returns title of the opened page or “” if the current page does not contain <
TITLE
> tag.- Return type:
str
- GetParser(self)¶
Returns a pointer to the current parser.
- Return type:
- 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.
- Return type:
None
- 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(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
- 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 a 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
- Return type:
None
- 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)
- Return type:
None
- OnOpeningURL(self, type, url)¶
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
returnsHTML_OPEN
. This method is called bywx.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 returnHTML_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.
Pointer to String variable that must be filled with an URL if
OnOpeningURL
returnsHTML_REDIRECT
.- Return type:
Tuple[HtmlOpeningStatus, str]
wx.html.HTML_OPEN
: Open the URL.wx.html.HTML_BLOCK
: Deny access to the URL,wx.html.HtmlParser.OpenURL
will returnNone
.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)
- Return type:
None
- 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.
- Return type:
None
- ScrollToAnchor(self, anchor)¶
- Parameters:
anchor (
String
)- Return type:
bool
- SelectAll(self)¶
Selects all text in the window.
- Return type:
None
See also
- 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)
- Return type:
None
See also
- 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)
- Return type:
None
See also
- SelectionToText(self)¶
Returns the current selection as plain text.
Returns an empty string if no text is currently selected.
- Return type:
str
- SetBorders(self, b)¶
This function sets the space between border of window and HTML contents.
See image:
- Parameters:
b (int) – indentation from borders in pixels
- Return type:
None
- static SetDefaultHTMLCursor(type, cursor)¶
Sets the default cursor for a given HTMLCursor type.
These cursors are used for all wx.html.HtmlWindow objects by default, but can be overridden on a per-window basis.
- Parameters:
type (HTMLCursor) – HTMLCursor type to retrieve.
cursor (wx.Cursor) – The default cursor for the specified cursor type.
- Return type:
None
Added in version 4.1/wxWidgets-3.1.0.
- 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)
- Return type:
None
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)
- Return type:
None
- SetRelatedStatusBar(self, *args, **kw)¶
-
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)
- Return type:
None
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)
- Return type:
None
Added 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)
- Return type:
None
See also
- ToText(self)¶
Returns content of currently displayed page as plain text.
- Return type:
str
- 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.
- Return type:
None
Properties¶
- InternalRepresentation¶
- OpenedAnchor¶
See
GetOpenedAnchor
- OpenedPage¶
See
GetOpenedPage
- OpenedPageTitle¶
- RelatedFrame¶
See
GetRelatedFrame
andSetRelatedFrame