1

I tried a bunch of different codes but am still not able to add a back button or add a google search bar.

4
  • 2
    Please provide the information and link of the tutorial you are following in order to get the proper support. Thank you. Oct 14, 2012 at 16:55
  • Language? Link to tutorial? Previous effort? Also, this probably belongs on Stack Overflow.
    – Ry-
    Oct 14, 2012 at 17:27
  • 1
    IMHO, what every new developer needs to learn first is to correctly program. Learn to use your tools. if you are using Quiclkly, then learn to use Glade and the Python Gtk bindings. If you want to use text input and know what can it mean, then learn string manipulation and regular expressions. ;) Oct 14, 2012 at 18:16
  • Every opinion is useful at all but it will be useful if we can have a link on the tutorial that he's attempting so we can focus on providing answers, not HO's. Oct 14, 2012 at 18:18

1 Answer 1

2

If this is the tutorial by Jono Bacon on Youtube, launch glade with quickly design and add a button to the toolbar similar to the refresh button that Jono adds ~12:30. Call it backbutton and create a handler for it when clicked and then sketch a function that will pull the previous URL that was passed (just create a list and append successful URLs to it, then pop it when needed). If you want to preprocess a URL entered in the entrybox, add code in the handler to do it. Here's some sample code:

#Code for other initializing.... 
....whatever goes here...
self.history=[]

def on_urlentry_activate(self,widget):
    #store previous location in history
    self.history.append(self.webview.get_uri())

    url = widget.get_text()

    #add http:// if not present in the url
    if 'http://' not in url:
        url='http://'+url

    self.webview.open(url)


def on_backbutton_activate(self,widget):
    #Only get the last url if there's something to get
    if len(self.history)!=0:
        #Use pop to remove the last entry from the list
        url=self.history.pop()
        self.webview.open(url)

This code is not very sophisticated, but should give you the idea.

As Timo has pointed out, WebKitGTK has a number of great functions and features including a go_back() method (If you read the manual). Here's a callback function which uses it:

def on_backbutton_activate(self, widget):
    if self.webview.can_go_back():
        self.webview.go_back()
2
  • Why would you do that if WebKitGTK has such extended API? Just use the go_back() method: webkitgtk.org/reference/webkitgtk/stable/…
    – Timo
    Oct 14, 2012 at 22:29
  • 1
    Honestly, it's because I didn't RTFM and have never used webkitgtk before. This was simply something that popped in my head and I thought would be instructive to someone learning. But your point is taken and I will add it to the answer.
    – Ian B.
    Oct 15, 2012 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .