1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
   | from wxPython.wx import *
from wxPython.html import *
import httplib
 
class MyApp(wxApp):
	def OnInit(self):
            frame = Myframe(None, -1, "Un navigateur web en Python !!")
            frame.Show(true)
            self.SetTopWindow(frame)
            return true
 
class Myframe(wxFrame):
	def __init__(self, parent, id, title):
		wxFrame.__init__(self,parent,id,title)
		self.SetSize(wxSize(400,400))
		self.Center(wxBOTH)
		StatusBar = wxStatusBar(self, -1)
		StatusBar.SetFieldsCount(2)
		self.SetStatusBar(StatusBar)
		MainMenu = wxMenuBar()
		MenuFichier =wxMenu()
		idNav = wxNewId()
		MenuFichier.Append(idNav, 'Naviguer', 'Page de garde de http://localhost')
		EVT_MENU(self, idNav,self.OnNavigate())
		MenuFichier.Append(wxID_EXIT,self.OnCloseWindow(EVT_MENU))
		MainMenu.Append(MenuFichier, 'Fichier')
		Self.SetMenuBar(MainMenu)
		Self.myhtml_window = MyHtmlWindow(self, -1)
 
        def OnCloseWindow(self, event):
            self.Destroy()
 
        def OnNavigate(self, event):
            self.myhtml_window.GetDoc('/')
 
class MyHtmlWindow(wxHtmlWindow):
	def __init__(self, parent, id):
		wxHtmlWindow.__init__(self, parent, id)
		self.http = httplib.HTTP('localhost')
 
	def GetDoc(self, doc):
		self.http.putrequest('GET', doc)
		self.http.putheader('Accept', '/text/html')
		self.http.purheader('Accept','text/plain')
		self.http.endheaders()
                errcode, errmsg, headers = self.http.getreply()
                if not errcode == 200:
                    self.SetPage("Impossible de charger la page : ",errcode)
                #return
 
                handle = self.http.getfile()
                document = handle.read()
                handle.close()
                print headers
                print document
                self.SetPage(document)
 
        def OnlinkClicked(self, linkinfo):
            self.GetDoc('/' + linkinfo.GetHref())
 
app = MyApp(0)
app.MainLoop() | 
Partager