]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxHtmlWindow.py
Bitmap button updates
[wxWidgets.git] / wxPython / demo / wxHtmlWindow.py
CommitLineData
ec3e670f 1
e166644c
RD
2import sys, os
3
4from wxPython.wx import *
5from wxPython.html import *
e166644c 6import wxPython.lib.wxpTag
ec3e670f 7
6c5ae2d2
RD
8from Main import opj
9
ec3e670f
RD
10#----------------------------------------------------------------------
11
12# This shows how to catch the OnLinkClicked non-event. (It's a virtual
13# method in the C++ code...)
14class MyHtmlWindow(wxHtmlWindow):
15 def __init__(self, parent, id, log):
fe953afb 16 wxHtmlWindow.__init__(self, parent, id, style=wxNO_FULL_REPAINT_ON_RESIZE)
ec3e670f 17 self.log = log
c368d904
RD
18 EVT_SCROLLWIN( self, self.OnScroll )
19
20 def OnScroll( self, event ):
a1bfae9d
RD
21 #print 'event.GetOrientation()',event.GetOrientation()
22 #print 'event.GetPosition()',event.GetPosition()
c368d904 23 event.Skip()
ec3e670f 24
9c00cfa3
RD
25
26 def OnLinkClicked(self, linkinfo):
27 self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref())
ec3e670f 28
eec92d76 29 # Virtuals in the base class have been renamed with base_ on the front.
9c00cfa3
RD
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)
ec3e670f 36
0122b7e3
RD
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)
ec3e670f
RD
44
45
46class TestHtmlPanel(wxPanel):
47 def __init__(self, parent, frame, log):
fe953afb 48 wxPanel.__init__(self, parent, -1, style=wxNO_FULL_REPAINT_ON_RESIZE)
ec3e670f
RD
49 self.log = log
50 self.frame = frame
ae920857
RD
51 self.cwd = os.path.split(sys.argv[0])[0]
52 if not self.cwd:
53 self.cwd = os.getcwd()
ec3e670f 54
ec3e670f
RD
55 self.html = MyHtmlWindow(self, -1, log)
56 self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s")
57 self.html.SetRelatedStatusBar(0)
58
65dd82cb
RD
59 self.printer = wxHtmlEasyPrinting()
60
2f90df85
RD
61 self.box = wxBoxSizer(wxVERTICAL)
62 self.box.Add(self.html, 1, wxGROW)
ec3e670f
RD
63
64 subbox = wxBoxSizer(wxHORIZONTAL)
ec3e670f 65
a1bfae9d
RD
66 btn = wxButton(self, -1, "Load File")
67 EVT_BUTTON(self, btn.GetId(), self.OnLoadFile)
2f90df85 68 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 69
a1bfae9d
RD
70 btn = wxButton(self, -1, "Load URL")
71 EVT_BUTTON(self, btn.GetId(), self.OnLoadURL)
2f90df85 72 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 73
a1bfae9d
RD
74 btn = wxButton(self, -1, "With Widgets")
75 EVT_BUTTON(self, btn.GetId(), self.OnWithWidgets)
2f90df85 76 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 77
a1bfae9d
RD
78 btn = wxButton(self, -1, "Back")
79 EVT_BUTTON(self, btn.GetId(), self.OnBack)
2f90df85 80 subbox.Add(btn, 1, wxGROW | wxALL, 2)
ec3e670f 81
a1bfae9d
RD
82 btn = wxButton(self, -1, "Forward")
83 EVT_BUTTON(self, btn.GetId(), self.OnForward)
65dd82cb
RD
84 subbox.Add(btn, 1, wxGROW | wxALL, 2)
85
a1bfae9d
RD
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)
2f90df85 92 subbox.Add(btn, 1, wxGROW | wxALL, 2)
e166644c 93
2f90df85
RD
94 self.box.Add(subbox, 0, wxGROW)
95 self.SetSizer(self.box)
96 self.SetAutoLayout(true)
e166644c
RD
97
98 # A button with this ID is created on the widget test page.
99 EVT_BUTTON(self, wxID_OK, self.OnOk)
100
ec3e670f
RD
101 self.OnShowDefault(None)
102
103
ec3e670f
RD
104
105 def OnShowDefault(self, event):
6c5ae2d2 106 name = os.path.join(self.cwd, opj('data/test.htm'))
e166644c 107 self.html.LoadPage(name)
ec3e670f
RD
108
109
110 def OnLoadFile(self, event):
e166644c
RD
111 dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN)
112 if dlg.ShowModal():
113 path = dlg.GetPath()
114 self.html.LoadPage(path)
115 dlg.Destroy()
ec3e670f
RD
116
117
a1bfae9d
RD
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
ec3e670f 126 def OnWithWidgets(self, event):
ae920857 127 os.chdir(self.cwd)
6c5ae2d2 128 name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
e166644c 129 self.html.LoadPage(name)
ae920857 130
e166644c
RD
131
132 def OnOk(self, event):
133 self.log.WriteText("It works!\n")
ec3e670f
RD
134
135 def OnBack(self, event):
136 if not self.html.HistoryBack():
137 wxMessageBox("No more items in history!")
138
e166644c 139
ec3e670f
RD
140 def OnForward(self, event):
141 if not self.html.HistoryForward():
142 wxMessageBox("No more items in history!")
143
144
e166644c
RD
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
65dd82cb 153 def OnPrint(self, event):
2f9be787 154 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
65dd82cb
RD
155 self.printer.PrintFile(self.html.GetOpenedPage())
156
ec3e670f
RD
157#----------------------------------------------------------------------
158
159def runTest(frame, nb, log):
160 win = TestHtmlPanel(nb, frame, log)
f9b24f07 161 print wxWindow_FindFocus()
ec3e670f
RD
162 return win
163
164
165#----------------------------------------------------------------------
166
167
168
169
170
171overview = """\
172wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
173
174It 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...
175
176"""
177
e166644c
RD
178
179
180
181
e166644c
RD
182
183
184
185
186