]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxHtmlWindow.py
Switch to a read-only combobox
[wxWidgets.git] / wxPython / demo / wxHtmlWindow.py
CommitLineData
8fa876ca
RD
1# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
ec3e670f 5
8fa876ca
RD
6import os
7import sys
e166644c 8
8fa876ca
RD
9import wx
10import wx.html as html
ec3e670f 11
6c5ae2d2
RD
12from Main import opj
13
fd3f2efe
RD
14##wxTrap()
15
ec3e670f
RD
16#----------------------------------------------------------------------
17
18# This shows how to catch the OnLinkClicked non-event. (It's a virtual
19# method in the C++ code...)
8fa876ca 20class MyHtmlWindow(html.HtmlWindow):
ec3e670f 21 def __init__(self, parent, id, log):
8fa876ca 22 html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
ec3e670f 23 self.log = log
8fa876ca 24 self.Bind(wx.EVT_SCROLLWIN, self.OnScroll )
c368d904
RD
25
26 def OnScroll( self, event ):
a1bfae9d
RD
27 #print 'event.GetOrientation()',event.GetOrientation()
28 #print 'event.GetPosition()',event.GetPosition()
c368d904 29 event.Skip()
ec3e670f 30
9c00cfa3
RD
31 def OnLinkClicked(self, linkinfo):
32 self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
ec3e670f 33
eec92d76 34 # Virtuals in the base class have been renamed with base_ on the front.
9c00cfa3
RD
35 self.base_OnLinkClicked(linkinfo)
36
37
38 def OnSetTitle(self, title):
39 self.log.WriteText('OnSetTitle: %s\n' % title)
40 self.base_OnSetTitle(title)
ec3e670f 41
0122b7e3
RD
42 def OnCellMouseHover(self, cell, x, y):
43 self.log.WriteText('OnCellMouseHover: %s, (%d %d)\n' % (cell, x, y))
44 self.base_OnCellMouseHover(cell, x, y)
45
46 def OnCellClicked(self, cell, x, y, evt):
47 self.log.WriteText('OnCellClicked: %s, (%d %d)\n' % (cell, x, y))
48 self.base_OnCellClicked(cell, x, y, evt)
ec3e670f
RD
49
50
1e4a197e 51# This filter doesn't really do anything but show how to use filters
8fa876ca 52class MyHtmlFilter(html.HtmlFilter):
1e4a197e 53 def __init__(self, log):
8fa876ca 54 html.HtmlFilter.__init__(self)
1e4a197e
RD
55 self.log = log
56
57 # This method decides if this filter is able to read the file
58 def CanRead(self, fsfile):
59 self.log.write("CanRead: %s\n" % fsfile.GetMimeType())
60 return False
61
62 # If CanRead returns True then this method is called to actually
63 # read the file and return the contents.
64 def ReadFile(self, fsfile):
65 return ""
66
67
8fa876ca 68class TestHtmlPanel(wx.Panel):
ec3e670f 69 def __init__(self, parent, frame, log):
8fa876ca 70 wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
ec3e670f
RD
71 self.log = log
72 self.frame = frame
ae920857 73 self.cwd = os.path.split(sys.argv[0])[0]
8fa876ca 74
ae920857
RD
75 if not self.cwd:
76 self.cwd = os.getcwd()
1e4a197e
RD
77 if frame:
78 self.titleBase = frame.GetTitle()
79
8fa876ca 80 html.HtmlWindow_AddFilter(MyHtmlFilter(log))
ec3e670f 81
ec3e670f 82 self.html = MyHtmlWindow(self, -1, log)
1e4a197e 83 self.html.SetRelatedFrame(frame, self.titleBase + " -- %s")
ec3e670f
RD
84 self.html.SetRelatedStatusBar(0)
85
8fa876ca 86 self.printer = html.HtmlEasyPrinting()
65dd82cb 87
8fa876ca
RD
88 self.box = wx.BoxSizer(wx.VERTICAL)
89 self.box.Add(self.html, 1, wx.GROW)
ec3e670f 90
8fa876ca 91 subbox = wx.BoxSizer(wx.HORIZONTAL)
ec3e670f 92
8fa876ca
RD
93 btn = wx.Button(self, -1, "Load File")
94 self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn)
95 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
ec3e670f 96
8fa876ca
RD
97 btn = wx.Button(self, -1, "Load URL")
98 self.Bind(wx.EVT_BUTTON, self.OnLoadURL, btn)
99 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
ec3e670f 100
8fa876ca
RD
101 btn = wx.Button(self, -1, "With Widgets")
102 self.Bind(wx.EVT_BUTTON, self.OnWithWidgets, btn)
103 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
ec3e670f 104
8fa876ca
RD
105 btn = wx.Button(self, -1, "Back")
106 self.Bind(wx.EVT_BUTTON, self.OnBack, btn)
107 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
ec3e670f 108
8fa876ca
RD
109 btn = wx.Button(self, -1, "Forward")
110 self.Bind(wx.EVT_BUTTON, self.OnForward, btn)
111 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
65dd82cb 112
8fa876ca
RD
113 btn = wx.Button(self, -1, "Print")
114 self.Bind(wx.EVT_BUTTON, self.OnPrint, btn)
115 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
a1bfae9d 116
8fa876ca
RD
117 btn = wx.Button(self, -1, "View Source")
118 self.Bind(wx.EVT_BUTTON, self.OnViewSource, btn)
119 subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
e166644c 120
8fa876ca 121 self.box.Add(subbox, 0, wx.GROW)
2f90df85 122 self.SetSizer(self.box)
1e4a197e 123 self.SetAutoLayout(True)
e166644c
RD
124
125 # A button with this ID is created on the widget test page.
8fa876ca 126 self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK)
e166644c 127
ec3e670f
RD
128 self.OnShowDefault(None)
129
130
1e4a197e
RD
131 def ShutdownDemo(self):
132 # put the frame title back
133 if self.frame:
134 self.frame.SetTitle(self.titleBase)
135
ec3e670f
RD
136
137 def OnShowDefault(self, event):
6c5ae2d2 138 name = os.path.join(self.cwd, opj('data/test.htm'))
e166644c 139 self.html.LoadPage(name)
ec3e670f
RD
140
141
142 def OnLoadFile(self, event):
8fa876ca
RD
143 dlg = wx.FileDialog(self, wildcard = '*.htm*', style=wx.OPEN)
144
e166644c
RD
145 if dlg.ShowModal():
146 path = dlg.GetPath()
147 self.html.LoadPage(path)
8fa876ca 148
e166644c 149 dlg.Destroy()
ec3e670f
RD
150
151
a1bfae9d 152 def OnLoadURL(self, event):
8fa876ca
RD
153 dlg = wx.TextEntryDialog(self, "Enter a URL")
154
a1bfae9d
RD
155 if dlg.ShowModal():
156 url = dlg.GetValue()
157 self.html.LoadPage(url)
8fa876ca 158
a1bfae9d
RD
159 dlg.Destroy()
160
161
ec3e670f 162 def OnWithWidgets(self, event):
ae920857 163 os.chdir(self.cwd)
6c5ae2d2 164 name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
e166644c 165 self.html.LoadPage(name)
ae920857 166
e166644c
RD
167
168 def OnOk(self, event):
169 self.log.WriteText("It works!\n")
ec3e670f
RD
170
171 def OnBack(self, event):
172 if not self.html.HistoryBack():
8fa876ca 173 wx.MessageBox("No more items in history!")
ec3e670f 174
e166644c 175
ec3e670f
RD
176 def OnForward(self, event):
177 if not self.html.HistoryForward():
8fa876ca 178 wx.MessageBox("No more items in history!")
ec3e670f
RD
179
180
e166644c 181 def OnViewSource(self, event):
8fa876ca
RD
182 import wx.lib.dialogs as dlgs
183
e166644c 184 source = self.html.GetParser().GetSource()
8fa876ca
RD
185
186 dlg = dlgs.wxScrolledMessageDialog(self, source, 'HTML Source')
e166644c
RD
187 dlg.ShowModal()
188 dlg.Destroy()
189
190
65dd82cb 191 def OnPrint(self, event):
2f9be787 192 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
65dd82cb
RD
193 self.printer.PrintFile(self.html.GetOpenedPage())
194
ec3e670f
RD
195#----------------------------------------------------------------------
196
197def runTest(frame, nb, log):
198 win = TestHtmlPanel(nb, frame, log)
8fa876ca 199 print wx.Window_FindFocus()
ec3e670f
RD
200 return win
201
202
203#----------------------------------------------------------------------
204
205
1e4a197e
RD
206overview = """<html><body>
207<h2>wxHtmlWindow</h2>
ec3e670f 208
1e4a197e
RD
209<p>wxHtmlWindow is capable of parsing and rendering most
210simple HTML tags.
ec3e670f 211
1e4a197e 212<p>It is not intended to be a high-end HTML browser. If you're
8fa876ca
RD
213looking for something like that see the IEHtmlWin class, which
214wraps the core MSIE HTML viewer.
1e4a197e
RD
215
216</body></html>
ec3e670f
RD
217"""
218
e166644c
RD
219
220
1e4a197e
RD
221if __name__ == '__main__':
222 import sys,os
223 import run
224 run.main(['', os.path.basename(sys.argv[0])])
225
e166644c
RD
226
227
e166644c
RD
228
229
230
231
232