]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxHtmlWindow.py
Fix Cygwin and MinGW compilation
[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 ## btn = wxButton(self, 1201, "Show Default")
66 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
67 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
68
69 btn = wxButton(self, 1202, "Load File")
70 EVT_BUTTON(self, 1202, self.OnLoadFile)
71 subbox.Add(btn, 1, wxGROW | wxALL, 2)
72
73 btn = wxButton(self, 1203, "With Widgets")
74 EVT_BUTTON(self, 1203, self.OnWithWidgets)
75 subbox.Add(btn, 1, wxGROW | wxALL, 2)
76
77 btn = wxButton(self, 1204, "Back")
78 EVT_BUTTON(self, 1204, self.OnBack)
79 subbox.Add(btn, 1, wxGROW | wxALL, 2)
80
81 btn = wxButton(self, 1205, "Forward")
82 EVT_BUTTON(self, 1205, self.OnForward)
83 subbox.Add(btn, 1, wxGROW | wxALL, 2)
84
85 btn = wxButton(self, 1207, "Print")
86 EVT_BUTTON(self, 1207, self.OnPrint)
87 subbox.Add(btn, 1, wxGROW | wxALL, 2)
88
89 btn = wxButton(self, 1206, "View Source")
90 EVT_BUTTON(self, 1206, self.OnViewSource)
91 subbox.Add(btn, 1, wxGROW | wxALL, 2)
92
93 self.box.Add(subbox, 0, wxGROW)
94 self.SetSizer(self.box)
95 self.SetAutoLayout(true)
96
97 # A button with this ID is created on the widget test page.
98 EVT_BUTTON(self, wxID_OK, self.OnOk)
99
100 self.OnShowDefault(None)
101
102
103 ## def __del__(self):
104 ## print 'TestHtmlPanel.__del__'
105
106
107
108 def OnShowDefault(self, event):
109 name = os.path.join(self.cwd, opj('data/test.htm'))
110 self.html.LoadPage(name)
111
112
113 def OnLoadFile(self, event):
114 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
115 if dlg.ShowModal():
116 path = dlg.GetPath()
117 self.html.LoadPage(path)
118 dlg.Destroy()
119
120
121 def OnWithWidgets(self, event):
122 os.chdir(self.cwd)
123 name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
124 self.html.LoadPage(name)
125
126
127 def OnOk(self, event):
128 self.log.WriteText("It works!\n")
129
130 def OnBack(self, event):
131 if not self.html.HistoryBack():
132 wxMessageBox("No more items in history!")
133
134
135 def OnForward(self, event):
136 if not self.html.HistoryForward():
137 wxMessageBox("No more items in history!")
138
139
140 def OnViewSource(self, event):
141 from wxPython.lib.dialogs import wxScrolledMessageDialog
142 source = self.html.GetParser().GetSource()
143 dlg = wxScrolledMessageDialog(self, source, 'HTML Source')
144 dlg.ShowModal()
145 dlg.Destroy()
146
147
148 def OnPrint(self, event):
149 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
150 self.printer.PrintFile(self.html.GetOpenedPage())
151
152 #----------------------------------------------------------------------
153
154 def runTest(frame, nb, log):
155 win = TestHtmlPanel(nb, frame, log)
156 return win
157
158
159 #----------------------------------------------------------------------
160
161
162
163
164
165 overview = """\
166 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
167
168 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...
169
170 """
171
172
173
174
175
176
177
178
179
180