]>
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 )
17 def OnLinkClicked ( self
, link
):
18 self
. log
. WriteText ( 'OnLinkClicked: %s \n ' % link
)
20 # Virtuals in the base class have been renamed with base_ on the font.
21 self
. base_OnLinkClicked ( link
)
25 class TestHtmlPanel ( wxPanel
):
26 def __init__ ( self
, parent
, frame
, log
):
27 wxPanel
.__ init
__ ( self
, parent
, - 1 )
30 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
32 self
. cwd
= os
. getcwd ()
35 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
36 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
37 self
. html
. SetRelatedStatusBar ( 0 )
39 self
. printer
= wxHtmlEasyPrinting ()
41 self
. box
= wxBoxSizer ( wxVERTICAL
)
42 self
. box
. Add ( self
. html
, 1 , wxGROW
)
44 subbox
= wxBoxSizer ( wxHORIZONTAL
)
45 btn
= wxButton ( self
, 1201 , "Show Default" )
46 EVT_BUTTON ( self
, 1201 , self
. OnShowDefault
)
47 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
49 btn
= wxButton ( self
, 1202 , "Load File" )
50 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
51 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
53 btn
= wxButton ( self
, 1203 , "With Widgets" )
54 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
55 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
57 btn
= wxButton ( self
, 1204 , "Back" )
58 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
59 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
61 btn
= wxButton ( self
, 1205 , "Forward" )
62 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
63 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
65 btn
= wxButton ( self
, 1207 , "Print" )
66 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
67 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
69 btn
= wxButton ( self
, 1206 , "View Source" )
70 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
71 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
73 self
. box
. Add ( subbox
, 0 , wxGROW
)
74 self
. SetSizer ( self
. box
)
75 self
. SetAutoLayout ( true
)
77 # A button with this ID is created on the widget test page.
78 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
80 self
. OnShowDefault ( None )
85 def OnShowDefault ( self
, event
):
86 name
= os
. path
. join ( self
. cwd
, 'data/test.htm' )
87 self
. html
. LoadPage ( name
)
90 def OnLoadFile ( self
, event
):
91 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
94 self
. html
. LoadPage ( path
)
98 def OnWithWidgets ( self
, event
):
100 name
= os
. path
. join ( self
. cwd
, 'data/widgetTest.htm' )
101 self
. html
. LoadPage ( name
)
104 def OnOk ( self
, event
):
105 self
. log
. WriteText ( "It works! \n " )
107 def OnBack ( self
, event
):
108 if not self
. html
. HistoryBack ():
109 wxMessageBox ( "No more items in history!" )
112 def OnForward ( self
, event
):
113 if not self
. html
. HistoryForward ():
114 wxMessageBox ( "No more items in history!" )
117 def OnViewSource ( self
, event
):
118 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
119 source
= self
. html
. GetParser (). GetSource ()
120 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
125 def OnPrint ( self
, event
):
126 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
128 #----------------------------------------------------------------------
130 def runTest ( frame
, nb
, log
):
131 win
= TestHtmlPanel ( nb
, frame
, log
)
135 #----------------------------------------------------------------------
142 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
144 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...