]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxHtmlWindow.py
4 from wxPython
. wx
import *
5 from wxPython
. html
import *
6 import wxPython
. lib
. wxpTag
8 #----------------------------------------------------------------------
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 )
18 def OnLinkClicked ( self
, linkinfo
):
19 self
. log
. WriteText ( 'OnLinkClicked: %s \n ' % linkinfo
. GetHref ())
21 # Virtuals in the base class have been renamed with base_ on the front.
22 self
. base_OnLinkClicked ( linkinfo
)
25 def OnSetTitle ( self
, title
):
26 self
. log
. WriteText ( 'OnSetTitle: %s \n ' % title
)
27 self
. base_OnSetTitle ( title
)
30 ## print 'MyHtmlWindow.__del__'
33 class TestHtmlPanel ( wxPanel
):
34 def __init__ ( self
, parent
, frame
, log
):
35 wxPanel
.__ init
__ ( self
, parent
, - 1 )
38 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
40 self
. cwd
= os
. getcwd ()
42 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
43 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
44 self
. html
. SetRelatedStatusBar ( 0 )
46 self
. printer
= wxHtmlEasyPrinting ()
48 self
. box
= wxBoxSizer ( wxVERTICAL
)
49 self
. box
. Add ( self
. html
, 1 , wxGROW
)
51 subbox
= wxBoxSizer ( wxHORIZONTAL
)
52 ## btn = wxButton(self, 1201, "Show Default")
53 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
54 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
56 btn
= wxButton ( self
, 1202 , "Load File" )
57 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
58 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
60 btn
= wxButton ( self
, 1203 , "With Widgets" )
61 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
62 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
64 btn
= wxButton ( self
, 1204 , "Back" )
65 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
66 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
68 btn
= wxButton ( self
, 1205 , "Forward" )
69 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
70 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
72 btn
= wxButton ( self
, 1207 , "Print" )
73 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
74 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
76 btn
= wxButton ( self
, 1206 , "View Source" )
77 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
78 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
80 self
. box
. Add ( subbox
, 0 , wxGROW
)
81 self
. SetSizer ( self
. box
)
82 self
. SetAutoLayout ( true
)
84 # A button with this ID is created on the widget test page.
85 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
87 self
. OnShowDefault ( None )
91 ## print 'TestHtmlPanel.__del__'
95 def OnShowDefault ( self
, event
):
96 name
= os
. path
. join ( self
. cwd
, 'data/test.htm' )
97 self
. html
. LoadPage ( name
)
100 def OnLoadFile ( self
, event
):
101 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
104 self
. html
. LoadPage ( path
)
108 def OnWithWidgets ( self
, event
):
110 name
= os
. path
. join ( self
. cwd
, 'data/widgetTest.htm' )
111 self
. html
. LoadPage ( name
)
114 def OnOk ( self
, event
):
115 self
. log
. WriteText ( "It works! \n " )
117 def OnBack ( self
, event
):
118 if not self
. html
. HistoryBack ():
119 wxMessageBox ( "No more items in history!" )
122 def OnForward ( self
, event
):
123 if not self
. html
. HistoryForward ():
124 wxMessageBox ( "No more items in history!" )
127 def OnViewSource ( self
, event
):
128 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
129 source
= self
. html
. GetParser (). GetSource ()
130 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
135 def OnPrint ( self
, event
):
136 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
138 #----------------------------------------------------------------------
140 def runTest ( frame
, nb
, log
):
141 win
= TestHtmlPanel ( nb
, frame
, log
)
145 #----------------------------------------------------------------------
152 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
154 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...