]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxHtmlWindow.py 
bdafa03d36a19cbee616cafa9c677636e0108037
   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
)   66          btn 
=  wxButton ( self
, - 1 ,  "Load File" )   67          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnLoadFile
)   68          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   70          btn 
=  wxButton ( self
, - 1 ,  "Load URL" )   71          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnLoadURL
)   72          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   74          btn 
=  wxButton ( self
, - 1 ,  "With Widgets" )   75          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnWithWidgets
)   76          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   78          btn 
=  wxButton ( self
, - 1 ,  "Back" )   79          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnBack
)   80          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   82          btn 
=  wxButton ( self
, - 1 ,  "Forward" )   83          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnForward
)   84          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   86          btn 
=  wxButton ( self
, - 1 ,  "Print" )   87          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnPrint
)   88          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   90          btn 
=  wxButton ( self
, - 1 ,  "View Source" )   91          EVT_BUTTON ( self
,  btn
. GetId (),  self
. OnViewSource
)   92          subbox
. Add ( btn
,  1 ,  wxGROW | wxALL
,  2 )   94          self
. box
. Add ( subbox
,  0 ,  wxGROW
)   95          self
. SetSizer ( self
. box
)   96          self
. SetAutoLayout ( true
)   98          # A button with this ID is created on the widget test page.   99          EVT_BUTTON ( self
,  wxID_OK
,  self
. OnOk
)  101          self
. OnShowDefault ( None )  105      def  OnShowDefault ( self
,  event
):  106          name 
=  os
. path
. join ( self
. cwd
,  opj ( 'data/test.htm' ))  107          self
. html
. LoadPage ( name
)  110      def  OnLoadFile ( self
,  event
):  111          dlg 
=  wxFileDialog ( self
,  wildcard 
=  '*.htm*' ,  style
= wxOPEN
)  114              self
. html
. LoadPage ( path
)  118      def  OnLoadURL ( self
,  event
):  119          dlg 
=  wxTextEntryDialog ( self
,  "Enter a URL" )  122              self
. html
. LoadPage ( url
)  126      def  OnWithWidgets ( self
,  event
):  128          name 
=  os
. path
. join ( self
. cwd
,  opj ( 'data/widgetTest.htm' ))  129          self
. html
. LoadPage ( name
)  132      def  OnOk ( self
,  event
):  133          self
. log
. WriteText ( "It works! \n " )  135      def  OnBack ( self
,  event
):  136          if not  self
. html
. HistoryBack ():  137              wxMessageBox ( "No more items in history!" )  140      def  OnForward ( self
,  event
):  141          if not  self
. html
. HistoryForward ():  142              wxMessageBox ( "No more items in history!" )  145      def  OnViewSource ( self
,  event
):  146          from  wxPython
. lib
. dialogs 
import  wxScrolledMessageDialog
 147          source 
=  self
. html
. GetParser (). GetSource ()  148          dlg 
=  wxScrolledMessageDialog ( self
,  source
,  'HTML Source' )  153      def  OnPrint ( self
,  event
):  154          ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100))  155          self
. printer
. PrintFile ( self
. html
. GetOpenedPage ())  157  #----------------------------------------------------------------------  159  def  runTest ( frame
,  nb
,  log
):  160      win 
=  TestHtmlPanel ( nb
,  frame
,  log
)  164  #----------------------------------------------------------------------  171  wxHtmlWindow is capable of parsing and rendering most simple HTML tags.  173  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...