jueves, 6 de enero de 2011

Create a basic web browser with python+webkit+gtk

Returning to the programming with python, glade and gtknow explain how to make a simple browser using python webkit.

This post is based on Marcelo's blog article, I create interface with glade.

The figure shows the GUI application.

The application simply has a EntryText, the URL where you can enter to load the page when push button go, the page is loaded into the frame with sliders in the center of the interface and has a button  exit. The default is to load a page to start the application.

The application code is shown below:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Import gtk and webkit

import gtk
import webkit

#class App
class App:
    def __init__(self):
     #function init 
        #bind glade file with Builder object
        self.glade_file = "browser.glade"
        self.glade = gtk.Builder()
        #Binding  window with browser
        self.window = self.glade.get_object('browser')
        #Button exit
        self.exit = self.glade.get_object('bexit')
        #Button browser
        self.go = self.glade.get_object('browse')
        #EntryText URL
        self.link = self.glade.get_object('url')
        #Scrolledwindows where you can see a site
        self.scrolledwindow1 = self.glade.get_object('scrolledwindow1')
        #Linking destroy browser with function
        #Linking clicked exit button
        self.exit.connect('clicked', self.on_bexit_clicked)
        #Linking clicked browse button
        #Linking activate with URL entrytext
        #Open  default site
        #Instant class webview 
        self.webview = webkit.WebView()
        #Add webview in scrolledwindow
        #Open default page
        #Show window 
    def on_url_activate(self,*args):
        #catch url to open page
        url = "http://" + self.enlace.get_text()

    def __go(self,url):
    def on_browser_destroy(self,*args):
        #close application
    def on_bexit_clicked(self,*args):
     #close application
    def on_browse_clicked(self,*args):
        #Open site
        url = "http://" + self.link.get_text()
    def main(self):
     #star application

if __name__ == '__main__':
    app = App()

The following figure shows the browser.

1 comentario:

  1. can you please give me the brower.glade file for above code...