]>
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 )
32 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
33 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
34 self
. html
. SetRelatedStatusBar ( 0 )
36 self
. box
= wxBoxSizer ( wxVERTICAL
)
37 self
. box
. Add ( self
. html
, 1 , wxGROW
)
39 subbox
= wxBoxSizer ( wxHORIZONTAL
)
40 btn
= wxButton ( self
, 1201 , "Show Default" )
41 EVT_BUTTON ( self
, 1201 , self
. OnShowDefault
)
42 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
44 btn
= wxButton ( self
, 1202 , "Load File" )
45 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
46 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
48 btn
= wxButton ( self
, 1203 , "With Widgets" )
49 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
50 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
52 btn
= wxButton ( self
, 1204 , "Back" )
53 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
54 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
56 btn
= wxButton ( self
, 1205 , "Forward" )
57 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
58 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
60 btn
= wxButton ( self
, 1206 , "View Source" )
61 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
62 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
64 self
. box
. Add ( subbox
, 0 , wxGROW
)
65 self
. SetSizer ( self
. box
)
66 self
. SetAutoLayout ( true
)
68 # A button with this ID is created on the widget test page.
69 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
71 self
. OnShowDefault ( None )
76 def OnShowDefault ( self
, event
):
77 name
= os
. path
. join ( os
. path
. split ( sys
. argv
[ 0 ])[ 0 ], 'data/test.htm' )
78 self
. html
. LoadPage ( name
)
81 def OnLoadFile ( self
, event
):
82 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
85 self
. html
. LoadPage ( path
)
89 def OnWithWidgets ( self
, event
):
90 os
. chdir ( os
. path
. split ( sys
. argv
[ 0 ])[ 0 ])
91 name
= os
. path
. join ( os
. path
. split ( sys
. argv
[ 0 ])[ 0 ], 'data/widgetTest.htm' )
92 self
. html
. LoadPage ( name
)
93 #self.html.SetPage(_widgetTest)
95 def OnOk ( self
, event
):
96 self
. log
. WriteText ( "It works! \n " )
98 def OnBack ( self
, event
):
99 if not self
. html
. HistoryBack ():
100 wxMessageBox ( "No more items in history!" )
103 def OnForward ( self
, event
):
104 if not self
. html
. HistoryForward ():
105 wxMessageBox ( "No more items in history!" )
108 def OnViewSource ( self
, event
):
109 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
110 source
= self
. html
. GetParser (). GetSource ()
111 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
116 #----------------------------------------------------------------------
118 def runTest ( frame
, nb
, log
):
119 win
= TestHtmlPanel ( nb
, frame
, log
)
123 #----------------------------------------------------------------------
130 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
132 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...
142 The widgets on this page were created dynamically on the fly by a custom
143 wxTagHandler found in wxPython.lib.wxpTag.
147 <wxp class="wxButton" width="50%">
148 <param name="label" value="It works!">
149 <param name="id" value="wxID_OK">