]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxHtmlWindow.py
suppress compilation warning
[wxWidgets.git] / 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 EVT_SCROLLWIN( self, self.OnScroll )
17
18 def OnScroll( self, event ):
19 print 'event.GetOrientation()',event.GetOrientation()
20 print 'event.GetPosition()',event.GetPosition()
21 event.Skip()
22
23
24 def OnLinkClicked(self, linkinfo):
25 self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
26
27 # Virtuals in the base class have been renamed with base_ on the front.
28 self.base_OnLinkClicked(linkinfo)
29
30
31 def OnSetTitle(self, title):
32 self.log.WriteText('OnSetTitle: %s\n' % title)
33 self.base_OnSetTitle(title)
34
35 def OnCellMouseHover(self, cell, x, y):
36 self.log.WriteText('OnCellMouseHover: %s, (%d %d)\n' % (cell, x, y))
37 self.base_OnCellMouseHover(cell, x, y)
38
39 def OnCellClicked(self, cell, x, y, evt):
40 self.log.WriteText('OnCellClicked: %s, (%d %d)\n' % (cell, x, y))
41 self.base_OnCellClicked(cell, x, y, evt)
42
43
44 class TestHtmlPanel(wxPanel):
45 def __init__(self, parent, frame, log):
46 wxPanel.__init__(self, parent, -1)
47 self.log = log
48 self.frame = frame
49 self.cwd = os.path.split(sys.argv[0])[0]
50 if not self.cwd:
51 self.cwd = os.getcwd()
52
53 self.html = MyHtmlWindow(self, -1, log)
54 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
55 self.html.SetRelatedStatusBar(0)
56
57 self.printer = wxHtmlEasyPrinting()
58
59 self.box = wxBoxSizer(wxVERTICAL)
60 self.box.Add(self.html, 1, wxGROW)
61
62 subbox = wxBoxSizer(wxHORIZONTAL)
63 ## btn = wxButton(self, 1201, "Show Default")
64 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
65 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
66
67 btn = wxButton(self, 1202, "Load File")
68 EVT_BUTTON(self, 1202, self.OnLoadFile)
69 subbox.Add(btn, 1, wxGROW | wxALL, 2)
70
71 btn = wxButton(self, 1203, "With Widgets")
72 EVT_BUTTON(self, 1203, self.OnWithWidgets)
73 subbox.Add(btn, 1, wxGROW | wxALL, 2)
74
75 btn = wxButton(self, 1204, "Back")
76 EVT_BUTTON(self, 1204, self.OnBack)
77 subbox.Add(btn, 1, wxGROW | wxALL, 2)
78
79 btn = wxButton(self, 1205, "Forward")
80 EVT_BUTTON(self, 1205, self.OnForward)
81 subbox.Add(btn, 1, wxGROW | wxALL, 2)
82
83 btn = wxButton(self, 1207, "Print")
84 EVT_BUTTON(self, 1207, self.OnPrint)
85 subbox.Add(btn, 1, wxGROW | wxALL, 2)
86
87 btn = wxButton(self, 1206, "View Source")
88 EVT_BUTTON(self, 1206, self.OnViewSource)
89 subbox.Add(btn, 1, wxGROW | wxALL, 2)
90
91 self.box.Add(subbox, 0, wxGROW)
92 self.SetSizer(self.box)
93 self.SetAutoLayout(true)
94
95 # A button with this ID is created on the widget test page.
96 EVT_BUTTON(self, wxID_OK, self.OnOk)
97
98 self.OnShowDefault(None)
99
100
101 ## def __del__(self):
102 ## print 'TestHtmlPanel.__del__'
103
104
105
106 def OnShowDefault(self, event):
107 name = os.path.join(self.cwd, 'data/test.htm')
108 self.html.LoadPage(name)
109
110
111 def OnLoadFile(self, event):
112 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
113 if dlg.ShowModal():
114 path = dlg.GetPath()
115 self.html.LoadPage(path)
116 dlg.Destroy()
117
118
119 def OnWithWidgets(self, event):
120 os.chdir(self.cwd)
121 name = os.path.join(self.cwd, 'data/widgetTest.htm')
122 self.html.LoadPage(name)
123
124
125 def OnOk(self, event):
126 self.log.WriteText("It works!\n")
127
128 def OnBack(self, event):
129 if not self.html.HistoryBack():
130 wxMessageBox("No more items in history!")
131
132
133 def OnForward(self, event):
134 if not self.html.HistoryForward():
135 wxMessageBox("No more items in history!")
136
137
138 def OnViewSource(self, event):
139 from wxPython.lib.dialogs import wxScrolledMessageDialog
140 source = self.html.GetParser().GetSource()
141 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
142 dlg.ShowModal()
143 dlg.Destroy()
144
145
146 def OnPrint(self, event):
147 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
148 self.printer.PrintFile(self.html.GetOpenedPage())
149
150 #----------------------------------------------------------------------
151
152 def runTest(frame, nb, log):
153 win = TestHtmlPanel(nb, frame, log)
154 return win
155
156
157 #----------------------------------------------------------------------
158
159
160
161
162
163 overview = """\
164 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
165
166 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...
167
168 """
169
170
171
172
173
174
175
176
177
178