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 63
| 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(wxID_OPEN, 'Naviguer', 'Page de garde de http://localhost')
MenuFichier.Append(wxID_EXIT, "Fermer")
MainMenu.Append(MenuFichier, 'Fichier')
self.SetMenuBar(MainMenu)
self.myhtml_window = MyHtmlWindow(self, -1)
self.Bind(EVT_MENU, self.OnCloseWindow, id = wxID_EXIT)
self.Bind(EVT_MENU, self.OnNavigate, id = wxID_OPEN)
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.putheader('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