问题
I am trying to port an old GTK webkit code written in python2 to webkit2 and python3 (Ubuntu has removed old webkit v1). The js code changes the title of the html, and python detected it to close it. However, it is not working in webkit2. In the old code, there is the line
self.webview.connect('title-changed', title_changed) #title_changed is a python function, which will do something
which shows TypeError: <WebKit2.WebView object at 0x7f14b687ecd0 (WebKitWebView at 0x557297cdb7c0)>: unknown signal name: title-changed
.
How to port this code to webkit2? According to https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html there is webkit_web_view_get_title (), but is there any way to detect change of title?
回答1:
Since title
is a property, it automatically comes with a notify
signal you can connect to. Use notify::title
.
Use the following code, for example
self.webview.connect('notify::title', title_changed)
来源:https://stackoverflow.com/questions/63090388/how-to-make-title-change-call-work-in-webkit2gtk