]>
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
10 #----------------------------------------------------------------------
12 # This shows how to catch the OnLinkClicked non-event. (It's a virtual
13 # method in the C++ code...)
14 class MyHtmlWindow ( wxHtmlWindow
):
15 def __init__ ( self
, parent
, id , log
):
16 wxHtmlWindow
.__ init
__ ( self
, parent
, id )
18 EVT_SCROLLWIN ( self
, self
. OnScroll
)
20 def OnScroll ( self
, event
):
21 print 'event.GetOrientation()' , event
. GetOrientation ()
22 print 'event.GetPosition()' , event
. GetPosition ()
26 def OnLinkClicked ( self
, linkinfo
):
27 self
. log
. WriteText ( 'OnLinkClicked: %s \n ' % linkinfo
. GetHref ())
29 # Virtuals in the base class have been renamed with base_ on the front.
30 self
. base_OnLinkClicked ( linkinfo
)
33 def OnSetTitle ( self
, title
):
34 self
. log
. WriteText ( 'OnSetTitle: %s \n ' % title
)
35 self
. base_OnSetTitle ( title
)
37 def OnCellMouseHover ( self
, cell
, x
, y
):
38 self
. log
. WriteText ( 'OnCellMouseHover: %s , ( %d %d ) \n ' % ( cell
, x
, y
))
39 self
. base_OnCellMouseHover ( cell
, x
, y
)
41 def OnCellClicked ( self
, cell
, x
, y
, evt
):
42 self
. log
. WriteText ( 'OnCellClicked: %s , ( %d %d ) \n ' % ( cell
, x
, y
))
43 self
. base_OnCellClicked ( cell
, x
, y
, evt
)
46 class TestHtmlPanel ( wxPanel
):
47 def __init__ ( self
, parent
, frame
, log
):
48 wxPanel
.__ init
__ ( self
, parent
, - 1 )
51 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
53 self
. cwd
= os
. getcwd ()
55 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
56 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
57 self
. html
. SetRelatedStatusBar ( 0 )
59 self
. printer
= wxHtmlEasyPrinting ()
61 self
. box
= wxBoxSizer ( wxVERTICAL
)
62 self
. box
. Add ( self
. html
, 1 , wxGROW
)
64 subbox
= wxBoxSizer ( wxHORIZONTAL
)
65 ## btn = wxButton(self, 1201, "Show Default")
66 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
67 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
69 btn
= wxButton ( self
, 1202 , "Load File" )
70 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
71 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
73 btn
= wxButton ( self
, 1203 , "With Widgets" )
74 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
75 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
77 btn
= wxButton ( self
, 1204 , "Back" )
78 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
79 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
81 btn
= wxButton ( self
, 1205 , "Forward" )
82 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
83 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
85 btn
= wxButton ( self
, 1207 , "Print" )
86 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
87 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
89 btn
= wxButton ( self
, 1206 , "View Source" )
90 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
91 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
93 self
. box
. Add ( subbox
, 0 , wxGROW
)
94 self
. SetSizer ( self
. box
)
95 self
. SetAutoLayout ( true
)
97 # A button with this ID is created on the widget test page.
98 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
100 self
. OnShowDefault ( None )
103 ## def __del__(self):
104 ## print 'TestHtmlPanel.__del__'
108 def OnShowDefault ( self
, event
):
109 name
= os
. path
. join ( self
. cwd
, opj ( 'data/test.htm' ))
110 self
. html
. LoadPage ( name
)
113 def OnLoadFile ( self
, event
):
114 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
117 self
. html
. LoadPage ( path
)
121 def OnWithWidgets ( self
, event
):
123 name
= os
. path
. join ( self
. cwd
, opj ( 'data/widgetTest.htm' ))
124 self
. html
. LoadPage ( name
)
127 def OnOk ( self
, event
):
128 self
. log
. WriteText ( "It works! \n " )
130 def OnBack ( self
, event
):
131 if not self
. html
. HistoryBack ():
132 wxMessageBox ( "No more items in history!" )
135 def OnForward ( self
, event
):
136 if not self
. html
. HistoryForward ():
137 wxMessageBox ( "No more items in history!" )
140 def OnViewSource ( self
, event
):
141 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
142 source
= self
. html
. GetParser (). GetSource ()
143 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
148 def OnPrint ( self
, event
):
149 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
150 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
152 #----------------------------------------------------------------------
154 def runTest ( frame
, nb
, log
):
155 win
= TestHtmlPanel ( nb
, frame
, log
)
159 #----------------------------------------------------------------------
166 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
168 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...