widget - 远程控制/检查现有 GTK 应用程序

标签 widget gtk ui-automation gtk3 gtk2

如何非交互式访问现有 GTK 应用程序的小部件树?我想查询小部件的坐标,如果可能的话发送事件(悬停、单击、按键……)。

使用 GTKInspector,我可以交互地浏览小部件树并查看小部件的大小和坐标。我想使用命令行工具或使用任何语言的 GTK API 来访问此信息。

Screenshot of mate-calc with GTKInspector in the background.

# 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接口(interface)的,而不是关于一些用户界面。
  • 回到过去的美好时光,我们可以使用 dcop 对 QT 应用程序执行类似的操作,但它当然不适用于 GTK。

最佳答案

dogtail使用辅助技术访问应用程序的小部件树。在 Xubuntu 20.04 上测试。

$ sudo apt install python3-dogtail
$ sniff # explore using a GUI, it will enable assistive technologies for you.

dogtail-example.py :

#!/usr/bin/env python3
from dogtail.tree import *
app = root.application('mate-calc')
menuBar = app.findChildren(predicate.GenericPredicate(roleName="menu bar"))[0]
print('On-screen coordinates: ', menuBar.position)
print('Size:                  ', menuBar.size)
# to preview the nodes available in the menu bar, use menuBar.dump()

输出:

$ python3 dogtail-example.py
On-screen coordinates: (529, 431)
Size:                  (312, 25)

/usr/share/doc/python3-dogtail/examples/中有一些例子但实际的“doc”位于 /usr/lib/python3/dist-packages/dogtail/tree.py 的文档字符串中以及该目录中的其他文件。

关于widget - 远程控制/检查现有 GTK 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65190543/

相关文章:

html - 如何创建空格以替换代码中的白色

eclipse - JFace TableViewer 单元格中的小部件?

gtk - 在 GTK Notebook 中将窗口重新设置为选项卡

angularjs - Protractor/Webdriver 在对浏览器进行一系列调用后失去同步

angularjs - 可以创建可嵌入的基于 AngularJS 应用程序的小部件吗?

我可以在 xcode 上安装 gtk 吗?

c# - OSx 单声道 gtk Hello World 。 Gtk.Container 抛出异常

java - 测试框架意外退出、IntellijIdea、Java 和 TestNg 测试套件

java - 使用辅助功能 ID 和 xpath 错误单击菜单

flutter - Flutter 中 ListView 项目的动态高度