How can I respond to a user click on an active link

The use of a wx.html.HtmlWindow is not limited to display. You can also respond to user input. In this case, you do not need to define your own event handlers, as the C + + code comes with a set of predefined handlers that you can override in your own subclass of wx.html.HtmlWindow. This is the sort of thing you'd do to make your HTML window behave like an actual browser, including following hyperlinks, and displaying tooltips when the user hovers over a link.

Table 16.2 describes the defined handlers. The wx.html.HtmlWindow class does not define these events using the normal event system, so you must handle them with these overloaded member functions, rather than binding them as event types.

Again, if you want an HTML window that responds to user input, you must create your own subclass and override these methods.

Table 16.2 Event handlers of wx.html.HtmlWindow



OnCellClicked (cell, x, y, event)

Called when the user clicks inside the HTML document. The cell argument is a wx.html.HtmlCell object representing a portion of the displayed document, usually something like a run of same-styled text, a table cell, or an image. The wx.html.HtmlCell class is created by the HTML parser, and will be discussed later in the chapter. The x and y coordinates are the exact pixel location of the mouse click, and the event is the relevant mouse click event. The default version of this method simply delegates to OnLinkClicked() if the cell contains a link, otherwise it does nothing.

OnCellMouseHover (cell, x, y)

Called when the user rolls the mouse over an HTML cell, where a cell has the same definition as above. The arguments are as in OnCellClicked().


Called when the user clicks on a hyperlink. The link argument is of the parser-created class wx.html.HtmlLinkInfo, and contains the information needed to load the linked resource. The default version of the method calls LoadPage on the URL in the link. A common use case for overriding this method is to use an HtmlWindow to make a fancy about box for an application. In that case you might change the behavior so the user clicks homepage to launch's the system's default browser using Python's webbrowser module.

OnOpeningURL (type, url)

Called when the user requests a URL to open, whether it is a page or an image that is part of a page. The type argument is wx.html.HTML_URL_PAGE, wx.html.HTML_URL_IMAGE, or wx.html.HTML_URL_OTHER. This method returns one of the following—wx.html.HTML_OPEN to allow the resource to load, wx.html.HTML_BLOCK to prevent the resource from loading, or a string that will be used as a url redirect, and this method is then called again on the redirected location. The default version of this method always returns wx.html.HTML_OPEN.


Called when the HTML source has a <title> tag. Generally used to display that title elsewhere in the application.

Was this article helpful?

0 0


    Does a cell contain a hyperlink?
    8 years ago

Post a comment