]>
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
)
35 def OnCellMouseHover ( self
, cell
, x
, y
):
36 self
. log
. WriteText ( 'OnCellMouseHover: %s , ( %d %d ) \n ' % ( cell
, x
, y
))
37 self
. base_OnCellMouseHover ( cell
, x
, y
)
39 def OnCellClicked ( self
, cell
, x
, y
, evt
):
40 self
. log
. WriteText ( 'OnCellClicked: %s , ( %d %d ) \n ' % ( cell
, x
, y
))
41 self
. base_OnCellClicked ( cell
, x
, y
, evt
)
44 class TestHtmlPanel ( wxPanel
):
45 def __init__ ( self
, parent
, frame
, log
):
46 wxPanel
.__ init
__ ( self
, parent
, - 1 )
49 self
. cwd
= os
. path
. split ( sys
. argv
[ 0 ])[ 0 ]
51 self
. cwd
= os
. getcwd ()
53 self
. html
= MyHtmlWindow ( self
, - 1 , log
)
54 self
. html
. SetRelatedFrame ( frame
, "wxPython: (A Demonstration) -- %s " )
55 self
. html
. SetRelatedStatusBar ( 0 )
57 self
. printer
= wxHtmlEasyPrinting ()
59 self
. box
= wxBoxSizer ( wxVERTICAL
)
60 self
. box
. Add ( self
. html
, 1 , wxGROW
)
62 subbox
= wxBoxSizer ( wxHORIZONTAL
)
63 ## btn = wxButton(self, 1201, "Show Default")
64 ## EVT_BUTTON(self, 1201, self.OnShowDefault)
65 ## subbox.Add(btn, 1, wxGROW | wxALL, 2)
67 btn
= wxButton ( self
, 1202 , "Load File" )
68 EVT_BUTTON ( self
, 1202 , self
. OnLoadFile
)
69 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
71 btn
= wxButton ( self
, 1203 , "With Widgets" )
72 EVT_BUTTON ( self
, 1203 , self
. OnWithWidgets
)
73 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
75 btn
= wxButton ( self
, 1204 , "Back" )
76 EVT_BUTTON ( self
, 1204 , self
. OnBack
)
77 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
79 btn
= wxButton ( self
, 1205 , "Forward" )
80 EVT_BUTTON ( self
, 1205 , self
. OnForward
)
81 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
83 btn
= wxButton ( self
, 1207 , "Print" )
84 EVT_BUTTON ( self
, 1207 , self
. OnPrint
)
85 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
87 btn
= wxButton ( self
, 1206 , "View Source" )
88 EVT_BUTTON ( self
, 1206 , self
. OnViewSource
)
89 subbox
. Add ( btn
, 1 , wxGROW | wxALL
, 2 )
91 self
. box
. Add ( subbox
, 0 , wxGROW
)
92 self
. SetSizer ( self
. box
)
93 self
. SetAutoLayout ( true
)
95 # A button with this ID is created on the widget test page.
96 EVT_BUTTON ( self
, wxID_OK
, self
. OnOk
)
98 self
. OnShowDefault ( None )
101 ## def __del__(self):
102 ## print 'TestHtmlPanel.__del__'
106 def OnShowDefault ( self
, event
):
107 name
= os
. path
. join ( self
. cwd
, 'data/test.htm' )
108 self
. html
. LoadPage ( name
)
111 def OnLoadFile ( self
, event
):
112 dlg
= wxFileDialog ( self
, wildcard
= '*.htm*' , style
= wxOPEN
)
115 self
. html
. LoadPage ( path
)
119 def OnWithWidgets ( self
, event
):
121 name
= os
. path
. join ( self
. cwd
, 'data/widgetTest.htm' )
122 self
. html
. LoadPage ( name
)
125 def OnOk ( self
, event
):
126 self
. log
. WriteText ( "It works! \n " )
128 def OnBack ( self
, event
):
129 if not self
. html
. HistoryBack ():
130 wxMessageBox ( "No more items in history!" )
133 def OnForward ( self
, event
):
134 if not self
. html
. HistoryForward ():
135 wxMessageBox ( "No more items in history!" )
138 def OnViewSource ( self
, event
):
139 from wxPython
. lib
. dialogs
import wxScrolledMessageDialog
140 source
= self
. html
. GetParser (). GetSource ()
141 dlg
= wxScrolledMessageDialog ( self
, source
, 'HTML Source' )
146 def OnPrint ( self
, event
):
147 ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))
148 self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())
150 #----------------------------------------------------------------------
152 def runTest ( frame
, nb
, log
):
153 win
= TestHtmlPanel ( nb
, frame
, log
)
157 #----------------------------------------------------------------------
164 wxHtmlWindow is capable of parsing and rendering most simple HTML tags.
166 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...