我已尝试自动执行UCL Enchance任务,但在从列表中选择文件后,每个连续会话都具有任何任务的唯一动态参数。我使用SWAPY32bit.exe工具为pywinauto编程。如何为任何任务自动化具有唯一参数的软件?
UCL增强主页 - UCL语音和语言学 www.phon.ucl.ac.uk/resource/sfs/enhance.php
from pywinauto.application import Application
from pywinauto.timings import Timings
import time
app = Application().Start(cmd_line=u'"C:\\Program Files\\SFS\\Enhance\\enhance.exe"')
afxbd = app[u'Untitled - UCLEnhance']
afxbd.Wait('ready')
time.sleep(3)
menu_item = afxbd.MenuItem(u'&File->&1 File.wav')
menu_item.Select()
time.sleep(3)
app = Application().Start(cmd_line=u'"C:\\Program Files\\SFS\\Enhance\\enhance.exe"')
afxbd = app[u'File.wav - UCLEnhance']
menu_item = afxbd.MenuItem(u'&File->&Save Original &As...\tCtrl+S')
menu_item.Select()
答案 0 :(得分:1)
以下代码适合您(在pywinauto 0.6.0上测试):
from pywinauto.application import Application
import time
app = Application().Start(cmd_line=u'"C:\\Program Files\\SFS\\Enhance\\enhance.exe"')
main_window = app[u'Untitled - UCLEnhance']
main_window.wait('ready')
# further actions can be done in a loop for every input file
main_window.menu_select('&File->Open...')
app.OpenDialog.Edit.set_text(ur'C:\Program Files\SFS\Enhance\six.wav')
app.OpenDialog.Open.click_input()
app.OpenDialog.wait_not('visible')
main_window = app.window(title_re='.* - UCLEnhance')
main_window.wait('ready')
# time.sleep(...) might be necessary here
main_window.Toolbar.press_button(11) # 'Enhance' button
# WM_CHECK is handled incorrectly so use WM_CLICK to check the option
app.Enhancement.SpeechLevelRadioButton.check_by_click()
app.Enhancement.OK.click()
app.Enhancement.OK.wait_not('visible')
希望它有所帮助。
P.S。 SWAPY对于简单的场景很有用,但更复杂的情况需要阅读文档和桌面GUI自动化方面的一些经验(有时这真的不容易)。随意提出更多问题。
P.P.S。使用backend='uia'
(MS UI自动化技术)的代码非常相似且更具可读性:
from pywinauto.application import Application
app = Application(backend='uia').start(cmd_line=u'"C:\\Program Files\\SFS\\Enhance\\enhance.exe"')
main_window = app[u'Untitled - UCLEnhance']
main_window.wait('ready')
main_window.menu_select('&File->Open...')
main_window.OpenDialog.Edit.type_keys(ur'C:\Program Files\SFS\Enhance\six.wav{ENTER}', with_spaces=True)
main_window.OpenDialog.wait_not('visible')
main_window = app.window(title_re='.* - UCLEnhance')
main_window.wait('ready')
main_window.Toolbar.Enhance.click()
main_window.Enhancement.SpeechLevelRadioButton.invoke()
main_window.Enhancement.OK.click()
main_window.Enhancement.OK.wait_not('visible')