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