hi there im creating a web browser using a mix of quickly and Python, im wanting to get a websites title to show up in the very top of the page. im not sure of what code that i need adding to the file, ive looked all over the internet and that has been of no use.

this is the code i have got for the browser so far :

import gettext
from gettext import gettext as _

from gi.repository import Gtk, WebKit # pylint: disable=E0611
import logging
logger = logging.getLogger('dmbrowser')

from dmbrowser_lib import Window
from dmbrowser.AboutDmbrowserDialog import AboutDmbrowserDialog
from dmbrowser.PreferencesDmbrowserDialog import PreferencesDmbrowserDialog

# See dmbrowser_lib.Window.py for more details about how this class works
class DmbrowserWindow(Window):
    __gtype_name__ = "DmbrowserWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(DmbrowserWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutDmbrowserDialog
        self.PreferencesDialog = PreferencesDmbrowserDialog

        # Code for other initialization actions should be added here.
        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.urlentry = self.builder.get_object("urlentry")
        self.scrolledwindow = self.builder.get_object("scrolledwindow")
        self.toolbar = self.builder.get_object("toolbar")

        context = self.toolbar.get_style_context()

        self.webview = WebKit.WebView()


    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_urlentry_activate(self, widget):
        url = widget.get_text()

        self.webview.open("http://" + url)

        print url

Untested, but the following should work.

self.webview.connect('notify::title', self._title_changed_cb)

def _title_changed_cb(self, webview, title):

You'll probably want a better title, like "%s - %s" % (title, APPNAME).

Edit: Apprently you can't use the title property directly because it's a GParamString type. Just retrieve the title from the webview.

  • Cheers @timo so if i add that directly to the code ive been working n should it start displaying the webpage title in the menu? – Mattn1014 Apr 19 '13 at 12:25
  • @DriftedMass: yes, but in the right place ofcourse :-). The connect should go right after the webview creation and the callback handler can go anywhere in your class. – Timo Apr 19 '13 at 12:44
  • when i tried that code i got this error message when running the program via command prompt self.webview.connect('notify::title', self._title_changed_cb) def _title_changed_cb(self, webview, title): self.set_title(title) that is the message i get, i put the connector here : self.toolbar = self.builder.get_object("toolbar") self.webview = WebKit.WebView() self.webview.connect('notify::title', self._title_changed_cb) any idea of what i have done wrong? – Mattn1014 Apr 19 '13 at 21:29
  • @DriftedMass: please note that formatting gets lost in the comments which makes it hard to see what you're saying. I've made a change to my answer which fixed an error, maybe that's what you are trying to say. – Timo Apr 20 '13 at 8:59
  • Yeah im guessing all that mumbo jumbo that i had entered was saying it produced an error. Sorry for that @timo i could see any other way of adding the error code – Mattn1014 Apr 20 '13 at 12:58
   self.webview.connect('load_committed', self.change_url)
def change_url(self, widget, data=None):
   self.urlentry.set_text( widget.get_main_frame().get_uri() )

it will work check out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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