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