how do you code in a home button for a web browser?

im creating a web browser in ubuntu for use in ubuntu. I am using a mix of Glade, Python, quickly, WebKit and WebView

i have got nearly everything done and thought a home button would be a nice touch. I already have the home button in place just need to know how to get it to work.

for the tabbed buttons i have done this:

        self.webview = WebKit.WebView()
    self.scrolledwindow1.add(self, webview)
    self.scrolledwindow2.add(self, webview)
    self.scrolledwindow3.add(self, webview)

the way i have set that tabbed windows and the scrolledwindow out in glade is like this:

tab1 holds scrolledwindow1 tab2 holds scrolledwindow2 tab3 holds scrolledwindow3

when i do "quickly run" i get this error message:

/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `Window' can't be set after construction

Gtk.Window.init(self, type=type, **kwds) Traceback (most recent call last): File "bin/dm-test", line 33, in dm_test.main() File "/home/matty/dm-test/dm_test/init.py", line 33, in main window = DmTestWindow.DmTestWindow() File "/home/matty/dm-test/dm_test_lib/Window.py", line 35, in new new_object.finish_initializing(builder) File "/home/matty/dm-test/dm_test/DmTestWindow.py", line 55, in finish_initializing self.scrolledwindow1.add(self, webview) AttributeError: 'DmTestWindow' object has no attribute 'scrolledwindow1'

now im not sure if im actually calling the tab's and the scrolledwindow in the right way or not. Below is the full code that i have written for this to work (was working before tabbed window idea)

# Code for other initialization actions should be added here.

#this builds the tool back and all the buttons(defines)

    self.toolbar = self.builder.get_object("toolbar")
    self.backbutton = self.builder.get_object("backbutton")
    self.forwardbutton = self.builder.get_object("forwardbutton")
    self.refreshbutton = self.builder.get_object("refreshbutton")
    self.stopbutton = self.builder.get_object("stopbutton")
    self.homebutton = self.builder.get_object("homebutton")
    self.urlentry = self.builder.get_object("urlentry")
    self.webview = WebKit.WebView()
    self.scrolledwindow1.add(self, webview)
    self.scrolledwindow2.add(self, webview)
    self.scrolledwindow3.add(self, webview)

#This sets the buttons in tool bar to work

def on_backbutton_clicked(self, widget):

def on_forwardbutton_clicked(self, widget):

def on_refreshbutton_clicked(self, widget):

def on_stopbutton_clicked(self, widget):

def on_homebutton_clicked(self, widget):

def on_url_entry_activate(self, widget):
    url = widget.get_text()
    self.webview.open("http://" + url)
    print url

has anyone got any ideas how i can properly set the tabbed windows (want it to look abit like chromium) the code to set it would also be helpful or a sample of the code i would need to use and a explanation on how to use it if possible.

many thanks in advance


A home button is very simple, considering you already have the button and handler created through Glade:

# You'll probably have this laying around somewhere already
DEFAULT_URL = "http://www.ubuntu.com"

# class
    # init etc

    def on_home_clicked(self, widget):

Making your browser tabbed is a bit more work. You should created a GtkNotebook inside your window and pack each browserview into a seperate page.

  • cheers @timo, so to do the tabbed browser part i would need to add a scrollable window to each tab and add the code ive currently added for each window to work as a web page? (with of course changing the name of each scolledwindow for the corrisponding one) – Mattn1014 Apr 20 '13 at 13:11
  • 1
    @DriftedMass: best way is to seperate window and browserpage into different classes. Build the window and notebook in the window class, and the toolbar with webview in a seperate class (BrowserView for example). Then you can create a new BrowserView instance for each tab in the notebook. – Timo Apr 20 '13 at 13:27
  • so if i firstly add the notebook, create the URL Entry inside each notebook tab, add the scrolledwindow to each tab and then for each set of tabs create its own seperate class? would that work properly or am i best creating the notebook tabs, adding the URL entry to all the tabs (adding it above the tabbed windows) then inside the tabbed windows adding the scrolled window? – Mattn1014 Apr 20 '13 at 13:43
  • i have now sorted the problem with the default_url. However if you take a look at my edited question you will notice that i have now added the code i have added for the tabbed browser. i can not for the life of me figure out how to get this working properly. any ideas? – Mattn1014 Apr 20 '13 at 15:14

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.