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
.
^^
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. ^^
^^
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.
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. |
See |
|
See |
|
See |
|
See |
wx.html.
HtmlWindow
(ScrolledWindow, HtmlWindowInterface)¶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).
__init__
(self, *args, **kw)¶__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.
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.
filter (wx.html.HtmlFilter) –
AppendToPage
(self, source)¶Appends HTML fragment to currently displayed text and refreshes the window.
source (string) – HTML code fragment
bool
False
if an error occurred, True
otherwise.
GetClassDefaultAttributes
(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
VisualAttributes
GetDefaultHTMLCursor
(type)¶Retrieves the default cursor for a given HTMLCursor type.
type (HTMLCursor) – HTMLCursor type to retrieve.
Cursor
New in version 4.1/wxWidgets-3.1.0.
GetInternalRepresentation
(self)¶Returns pointer to the top-level container.
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.
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.
string
GetOpenedPageTitle
(self)¶Returns title of the opened page or “” if the current page does not contain <TITLE
> tag.
string
GetParser
(self)¶Returns a pointer to the current parser.
GetRelatedFrame
(self)¶Returns the related frame.
Frame
HistoryBack
(self)¶Moves back to the previous page.
Only pages displayed using LoadPage
are stored in history list.
bool
HistoryCanBack
(self)¶Returns True
if it is possible to go back in the history i.e.
HistoryBack
won’t fail.
bool
HistoryCanForward
(self)¶Returns True
if it is possible to go forward in the history i.e.
HistoryForward
won’t fail.
bool
HistoryClear
(self)¶Clears history.
HistoryForward
(self)¶Moves to next page in history.
Only pages displayed using LoadPage
are stored in history list.
bool
LoadFile
(self, filename)¶Loads an HTML page from a file and displays it.
filename (string) –
bool
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.
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.
bool
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.
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
bool
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.
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.
link (wx.html.HtmlLinkInfo) –
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
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
.
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
returns HTML_REDIRECT
.
tuple
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.
( wx.html.HtmlOpeningStatus, redirectTo )
OnSetTitle
(self, title)¶Called on parsing <TITLE
> tag.
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
.
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.
ScrollToAnchor
(self, anchor)¶anchor (String
) –
bool
SelectAll
(self)¶Selects all text in the window.
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.
pos (wx.Point) –
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.
pos (wx.Point) –
See also
SelectionToText
(self)¶Returns the current selection as plain text.
Returns an empty string if no text is currently selected.
string
SetBorders
(self, b)¶This function sets the space between border of window and HTML contents.
See image:
b (int) – indentation from borders in pixels
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.
type (HTMLCursor) – HTMLCursor type to retrieve.
cursor (wx.Cursor) – The default cursor for the specified cursor type.
New 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.
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.
source (string) – The HTML to be displayed.
bool
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.
frame (wx.Frame) –
format (string) –
SetRelatedStatusBar
(self, *args, **kw)¶SetRelatedStatusBar (self, index)
After calling SetRelatedFrame
, this sets statusbar slot where messages will be displayed.
(Default is -1 = no messages.)
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.
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.
size (int) –
normal_face (string) –
fixed_face (string) –
See also
ToText
(self)¶Returns content of currently displayed page as plain text.
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
.
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.
InternalRepresentation
¶OpenedAnchor
¶See GetOpenedAnchor
OpenedPage
¶See GetOpenedPage
OpenedPageTitle
¶RelatedFrame
¶See GetRelatedFrame
and SetRelatedFrame