]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/demo/wxHtmlWindow.py
Fixed wxWindowCreateEvent and wxWindowDestroyEvent to set m_eventType
[wxWidgets.git] / utils / wxPython / demo / wxHtmlWindow.py
CommitLineData
ec3e670f 1
e166644c
RD
2import sys, os
3
4from wxPython.wx import *
5from wxPython.html import *
e166644c 6import wxPython.lib.wxpTag
ec3e670f
RD
7
8#----------------------------------------------------------------------
9
10# This shows how to catch the OnLinkClicked non-event. (It's a virtual
11# method in the C++ code...)
12class MyHtmlWindow(wxHtmlWindow):
13 def __init__(self, parent, id, log):
14 wxHtmlWindow.__init__(self, parent, id)
15 self.log = log
16
9c00cfa3
RD
17
18 def OnLinkClicked(self, linkinfo):
19 self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
ec3e670f
RD
20
21 # Virtuals in the base class have been renamed with base_ on the font.
9c00cfa3
RD
22 self.base_OnLinkClicked(linkinfo)
23
24
25 def OnSetTitle(self, title):
26 self.log.WriteText('OnSetTitle: %s\n' % title)
27 self.base_OnSetTitle(title)
ec3e670f
RD
28
29
30
31class TestHtmlPanel(wxPanel):
32 def __init__(self, parent, frame, log):
33 wxPanel.__init__(self, parent, -1)
34 self.log = log
35 self.frame = frame
ae920857
RD
36 self.cwd = os.path.split(sys.argv[0])[0]
37 if not self.cwd:
38 self.cwd = os.getcwd()
ec3e670f
RD
39
40
41 self.html = MyHtmlWindow(self, -1, log)
42 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
43 self.html.SetRelatedStatusBar(0)
44
65dd82cb
RD
45 self.printer = wxHtmlEasyPrinting()
46
2f90df85
RD
47 self.box = wxBoxSizer(wxVERTICAL)
48 self.box.Add(self.html, 1, wxGROW)
ec3e670f
RD
49
50 subbox = wxBoxSizer(wxHORIZONTAL)
51 btn = wxButton(self, 1201, "Show Default")
52 EVT_BUTTON(self, 1201, self.OnShowDefault)
2f90df85 53 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
54
55 btn = wxButton(self, 1202, "Load File")
56 EVT_BUTTON(self, 1202, self.OnLoadFile)
2f90df85 57 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
58
59 btn = wxButton(self, 1203, "With Widgets")
60 EVT_BUTTON(self, 1203, self.OnWithWidgets)
2f90df85 61 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
62
63 btn = wxButton(self, 1204, "Back")
64 EVT_BUTTON(self, 1204, self.OnBack)
2f90df85 65 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
66
67 btn = wxButton(self, 1205, "Forward")
68 EVT_BUTTON(self, 1205, self.OnForward)
2f90df85 69 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 70
65dd82cb
RD
71 btn = wxButton(self, 1207, "Print")
72 EVT_BUTTON(self, 1207, self.OnPrint)
73 subbox.Add(btn, 1, wxGROW | wxALL, 2)
74
e166644c
RD
75 btn = wxButton(self, 1206, "View Source")
76 EVT_BUTTON(self, 1206, self.OnViewSource)
2f90df85 77 subbox.Add(btn, 1, wxGROW | wxALL, 2)
e166644c 78
2f90df85
RD
79 self.box.Add(subbox, 0, wxGROW)
80 self.SetSizer(self.box)
81 self.SetAutoLayout(true)
e166644c
RD
82
83 # A button with this ID is created on the widget test page.
84 EVT_BUTTON(self, wxID_OK, self.OnOk)
85
ec3e670f
RD
86 self.OnShowDefault(None)
87
88
e166644c 89
ec3e670f
RD
90
91 def OnShowDefault(self, event):
ae920857 92 name = os.path.join(self.cwd, 'data/test.htm')
e166644c 93 self.html.LoadPage(name)
ec3e670f
RD
94
95
96 def OnLoadFile(self, event):
e166644c
RD
97 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
98 if dlg.ShowModal():
99 path = dlg.GetPath()
100 self.html.LoadPage(path)
101 dlg.Destroy()
ec3e670f
RD
102
103
104 def OnWithWidgets(self, event):
ae920857
RD
105 os.chdir(self.cwd)
106 name = os.path.join(self.cwd, 'data/widgetTest.htm')
e166644c 107 self.html.LoadPage(name)
ae920857 108
e166644c
RD
109
110 def OnOk(self, event):
111 self.log.WriteText("It works!\n")
ec3e670f
RD
112
113 def OnBack(self, event):
114 if not self.html.HistoryBack():
115 wxMessageBox("No more items in history!")
116
e166644c 117
ec3e670f
RD
118 def OnForward(self, event):
119 if not self.html.HistoryForward():
120 wxMessageBox("No more items in history!")
121
122
e166644c
RD
123 def OnViewSource(self, event):
124 from wxPython.lib.dialogs import wxScrolledMessageDialog
125 source = self.html.GetParser().GetSource()
126 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
127 dlg.ShowModal()
128 dlg.Destroy()
129
130
65dd82cb
RD
131 def OnPrint(self, event):
132 self.printer.PrintFile(self.html.GetOpenedPage())
133
ec3e670f
RD
134#----------------------------------------------------------------------
135
136def runTest(frame, nb, log):
137 win = TestHtmlPanel(nb, frame, log)
138 return win
139
140
141#----------------------------------------------------------------------
142
143
144
145
146
147overview = """\
148wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
149
150It is not intended to be a high-end HTML browser. If you're looking for something like that try http://www.mozilla.org - there's a chance you'll be able to make their widget wxWindows-compatible. I'm sure everyone will enjoy your work in that case...
151
152"""
153
e166644c
RD
154
155
156
157
e166644c
RD
158
159
160
161
162