-
-
Save doorbash/fde0a99640cf14b9d595a0a897316ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import pywinauto | |
from pywinauto import application | |
import win32gui | |
import win32con | |
import win32clipboard | |
import re | |
import csv | |
# Usage: python script.py | |
# Make sure all matlab windows all closed before running script | |
def loop(): | |
try: | |
os.remove("C:\\Users\\win7\\Desktop\\ex.flac\\cohesion_test1.txt") | |
os.remove("C:\\Users\\win7\\Desktop\\ex.flac\\density_test1.txt") | |
os.remove("C:\\Users\\win7\\Desktop\\ex.flac\\friction_test1.txt") | |
except: | |
pass | |
print "running matlab file..." | |
os.system("matlab.exe -nodisplay -nosplash -nodesktop -r \"run('C:\Users\win7\Desktop\ex.flac\Untitled6.m');\"") | |
print "waiting for results..." | |
time.sleep(5) | |
while True: | |
try: | |
app = application.Application().connect(title_re="Figure 1") | |
# Wait a sec to make sure it is done | |
time.sleep(1) | |
print "ok it's done now closing window..." | |
app.kill_() | |
app = application.Application().connect(title="a - FLAC 7.0.411") | |
flac = app.window_(title="a - FLAC 7.0.411") | |
flac.Minimize() | |
flac.Maximize() | |
flac.SetFocus() | |
time.sleep(2) | |
# Click on Record tab | |
flac.ClickInput(coords=(78, 36)) | |
time.sleep(1) | |
# Click on Rebuild button | |
flac.ClickInput(coords=(265, 803)) | |
break | |
except pywinauto.findwindows.WindowNotFoundError: | |
print "seems it is not done yet..." | |
# Close dialogs | |
while True: | |
try: | |
time.sleep(2) | |
app = application.Application().connect(title="Message:") | |
message = app.window_(title="Message:") | |
message.Minimize() | |
message.Maximize() | |
message.SetFocus() | |
time.sleep(1) | |
message.TypeKeys('{ENTER}') | |
time.sleep(1) | |
app = application.Application().connect(title="Warning") | |
message = app.window_(title="Warning") | |
message.Minimize() | |
message.Maximize() | |
message.SetFocus() | |
time.sleep(1) | |
message.TypeKeys('{ENTER}') | |
time.sleep(1) | |
break | |
except Exception as e: | |
print e | |
time.sleep(0.5) | |
# Click on console tab | |
app = application.Application().connect(title="a - FLAC 7.0.411") | |
flac = app.window_(title="a - FLAC 7.0.411") | |
flac.Minimize() | |
flac.Maximize() | |
flac.SetFocus() | |
time.sleep(2) | |
flac.ClickInput(coords=(30, 39)) | |
# Select text | |
time.sleep(1) | |
flac.ClickInput(coords=(9, 730)) | |
flac.TypeKeys('+{END}') | |
time.sleep(1) | |
flac.TypeKeys('^c') | |
# Read text from clipboard | |
win32clipboard.OpenClipboard() | |
data = win32clipboard.GetClipboardData() | |
win32clipboard.CloseClipboard() | |
# Extract number from clipboard text | |
number = float(re.findall(r"[-+]?\d*\.\d+|\d+", data)[0]) | |
# Write it to csv file | |
with open('output.csv', 'ab') as myfile: | |
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL, lineterminator='\n') | |
wr.writerow([number]) | |
while True: | |
loop() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment