Friday, April 26, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 457  / 1 Year ago, sat, april 22, 2023, 7:26:46

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

More From » application-development

 Answers
1

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.


[#31697] Monday, April 24, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
afyess

Total Points: 437
Total Questions: 120
Total Answers: 107

Location: San Marino
Member since Fri, Jul 3, 2020
4 Years ago
afyess questions
;