Skip to content

Instantly share code, notes, and snippets.

@saltlakeryan
Created March 28, 2014 16:49
Show Gist options
  • Save saltlakeryan/9837435 to your computer and use it in GitHub Desktop.
Save saltlakeryan/9837435 to your computer and use it in GitHub Desktop.
from pywinauto import application, timings
import subprocess, pywinauto, time
def activation_window(app):
actwin = repeated_check(app, 'Dragon NaturallySpeaking 12.0 Activation')
actwinbutton = repeated_check(actwin, 'Activate Later')
repeated_check_generic(actwinbutton, 'Activate Later', button_ready)
return actwin
def profile_window(app):
win = repeated_check(app, 'Open User Profile')
winbutton = repeated_check(win, 'Open')
repeated_check_generic(winbutton, 'Open', button_ready)
return win
def update_window(app):
win = repeated_check_generic('unused', 'unused', update_window_ready)
return win
def update_window_ready(unusedvar1, unusedvar2):
window_handle = pywinauto.findwindows.find_window(title_re=".*Software Manager")
app = pywinauto.application.Application()
window = app.window_(handle = window_handle)
return window
def button_ready(button, name):
return button.VerifyEnabled()
def repeated_check(app, dialogname):
return repeated_check_generic(app, dialogname, check_for_dialog)
def repeated_check_generic(dlg, name, callback):
return timings.WaitUntilPasses(120, 0.5, callback, (pywinauto.findwindows.WindowNotFoundError, pywinauto.findbestmatch.MatchError, pywinauto.controls.HwndWrapper.ControlNotEnabled), dlg, name)
def check_for_dialog(app, dialogname):
print "check for dialog called: ", dialogname
print "app: ", app
return app[dialogname]
def check_button(app, buttonname):
return app[buttonname].VerifyEnabled()
def start_dragon():
subprocess.call(["net", "use", "y:", "\\\\vboxsrv\\dragon"])
app = application.Application()
app.start_('C:\\Program Files\\Nuance\\NaturallySpeaking12\\Program\\natspeak.exe')
activation = activation_window(app)
activation['Activate Later'].Click()
profile = profile_window(app)
profile['Open'].Click()
update = update_window(app)
update.Close()
start_dragon()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment