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