如何从终端控制图形程序?

Sar*_*ara 5 command-line inkscape

我正在尝试从终端控制 Inkscape 程序;例如,我想从终端打开 Inkscape 中的“文件”菜单、“编辑”菜单或“扩展”菜单,而无需从程序本身单击菜单。

我进行了很多搜索,但找不到我的问题的答案。如何从终端控制图形程序?

Syl*_*eau 2

我非常确定ldtp可以帮助您实现 Inkscape GUI 的自动化。首先打开终端并安装 python 绑定:

sudo apt-get install python-ldtp
Run Code Online (Sandbox Code Playgroud)

然后启动python解释器:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ldtp import *
>>> launchapp('inkscape')
25362
>>> GTK Accessibility Module initialized
>>> selectmenuitem('*Inkscape', 'mnuExtensions')
Run Code Online (Sandbox Code Playgroud)

或者使用以下代码片段创建专用脚本:

sudo apt-get install python-ldtp
Run Code Online (Sandbox Code Playgroud)

了解所有 GUI 组件名称有点困难,因为ldtpeditor已弃用(请参阅freedesktop 页面freedesktop-ldtp-dev 邮件列表上的此线程)。

要确定用于自动化应用程序的控件,您能做的最好的事情就是依赖getobjectlist)('<window name>')

示例(设置重新堆叠水平点和实时预览):

在此输入图像描述

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ldtp import *
>>> launchapp('inkscape')
11413
>>> GTK Accessibility Module initialized

>>> selectmenuitem('*Inkscape', 'Restack...')
1
>>> getobjectlist('Restack')
['dlgRestack', 'flr8', 'flr9', 'flr4', 'flr5', 'lblHorizontalPoint', 'flr7', 'flr0',
'flr1', 'flr2', 'flr3', 'lblVerticalPoint', 'mnuBottomtoTop(90)', 'mnuTop', 'spr1', 
'mnu8', 'flr11', 'mnu0', 'cboLefttoRight(0)', 'mnuRight', 'mnuRadialInward', 
'mnuMiddle1', 'mnu12', 'lblLivepreview', 'cboTop', 'flr6', 'mnuLefttoRight(0)', 
'btnApply', 'lblAngle', 'chk0', 'mnuRighttoLeft(180)', 'mnuRadialOutward', 'sbtn0', 
'mnuArbitraryAngle', 'lblRestackDirection', 'mnuLeft', 'btnClose', 'mnuMiddle', 
'mnuBottom', 'flr12', 'flr10', 'spr0', 'mnuToptoBottom(270)', 'cboMiddle']
>>> click('dlgRestack', 'mnuMiddle1')
1
>>> click('dlgRestack', 'mnuMiddle')
1
>>> click('dlgRestack', 'chk0')
1
>>> click('dlgRestack', 'btnApply')
1
>>> click('dlgRestack', 'chk0')
1
>>> click('dlgRestack', 'btnApply') 
Run Code Online (Sandbox Code Playgroud)