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