]>
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 )
16 EVT_SCROLLWIN ( self
, self
. OnScroll
)
18 def OnScroll ( self
, event
):
19 print 'event.GetOrientation()' , event
. GetOrientation ()
20 print 'event.GetPosition()' , event
. GetPosition ()
24 def OnLinkClicked ( self
, linkinfo
):
25 self
. log
. WriteText ( 'OnLinkClicked: %s \n ' % linkinfo
. GetHref ())
27 # Virtuals in the base class have been renamed with base_ on the front.
28 self
. base_OnLinkClicked ( linkinfo
)
31 def OnSetTitle ( self
, title
):
32 self
. log
. WriteText ( 'OnSetTitle: %s \n ' % title
)
33 self
. base_OnSetTitle ( title
)
36 ## print 'MyHtmlWindow.__del__'
39 class TestHtmlPanel ( wxPanel
):
40 def __init__ ( self
, parent
, frame
, log
):
41 wxPanel
.__ init
__ ( self
, parent
, - 1 )
44 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
46 self
. cwd
= os
. getcwd ()
48 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
49 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
50 self
. html
. SetRelatedStatusBar ( 0 )
52 self
. printer
= wxHtmlEasyPrinting ()
54 self
. box
= wxBoxSizer ( wxVERTICAL
)
55 self
. box
. Add ( self
. html
, 1 , wxGROW
)
57 subbox
= wxBoxSizer ( wxHORIZONTAL
)
58 ## btn = wxButton(self, 1201, "Show Default")
59 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
60 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
62 btn
= wxButton ( self
, 1202 , "Load File" )
63 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
64 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
66 btn
= wxButton ( self
, 1203 , "With Widgets" )
67 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
68 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
70 btn
= wxButton ( self
, 1204 , "Back" )
71 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
72 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
74 btn
= wxButton ( self
, 1205 , "Forward" )
75 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
76 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
78 btn
= wxButton ( self
, 1207 , "Print" )
79 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
80 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
82 btn
= wxButton ( self
, 1206 , "View Source" )
83 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
84 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
86 self
. box
. Add ( subbox
, 0 , wxGROW
)
87 self
. SetSizer ( self
. box
)
88 self
. SetAutoLayout ( true
)
90 # A button with this ID is created on the widget test page.
91 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
93 self
. OnShowDefault ( None )
97 ## print 'TestHtmlPanel.__del__'
101 def OnShowDefault ( self
, event
):
102 name
= os
. path
. join ( self
. cwd
, 'data/test.htm' )
103 self
. html
. LoadPage ( name
)
106 def OnLoadFile ( self
, event
):
107 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
110 self
. html
. LoadPage ( path
)
114 def OnWithWidgets ( self
, event
):
116 name
= os
. path
. join ( self
. cwd
, 'data/widgetTest.htm' )
117 self
. html
. LoadPage ( name
)
120 def OnOk ( self
, event
):
121 self
. log
. WriteText ( "It works! \n " )
123 def OnBack ( self
, event
):
124 if not self
. html
. HistoryBack ():
125 wxMessageBox ( "No more items in history!" )
128 def OnForward ( self
, event
):
129 if not self
. html
. HistoryForward ():
130 wxMessageBox ( "No more items in history!" )
133 def OnViewSource ( self
, event
):
134 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
135 source
= self
. html
. GetParser (). GetSource ()
136 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
141 def OnPrint ( self
, event
):
142 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
144 #----------------------------------------------------------------------
146 def runTest ( frame
, nb
, log
):
147 win
= TestHtmlPanel ( nb
, frame
, log
)
151 #----------------------------------------------------------------------
158 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
160 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...