]>
git.saurik.com Git - wxWidgets.git/blob - utils/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 font.
22 self
. base_OnLinkClicked ( linkinfo
)
25 def OnSetTitle ( self
, title
):
26 self
. log
. WriteText ( 'OnSetTitle: %s \n ' % title
)
27 self
. base_OnSetTitle ( title
)
31 class TestHtmlPanel ( wxPanel
):
32 def __init__ ( self
, parent
, frame
, log
):
33 wxPanel
.__ init
__ ( self
, parent
, - 1 )
36 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
38 self
. cwd
= os
. getcwd ()
41 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
42 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
43 self
. html
. SetRelatedStatusBar ( 0 )
45 self
. printer
= wxHtmlEasyPrinting ()
47 self
. box
= wxBoxSizer ( wxVERTICAL
)
48 self
. box
. Add ( self
. html
, 1 , wxGROW
)
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 )
55 btn
= wxButton ( self
, 1202 , "Load File" )
56 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
57 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
59 btn
= wxButton ( self
, 1203 , "With Widgets" )
60 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
61 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
63 btn
= wxButton ( self
, 1204 , "Back" )
64 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
65 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
67 btn
= wxButton ( self
, 1205 , "Forward" )
68 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
69 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
71 btn
= wxButton ( self
, 1207 , "Print" )
72 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
73 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
75 btn
= wxButton ( self
, 1206 , "View Source" )
76 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
77 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
79 self
. box
. Add ( subbox
, 0 , wxGROW
)
80 self
. SetSizer ( self
. box
)
81 self
. SetAutoLayout ( true
)
83 # A button with this ID is created on the widget test page.
84 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
86 self
. OnShowDefault ( None )
91 def OnShowDefault ( self
, event
):
92 name
= os
. path
. join ( self
. cwd
, 'data/test.htm' )
93 self
. html
. LoadPage ( name
)
96 def OnLoadFile ( self
, event
):
97 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
100 self
. html
. LoadPage ( path
)
104 def OnWithWidgets ( self
, event
):
106 name
= os
. path
. join ( self
. cwd
, 'data/widgetTest.htm' )
107 self
. html
. LoadPage ( name
)
110 def OnOk ( self
, event
):
111 self
. log
. WriteText ( "It works! \n " )
113 def OnBack ( self
, event
):
114 if not self
. html
. HistoryBack ():
115 wxMessageBox ( "No more items in history!" )
118 def OnForward ( self
, event
):
119 if not self
. html
. HistoryForward ():
120 wxMessageBox ( "No more items in history!" )
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' )
131 def OnPrint ( self
, event
):
132 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
134 #----------------------------------------------------------------------
136 def runTest ( frame
, nb
, log
):
137 win
= TestHtmlPanel ( nb
, frame
, log
)
141 #----------------------------------------------------------------------
148 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
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...