Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)
    self.webview.show()

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)
    self.webview.show()




#This sets the buttons in tool bar to work

def on_backbutton_clicked(self, widget):
    self.webview.go_back()

def on_forwardbutton_clicked(self, widget):
    self.webview.go_forward()

def on_refreshbutton_clicked(self, widget):
    self.webview.reload()

def on_stopbutton_clicked(self, widget):
    self.webview.stop_loading()

def on_homebutton_clicked(self, widget):
    self.webview.open(DEFAULT_URL)

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

share|improve this question
add comment

1 Answer

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):
        self.web_view.open(DEFAULT_URL)

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.

share|improve this answer
    
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) –  DriftedMass Apr 20 '13 at 13:11
    
@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? –  DriftedMass 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? –  DriftedMass Apr 20 '13 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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