【发布时间】:2020-12-07 22:44:57
【问题描述】:
我如何以非交互方式访问现有 GTK 应用程序的小部件树?我想查询一个小部件的坐标,如果可能的话发送事件(悬停、点击、按键……)。
使用 GTKInspector,我可以交互地浏览小部件树并查看小部件的大小和坐标。我想使用命令行工具或使用任何语言的 GTK API 访问此信息。
# Steps to do this interactively, I'd like a non-interactive version.
sudo apt install libgtk-3-dev
gsettings set org.gtk.Settings.Debug enable-inspector-keybinding true
GTK_DEBUG=interactive mate-calc
# Then go to `MathWindow → GtkBox → GtkMenuBar`
# click on the (i) icon to show the details view
# `allocation` indicates the `width×height+x+y`, here it's `312×25+0+0`
我考虑过的解决方案:
- 使用 xdotool 自动控制 GTKInspector(预计性能不佳 + 需要额外的 GTKInspector 窗口)。
- 使用 dbus,但
d-feet不显示小部件树,我怀疑它显示的关于interface的内容是关于 OOP 或 d-bus 接口,而不是关于某些 用户 接口。 - 在过去的美好时光中,我们可以使用
dcop为 QT 应用程序做类似的事情,但它当然不适用于 GTK。
【问题讨论】:
标签: widget gtk ui-automation gtk3 gtk2