]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxHtmlWindow.py
added SetString(), deprecated SetLabel()
[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 7
6c5ae2d2
RD
8from Main import opj
9
ec3e670f
RD
10#----------------------------------------------------------------------
11
12# This shows how to catch the OnLinkClicked non-event. (It's a virtual
13# method in the C++ code...)
14class MyHtmlWindow(wxHtmlWindow):
15 def __init__(self, parent, id, log):
16 wxHtmlWindow.__init__(self, parent, id)
17 self.log = log
c368d904
RD
18 EVT_SCROLLWIN( self, self.OnScroll )
19
20 def OnScroll( self, event ):
21 print 'event.GetOrientation()',event.GetOrientation()
22 print 'event.GetPosition()',event.GetPosition()
23 event.Skip()
ec3e670f 24
9c00cfa3
RD
25
26 def OnLinkClicked(self, linkinfo):
27 self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
ec3e670f 28
eec92d76 29 # Virtuals in the base class have been renamed with base_ on the front.
9c00cfa3
RD
30 self.base_OnLinkClicked(linkinfo)
31
32
33 def OnSetTitle(self, title):
34 self.log.WriteText('OnSetTitle: %s\n' % title)
35 self.base_OnSetTitle(title)
ec3e670f 36
0122b7e3
RD
37 def OnCellMouseHover(self, cell, x, y):
38 self.log.WriteText('OnCellMouseHover: %s, (%d %d)\n' % (cell, x, y))
39 self.base_OnCellMouseHover(cell, x, y)
40
41 def OnCellClicked(self, cell, x, y, evt):
42 self.log.WriteText('OnCellClicked: %s, (%d %d)\n' % (cell, x, y))
43 self.base_OnCellClicked(cell, x, y, evt)
ec3e670f
RD
44
45
46class TestHtmlPanel(wxPanel):
47 def __init__(self, parent, frame, log):
48 wxPanel.__init__(self, parent, -1)
49 self.log = log
50 self.frame = frame
ae920857
RD
51 self.cwd = os.path.split(sys.argv[0])[0]
52 if not self.cwd:
53 self.cwd = os.getcwd()
ec3e670f 54
ec3e670f
RD
55 self.html = MyHtmlWindow(self, -1, log)
56 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
57 self.html.SetRelatedStatusBar(0)
58
65dd82cb
RD
59 self.printer = wxHtmlEasyPrinting()
60
2f90df85
RD
61 self.box = wxBoxSizer(wxVERTICAL)
62 self.box.Add(self.html, 1, wxGROW)
ec3e670f
RD
63
64 subbox = wxBoxSizer(wxHORIZONTAL)
854862f5
RD
65## btn = wxButton(self, 1201, "Show Default")
66## EVT_BUTTON(self, 1201, self.OnShowDefault)
67## subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
68
69 btn = wxButton(self, 1202, "Load File")
70 EVT_BUTTON(self, 1202, self.OnLoadFile)
2f90df85 71 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
72
73 btn = wxButton(self, 1203, "With Widgets")
74 EVT_BUTTON(self, 1203, self.OnWithWidgets)
2f90df85 75 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
76
77 btn = wxButton(self, 1204, "Back")
78 EVT_BUTTON(self, 1204, self.OnBack)
2f90df85 79 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f
RD
80
81 btn = wxButton(self, 1205, "Forward")
82 EVT_BUTTON(self, 1205, self.OnForward)
2f90df85 83 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 84
65dd82cb
RD
85 btn = wxButton(self, 1207, "Print")
86 EVT_BUTTON(self, 1207, self.OnPrint)
87 subbox.Add(btn, 1, wxGROW | wxALL, 2)
88
e166644c
RD
89 btn = wxButton(self, 1206, "View Source")
90 EVT_BUTTON(self, 1206, self.OnViewSource)
2f90df85 91 subbox.Add(btn, 1, wxGROW | wxALL, 2)
e166644c 92
2f90df85
RD
93 self.box.Add(subbox, 0, wxGROW)
94 self.SetSizer(self.box)
95 self.SetAutoLayout(true)
e166644c
RD
96
97 # A button with this ID is created on the widget test page.
98 EVT_BUTTON(self, wxID_OK, self.OnOk)
99
ec3e670f
RD
100 self.OnShowDefault(None)
101
102
854862f5
RD
103## def __del__(self):
104## print 'TestHtmlPanel.__del__'
eec92d76 105
e166644c 106
ec3e670f
RD
107
108 def OnShowDefault(self, event):
6c5ae2d2 109 name = os.path.join(self.cwd, opj('data/test.htm'))
e166644c 110 self.html.LoadPage(name)
ec3e670f
RD
111
112
113 def OnLoadFile(self, event):
e166644c
RD
114 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
115 if dlg.ShowModal():
116 path = dlg.GetPath()
117 self.html.LoadPage(path)
118 dlg.Destroy()
ec3e670f
RD
119
120
121 def OnWithWidgets(self, event):
ae920857 122 os.chdir(self.cwd)
6c5ae2d2 123 name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
e166644c 124 self.html.LoadPage(name)
ae920857 125
e166644c
RD
126
127 def OnOk(self, event):
128 self.log.WriteText("It works!\n")
ec3e670f
RD
129
130 def OnBack(self, event):
131 if not self.html.HistoryBack():
132 wxMessageBox("No more items in history!")
133
e166644c 134
ec3e670f
RD
135 def OnForward(self, event):
136 if not self.html.HistoryForward():
137 wxMessageBox("No more items in history!")
138
139
e166644c
RD
140 def OnViewSource(self, event):
141 from wxPython.lib.dialogs import wxScrolledMessageDialog
142 source = self.html.GetParser().GetSource()
143 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
144 dlg.ShowModal()
145 dlg.Destroy()
146
147
65dd82cb 148 def OnPrint(self, event):
2f9be787 149 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
65dd82cb
RD
150 self.printer.PrintFile(self.html.GetOpenedPage())
151
ec3e670f
RD
152#----------------------------------------------------------------------
153
154def runTest(frame, nb, log):
155 win = TestHtmlPanel(nb, frame, log)
156 return win
157
158
159#----------------------------------------------------------------------
160
161
162
163
164
165overview = """\
166wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
167
168It 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...
169
170"""
171
e166644c
RD
172
173
174
175
e166644c
RD
176
177
178
179
180