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