Some cleanup prior to release
This commit is contained in:
parent
5959cf3b30
commit
3fac9506ad
@ -8,9 +8,9 @@
|
|||||||
# TopLevel = true/false
|
# TopLevel = true/false
|
||||||
import time
|
import time
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import re
|
|
||||||
|
|
||||||
import win32structures
|
import win32structures
|
||||||
import win32functions
|
import win32functions
|
||||||
@ -21,8 +21,6 @@ import controlproperties
|
|||||||
import controlactions
|
import controlactions
|
||||||
import XMLHelpers
|
import XMLHelpers
|
||||||
|
|
||||||
# should be possible to get the modules used by a process
|
|
||||||
|
|
||||||
|
|
||||||
class AppStartError(Exception):
|
class AppStartError(Exception):
|
||||||
pass
|
pass
|
||||||
@ -40,8 +38,6 @@ class WindowNotFoundError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#=========================================================================
|
#=========================================================================
|
||||||
def make_valid_filename(filename):
|
def make_valid_filename(filename):
|
||||||
for char in ('\/:*?"<>|'):
|
for char in ('\/:*?"<>|'):
|
||||||
@ -471,5 +467,6 @@ def enum_windows():
|
|||||||
return windows
|
return windows
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import test_application
|
||||||
|
test_application.Main()
|
@ -3,176 +3,166 @@ import os
|
|||||||
import application
|
import application
|
||||||
|
|
||||||
|
|
||||||
|
def TestExceptions():
|
||||||
|
# test that trying to _connect to a non existent app fails
|
||||||
|
try:
|
||||||
|
app = application.Application()
|
||||||
|
app._connect(path = ur"No process with this please")
|
||||||
|
assert 0
|
||||||
|
except application.ProcessNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# test that trying to _connect to a non existent app fails
|
||||||
|
try:
|
||||||
|
app = application.Application()
|
||||||
|
app._start(cmd_line = ur"No process with this please")
|
||||||
|
assert 0
|
||||||
|
except application.AppStartError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# try when it isn't connected
|
||||||
|
try:
|
||||||
|
app = application.Application()
|
||||||
|
#app._start(ur"c:\windows\system32\notepad.exe")
|
||||||
|
app.Notepad.Click()
|
||||||
|
assert 0
|
||||||
|
except application.AppNotConnected:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def TestNotepad():
|
def TestNotepad():
|
||||||
|
|
||||||
if 1:
|
app = application.Application()
|
||||||
|
|
||||||
# ensure that the XML path exists
|
# # for distribution we don't want to connect to anybodies application
|
||||||
example_path = r"examples\notepad_test"
|
# # because we may mess up something they are working on!
|
||||||
try:
|
# try:
|
||||||
os.makedirs(example_path)
|
# app._connect(path = ur"c:\windows\system32\notepad.exe")
|
||||||
except OSError:
|
# except application.ProcessNotFoundError:
|
||||||
pass
|
# app._start(ur"c:\windows\system32\notepad.exe")
|
||||||
|
app._start(ur"c:\windows\system32\notepad.exe")
|
||||||
# test that trying to _connect to a non existent app fails
|
|
||||||
try:
|
|
||||||
app = application.Application()
|
|
||||||
app._connect(path = ur"No process with this please")
|
|
||||||
assert 0
|
|
||||||
except application.ProcessNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# test that trying to _connect to a non existent app fails
|
|
||||||
try:
|
|
||||||
app = application.Application()
|
|
||||||
app._start(cmd_line = ur"No process with this please")
|
|
||||||
assert 0
|
|
||||||
except application.AppStartError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# try when it isn't connected
|
|
||||||
try:
|
|
||||||
app = application.Application()
|
|
||||||
#app._start(ur"c:\windows\system32\notepad.exe")
|
|
||||||
app.Notepad.Click()
|
|
||||||
assert 0
|
|
||||||
except application.AppNotConnected:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
app = application.Application()
|
|
||||||
|
|
||||||
try:
|
|
||||||
app._connect(path = ur"c:\windows\system32\notepad.exe")
|
|
||||||
except application.ProcessNotFoundError:
|
|
||||||
app._start(ur"c:\windows\system32\notepad.exe")
|
|
||||||
|
|
||||||
app.Notepad.MenuSelect("File->PageSetup")
|
|
||||||
|
|
||||||
app.PageSetupDlg.ComboBox1.Select(4)
|
|
||||||
|
|
||||||
app.PageSetupDlg.Printer.Click()
|
|
||||||
|
|
||||||
TestingCheckBox = 1
|
|
||||||
if TestingCheckBox:
|
|
||||||
# Open the Connect to printer dialog so we can
|
|
||||||
# try out checking/unchecking a checkbox
|
|
||||||
app.PageSetupDlg.Network.Click()
|
|
||||||
|
|
||||||
app.ConnectToPrinter.ExpandByDefault.Check()
|
|
||||||
|
|
||||||
app.ConnectToPrinter.ExpandByDefault.UnCheck()
|
|
||||||
|
|
||||||
|
|
||||||
# try doing the same by using click
|
|
||||||
app.ConnectToPrinter.ExpandByDefault.Click()
|
|
||||||
|
|
||||||
app.ConnectToPrinter.ExpandByDefault.Click()
|
|
||||||
|
|
||||||
# close the dialog
|
|
||||||
app.ConnectToPrinter.Cancel.Click()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.PageSetupDlg2.Properties.Click()
|
|
||||||
|
|
||||||
docProps = app._window(title_re = ".*Document Properties")
|
|
||||||
|
|
||||||
TestingTabSelect = 1
|
|
||||||
if TestingTabSelect:
|
|
||||||
docProps.TabCtrl.Select(0)
|
|
||||||
|
|
||||||
docProps.TabCtrl.Select(1)
|
|
||||||
|
|
||||||
docProps.TabCtrl.Select(2)
|
|
||||||
|
|
||||||
|
|
||||||
docProps.TabCtrl.Select("PaperQuality")
|
|
||||||
|
|
||||||
docProps.TabCtrl.Select("JobRetention")
|
|
||||||
|
|
||||||
docProps.TabCtrl.Select("Layout")
|
|
||||||
|
|
||||||
|
|
||||||
TestingRadioButton = 1
|
|
||||||
if TestingRadioButton:
|
|
||||||
docProps.RotatedLandscape.Click()
|
|
||||||
|
|
||||||
docProps.BackToFront.Click()
|
|
||||||
|
|
||||||
docProps.FlipOnShortEdge.Click()
|
|
||||||
|
|
||||||
|
|
||||||
docProps.Portrait.Click()
|
|
||||||
|
|
||||||
docProps._None.Click()
|
|
||||||
|
|
||||||
docProps.FrontToBack.Click()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#print docProps._ctrl
|
|
||||||
advbutton = docProps.Advanced
|
|
||||||
advbutton.Click()
|
|
||||||
|
|
||||||
# close the 4 windows
|
|
||||||
app._window(title_re = ".* Advanced Options").Ok.Click()
|
|
||||||
|
|
||||||
docProps.Cancel.Click()
|
|
||||||
|
|
||||||
app.PageSetupDlg2.OK.Click()
|
|
||||||
|
|
||||||
app.PageSetupDlg.Ok.Click()
|
|
||||||
|
|
||||||
# type some text
|
|
||||||
app.Notepad.Edit.SetText("I am typing some text to Notepad\r\n\r\nAnd then I am going to quit")
|
|
||||||
|
|
||||||
# exit notepad
|
|
||||||
app.Notepad.MenuSelect("File->Exit")
|
|
||||||
app.Notepad.No.Click()
|
|
||||||
|
|
||||||
|
|
||||||
|
app.Notepad.MenuSelect("File->PageSetup")
|
||||||
|
|
||||||
|
app.PageSetupDlg.ComboBox1.Select(4)
|
||||||
|
|
||||||
|
app.PageSetupDlg.Printer.Click()
|
||||||
|
|
||||||
|
TestingCheckBox = 1
|
||||||
|
if TestingCheckBox:
|
||||||
|
# Open the Connect to printer dialog so we can
|
||||||
|
# try out checking/unchecking a checkbox
|
||||||
|
app.PageSetupDlg.Network.Click()
|
||||||
|
|
||||||
|
app.ConnectToPrinter.ExpandByDefault.Check()
|
||||||
|
|
||||||
|
app.ConnectToPrinter.ExpandByDefault.UnCheck()
|
||||||
|
|
||||||
|
# try doing the same by using click
|
||||||
|
app.ConnectToPrinter.ExpandByDefault.Click()
|
||||||
|
|
||||||
|
app.ConnectToPrinter.ExpandByDefault.Click()
|
||||||
|
|
||||||
|
# close the dialog
|
||||||
|
app.ConnectToPrinter.Cancel.Click()
|
||||||
|
|
||||||
|
app.PageSetupDlg2.Properties.Click()
|
||||||
|
|
||||||
|
docProps = app._window(title_re = ".*Document Properties")
|
||||||
|
|
||||||
|
TestingTabSelect = 1
|
||||||
|
if TestingTabSelect:
|
||||||
|
docProps.TabCtrl.Select(0)
|
||||||
|
docProps.TabCtrl.Select(1)
|
||||||
|
docProps.TabCtrl.Select(2)
|
||||||
|
|
||||||
|
docProps.TabCtrl.Select("PaperQuality")
|
||||||
|
docProps.TabCtrl.Select("JobRetention")
|
||||||
|
docProps.TabCtrl.Select("Layout")
|
||||||
|
|
||||||
|
|
||||||
|
TestingRadioButton = 1
|
||||||
|
if TestingRadioButton:
|
||||||
|
docProps.RotatedLandscape.Click()
|
||||||
|
docProps.BackToFront.Click()
|
||||||
|
docProps.FlipOnShortEdge.Click()
|
||||||
|
|
||||||
|
docProps.Portrait.Click()
|
||||||
|
docProps._None.Click()
|
||||||
|
docProps.FrontToBack.Click()
|
||||||
|
|
||||||
|
#print docProps._ctrl
|
||||||
|
advbutton = docProps.Advanced
|
||||||
|
advbutton.Click()
|
||||||
|
|
||||||
|
# close the 4 windows
|
||||||
|
app._window(title_re = ".* Advanced Options").Ok.Click()
|
||||||
|
docProps.Cancel.Click()
|
||||||
|
app.PageSetupDlg2.OK.Click()
|
||||||
|
app.PageSetupDlg.Ok.Click()
|
||||||
|
|
||||||
|
# type some text
|
||||||
|
app.Notepad.Edit.SetText("I am typing some text to Notepad\r\n\r\nAnd then I am going to quit")
|
||||||
|
|
||||||
|
# exit notepad
|
||||||
|
app.Notepad.MenuSelect("File->Exit")
|
||||||
|
app.Notepad.No.Click()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def TestPaint():
|
def TestPaint():
|
||||||
|
|
||||||
app = application.Application()
|
app = application.Application()
|
||||||
|
|
||||||
try:
|
# # for distribution we don't want to connect to anybodies application
|
||||||
app._connect(path = ur"c:\windows\system32\mspaint.exe")
|
# # because we may mess up something they are working on!
|
||||||
except application.ProcessNotFoundError:
|
# try:
|
||||||
app._start(ur"c:\windows\system32\mspaint.exe")
|
# app._connect(path = ur"c:\windows\system32\mspaint.exe")
|
||||||
|
# except application.ProcessNotFoundError:
|
||||||
|
# app._start(ur"c:\windows\system32\mspaint.exe")
|
||||||
|
|
||||||
|
app._start(ur"c:\windows\system32\mspaint.exe")
|
||||||
|
|
||||||
|
pwin = app._window(title_re = ".* - Paint")
|
||||||
|
|
||||||
|
# get the reference to the Canvas window
|
||||||
|
canvas = pwin.Afx100000008
|
||||||
|
|
||||||
|
# make sure the pencil tool is selected
|
||||||
|
pwin.Tools2.Click(coords = (91, 16))
|
||||||
|
|
||||||
|
size = 15
|
||||||
|
num_slants = 20
|
||||||
|
|
||||||
|
# draw the axes
|
||||||
|
canvas.PressMouse(coords = (size, size * num_slants))
|
||||||
|
canvas.MoveMouse(coords = (size*num_slants, size*num_slants)) # x and y axes
|
||||||
|
canvas.MoveMouse(coords = (size * num_slants, size))
|
||||||
|
canvas.ReleaseMouse()
|
||||||
|
|
||||||
|
# now draw the lines
|
||||||
|
print "*** if you move your mouse over Paint as it is drawing ***"
|
||||||
|
print "*** these lines then it will mess up the drawing! ***\n"
|
||||||
|
for i in range(1, num_slants):
|
||||||
|
canvas.PressMouse(coords = (size * num_slants, i * size)) # start
|
||||||
|
|
||||||
|
canvas.MoveMouse(coords = (size * (num_slants - i), size * num_slants)) # x and y axes
|
||||||
|
|
||||||
pwin = app._window(title_re = ".* - Paint")
|
|
||||||
|
|
||||||
canvas = pwin.Afx100000008
|
|
||||||
|
|
||||||
# make sure the pencil tool is selected
|
|
||||||
pwin.Tools2.Click(coords = (91, 16))
|
|
||||||
|
|
||||||
size = 30
|
|
||||||
num_slants = 8
|
|
||||||
|
|
||||||
# draw the axes
|
|
||||||
canvas.PressMouse(coords = (size, size * num_slants))
|
|
||||||
canvas.MoveMouse(coords = (size*num_slants, size*num_slants)) # x and y axes
|
|
||||||
canvas.MoveMouse(coords = (size * num_slants, size))
|
|
||||||
canvas.ReleaseMouse()
|
canvas.ReleaseMouse()
|
||||||
|
|
||||||
# now draw the lines
|
print "Saved image as: Application_Paint_test.png"
|
||||||
for i in range(1, num_slants):
|
canvas._.CaptureAsImage().save(r"Application_Paint_test.png")
|
||||||
canvas.PressMouse(coords = (size * num_slants, i * size)) # start
|
|
||||||
|
|
||||||
canvas.MoveMouse(coords = (size * (num_slants - i), size * num_slants)) # x and y axes
|
|
||||||
|
|
||||||
canvas.ReleaseMouse()
|
|
||||||
|
|
||||||
|
|
||||||
canvas._.CaptureAsImage().save(r"c:\test.png")
|
|
||||||
|
|
||||||
|
# close Paint
|
||||||
|
pwin.MenuSelect("File->Exit")
|
||||||
|
|
||||||
|
# Click the no button on teh message box asking if we want to save
|
||||||
|
app.Paint.No.Click()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def Main():
|
||||||
|
TestExceptions()
|
||||||
TestNotepad()
|
TestNotepad()
|
||||||
TestPaint()
|
TestPaint()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Main()
|
Loading…
Reference in New Issue
Block a user