File: HtmlWindow.py

package info (click to toggle)
cain 1.10%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 29,848 kB
  • sloc: cpp: 49,612; python: 14,988; xml: 11,654; ansic: 3,644; makefile: 129; sh: 2
file content (53 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Implements the HTML window."""

import wx
import wx.html

class HtmlWindow(wx.html.HtmlWindow):
    """The HTML display window.

    Links to local files are opened in this browser.  External files are
    opened in an external browser."""

    def __init__(self, parent):
        """Just construct the base class."""
        wx.html.HtmlWindow.__init__(self, parent)

    def OnLinkClicked(self, link):
        """Decide whether to open the linked document in this browser or 
        to open in an external browser."""
        # If this is a local link.
        if link.GetHref()[0] == '#':
            # Open the link in this window.
            return wx.html.HtmlWindow.OnLinkClicked(self, link)
        else:
            # Open the page in an external browser.
            import webbrowser
            # Check the version.
            import platform
            version = platform.python_version_tuple()
            if 10 * int(version[0]) + int(version[1]) >= 25:
                # Open the page in a new tab.
                # This function is new in python 2.5.
                webbrowser.open_new_tab(link.GetHref())
            else:
                # Open the page in a new window.
                webbrowser.open_new(link.GetHref())
                
class TestHtmlWindow(wx.Frame):
    """Test the HTML window."""
    
    def __init__(self, parent=None):
        """Read and render the HTML help file."""
        wx.Frame.__init__(self, parent, -1, 'Test', size=(800,600))
        html = HtmlWindow(self)
        html.LoadPage('help.html')

def main():
    app = wx.PySimpleApp()
    frame = TestHtmlWindow()
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()