]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxHtmlWindow.py
fixed an error in the sample
[wxWidgets.git] / utils / wxPython / demo / wxHtmlWindow.py
1
2 import sys, os
3
4 from wxPython.wx import *
5 from wxPython.html import *
6 import wxPython.lib.wxpTag
7
8 #----------------------------------------------------------------------
9
10 # This shows how to catch the OnLinkClicked non-event. (It's a virtual
11 # method in the C++ code...)
12 class 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
25 class 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
36 self.box = wxBoxSizer(wxVERTICAL)
37 self.box.Add(self.html, 1, wxGROW)
38
39 subbox = wxBoxSizer(wxHORIZONTAL)
40 btn = wxButton(self, 1201, "Show Default")
41 EVT_BUTTON(self, 1201, self.OnShowDefault)
42 subbox.Add(btn, 1, wxGROW | wxALL, 2)
43
44 btn = wxButton(self, 1202, "Load File")
45 EVT_BUTTON(self, 1202, self.OnLoadFile)
46 subbox.Add(btn, 1, wxGROW | wxALL, 2)
47
48 btn = wxButton(self, 1203, "With Widgets")
49 EVT_BUTTON(self, 1203, self.OnWithWidgets)
50 subbox.Add(btn, 1, wxGROW | wxALL, 2)
51
52 btn = wxButton(self, 1204, "Back")
53 EVT_BUTTON(self, 1204, self.OnBack)
54 subbox.Add(btn, 1, wxGROW | wxALL, 2)
55
56 btn = wxButton(self, 1205, "Forward")
57 EVT_BUTTON(self, 1205, self.OnForward)
58 subbox.Add(btn, 1, wxGROW | wxALL, 2)
59
60 btn = wxButton(self, 1206, "View Source")
61 EVT_BUTTON(self, 1206, self.OnViewSource)
62 subbox.Add(btn, 1, wxGROW | wxALL, 2)
63
64 self.box.Add(subbox, 0, wxGROW)
65 self.SetSizer(self.box)
66 self.SetAutoLayout(true)
67
68 # A button with this ID is created on the widget test page.
69 EVT_BUTTON(self, wxID_OK, self.OnOk)
70
71 self.OnShowDefault(None)
72
73
74
75
76 def OnShowDefault(self, event):
77 name = os.path.join(os.path.split(sys.argv[0])[0], 'data/test.htm')
78 self.html.LoadPage(name)
79
80
81 def OnLoadFile(self, event):
82 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
83 if dlg.ShowModal():
84 path = dlg.GetPath()
85 self.html.LoadPage(path)
86 dlg.Destroy()
87
88
89 def OnWithWidgets(self, event):
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")
97
98 def OnBack(self, event):
99 if not self.html.HistoryBack():
100 wxMessageBox("No more items in history!")
101
102
103 def OnForward(self, event):
104 if not self.html.HistoryForward():
105 wxMessageBox("No more items in history!")
106
107
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
116 #----------------------------------------------------------------------
117
118 def runTest(frame, nb, log):
119 win = TestHtmlPanel(nb, frame, log)
120 return win
121
122
123 #----------------------------------------------------------------------
124
125
126
127
128
129 overview = """\
130 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
131
132 It 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
136
137
138
139
140 _widgetTest = '''\
141 <html><body>
142 The widgets on this page were created dynamically on the fly by a custom
143 wxTagHandler 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>
153 after
154 </body></html>
155 '''
156
157
158
159
160