from Tkinter import * import re import string class Browser: def __init__(self, fetcher=None): print "initializing Browser..." self.fetcher = fetcher self.root = Tk() self.text_frame=Frame(self.root) self.text_frame.pack(fill=BOTH, expand=1) self.text=Text(self.text_frame) self.text.pack(fill=BOTH, side=LEFT, expand=1) self.textscrolly = Scrollbar(self.text_frame, orient=VERTICAL) self.textscrolly.pack(fill=Y, side=LEFT) self.text.config(yscrollcommand=self.textscrolly.set) self.textscrolly.config(command=self.text.yview) self.location=Entry(self.root) self.location.pack(fill=X) self.location.bind('', lambda e: self._get_location()) self.status = Label(self.root) self.status.pack(fill=X) def display(self,s,url=None, status=None): self.text.delete(1.0,END) self.text.insert(END,s) self.location.delete(0,END) self.status.configure(text='') if url: self.location.insert(END,url) if status: self.status.configure(text=status) def _get_location(self): url = self.location.get() print "url: ", url if self.fetcher: s1 = re.split('//', url)[1] print "s1: ", s1 l = re.split('/', s1) document = '/' + string.join(l[1:], '/') l2 = re.split(':', l[0] ) print l2 if len(l2) > 1: host = l2[0] port = l2[1] print "host: ", host, " port: ", port, " document: ", document else: host = l[0] port = None print "host: ", host, " document: ", document result, status = self.fetcher(host, document, port) self.display(result, url, status)