How to make title-change call work in webkit2gtk?

两盒软妹~` 提交于 2020-08-11 11:05:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!