]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxHtmlWindow.py
fixes for trailing commas for OS/2 from WX_2_2_BRANCH
[wxWidgets.git] / 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 20
eec92d76 21 # Virtuals in the base class have been renamed with base_ on the front.
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 28
854862f5
RD
29## def __del__(self):
30## print 'MyHtmlWindow.__del__'
ec3e670f
RD
31
32
33class TestHtmlPanel(wxPanel):
34 def __init__(self, parent, frame, log):
35 wxPanel.__init__(self, parent, -1)
36 self.log = log
37 self.frame = frame
ae920857
RD
38 self.cwd = os.path.split(sys.argv[0])[0]
39 if not self.cwd:
40 self.cwd = os.getcwd()
ec3e670f 41
ec3e670f
RD
42 self.html = MyHtmlWindow(self, -1, log)
43 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
44 self.html.SetRelatedStatusBar(0)
45
65dd82cb
RD
46 self.printer = wxHtmlEasyPrinting()
47
2f90df85
RD
48 self.box = wxBoxSizer(wxVERTICAL)
49 self.box.Add(self.html, 1, wxGROW)
ec3e670f
RD
50
51 subbox = wxBoxSizer(wxHORIZONTAL)
854862f5
RD
52## btn = wxButton(self, 1201, "Show Default")
53## EVT_BUTTON(self, 1201, self.OnShowDefault)
54## subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
55
56 btn = wxButton(self, 1202, "Load File")
57 EVT_BUTTON(self, 1202, self.OnLoadFile)
2f90df85 58 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
59
60 btn = wxButton(self, 1203, "With Widgets")
61 EVT_BUTTON(self, 1203, self.OnWithWidgets)
2f90df85 62 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
63
64 btn = wxButton(self, 1204, "Back")
65 EVT_BUTTON(self, 1204, self.OnBack)
2f90df85 66 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
67
68 btn = wxButton(self, 1205, "Forward")
69 EVT_BUTTON(self, 1205, self.OnForward)
2f90df85 70 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 71
65dd82cb
RD
72 btn = wxButton(self, 1207, "Print")
73 EVT_BUTTON(self, 1207, self.OnPrint)
74 subbox.Add(btn, 1, wxGROW | wxALL, 2)
75
e166644c
RD
76 btn = wxButton(self, 1206, "View Source")
77 EVT_BUTTON(self, 1206, self.OnViewSource)
2f90df85 78 subbox.Add(btn, 1, wxGROW | wxALL, 2)
e166644c 79
2f90df85
RD
80 self.box.Add(subbox, 0, wxGROW)
81 self.SetSizer(self.box)
82 self.SetAutoLayout(true)
e166644c
RD
83
84 # A button with this ID is created on the widget test page.
85 EVT_BUTTON(self, wxID_OK, self.OnOk)
86
ec3e670f
RD
87 self.OnShowDefault(None)
88
89
854862f5
RD
90## def __del__(self):
91## print 'TestHtmlPanel.__del__'
eec92d76 92
e166644c 93
ec3e670f
RD
94
95 def OnShowDefault(self, event):
ae920857 96 name = os.path.join(self.cwd, 'data/test.htm')
e166644c 97 self.html.LoadPage(name)
ec3e670f
RD
98
99
100 def OnLoadFile(self, event):
e166644c
RD
101 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
102 if dlg.ShowModal():
103 path = dlg.GetPath()
104 self.html.LoadPage(path)
105 dlg.Destroy()
ec3e670f
RD
106
107
108 def OnWithWidgets(self, event):
ae920857
RD
109 os.chdir(self.cwd)
110 name = os.path.join(self.cwd, 'data/widgetTest.htm')
e166644c 111 self.html.LoadPage(name)
ae920857 112
e166644c
RD
113
114 def OnOk(self, event):
115 self.log.WriteText("It works!\n")
ec3e670f
RD
116
117 def OnBack(self, event):
118 if not self.html.HistoryBack():
119 wxMessageBox("No more items in history!")
120
e166644c 121
ec3e670f
RD
122 def OnForward(self, event):
123 if not self.html.HistoryForward():
124 wxMessageBox("No more items in history!")
125
126
e166644c
RD
127 def OnViewSource(self, event):
128 from wxPython.lib.dialogs import wxScrolledMessageDialog
129 source = self.html.GetParser().GetSource()
130 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
131 dlg.ShowModal()
132 dlg.Destroy()
133
134
65dd82cb
RD
135 def OnPrint(self, event):
136 self.printer.PrintFile(self.html.GetOpenedPage())
137
ec3e670f
RD
138#----------------------------------------------------------------------
139
140def runTest(frame, nb, log):
141 win = TestHtmlPanel(nb, frame, log)
142 return win
143
144
145#----------------------------------------------------------------------
146
147
148
149
150
151overview = """\
152wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
153
154It 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...
155
156"""
157
e166644c
RD
158
159
160
161
e166644c
RD
162
163
164
165
166