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.

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 _
gettext.textdomain('dmbrowser')

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()
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        self.webview = WebKit.WebView()

        self.scrolledwindow.add(self.webview)
        self.webview.show()

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

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

        print url
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Untested, but the following should work.

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

def _title_changed_cb(self, webview, title):
    self.set_title(webview.get_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.

share|improve this answer
    
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? –  DriftedMass 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? –  DriftedMass 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 –  DriftedMass Apr 20 '13 at 12:58

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.