]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxHtmlWindow.py
Added some test code...
[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 self.cwd = os.path.split(sys.argv[0])[0]
31 if not self.cwd:
32 self.cwd = os.getcwd()
33
34
35 self.html = MyHtmlWindow(self, -1, log)
36 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
37 self.html.SetRelatedStatusBar(0)
38
39 self.printer = wxHtmlEasyPrinting()
40
41 self.box = wxBoxSizer(wxVERTICAL)
42 self.box.Add(self.html, 1, wxGROW)
43
44 subbox = wxBoxSizer(wxHORIZONTAL)
45 btn = wxButton(self, 1201, "Show Default")
46 EVT_BUTTON(self, 1201, self.OnShowDefault)
47 subbox.Add(btn, 1, wxGROW | wxALL, 2)
48
49 btn = wxButton(self, 1202, "Load File")
50 EVT_BUTTON(self, 1202, self.OnLoadFile)
51 subbox.Add(btn, 1, wxGROW | wxALL, 2)
52
53 btn = wxButton(self, 1203, "With Widgets")
54 EVT_BUTTON(self, 1203, self.OnWithWidgets)
55 subbox.Add(btn, 1, wxGROW | wxALL, 2)
56
57 btn = wxButton(self, 1204, "Back")
58 EVT_BUTTON(self, 1204, self.OnBack)
59 subbox.Add(btn, 1, wxGROW | wxALL, 2)
60
61 btn = wxButton(self, 1205, "Forward")
62 EVT_BUTTON(self, 1205, self.OnForward)
63 subbox.Add(btn, 1, wxGROW | wxALL, 2)
64
65 btn = wxButton(self, 1207, "Print")
66 EVT_BUTTON(self, 1207, self.OnPrint)
67 subbox.Add(btn, 1, wxGROW | wxALL, 2)
68
69 btn = wxButton(self, 1206, "View Source")
70 EVT_BUTTON(self, 1206, self.OnViewSource)
71 subbox.Add(btn, 1, wxGROW | wxALL, 2)
72
73 self.box.Add(subbox, 0, wxGROW)
74 self.SetSizer(self.box)
75 self.SetAutoLayout(true)
76
77 # A button with this ID is created on the widget test page.
78 EVT_BUTTON(self, wxID_OK, self.OnOk)
79
80 self.OnShowDefault(None)
81
82
83
84
85 def OnShowDefault(self, event):
86 name = os.path.join(self.cwd, 'data/test.htm')
87 self.html.LoadPage(name)
88
89
90 def OnLoadFile(self, event):
91 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
92 if dlg.ShowModal():
93 path = dlg.GetPath()
94 self.html.LoadPage(path)
95 dlg.Destroy()
96
97
98 def OnWithWidgets(self, event):
99 os.chdir(self.cwd)
100 name = os.path.join(self.cwd, 'data/widgetTest.htm')
101 self.html.LoadPage(name)
102
103
104 def OnOk(self, event):
105 self.log.WriteText("It works!\n")
106
107 def OnBack(self, event):
108 if not self.html.HistoryBack():
109 wxMessageBox("No more items in history!")
110
111
112 def OnForward(self, event):
113 if not self.html.HistoryForward():
114 wxMessageBox("No more items in history!")
115
116
117 def OnViewSource(self, event):
118 from wxPython.lib.dialogs import wxScrolledMessageDialog
119 source = self.html.GetParser().GetSource()
120 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
121 dlg.ShowModal()
122 dlg.Destroy()
123
124
125 def OnPrint(self, event):
126 self.printer.PrintFile(self.html.GetOpenedPage())
127
128 #----------------------------------------------------------------------
129
130 def runTest(frame, nb, log):
131 win = TestHtmlPanel(nb, frame, log)
132 return win
133
134
135 #----------------------------------------------------------------------
136
137
138
139
140
141 overview = """\
142 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
143
144 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...
145
146 """
147
148
149
150
151
152
153
154
155
156