from sikuli import *
import os

App.focus("FieldWorks")
setAutoWaitTimeout(30)


def alt(key):
	type(key,KeyModifier.ALT)
def ek():
	type(Key.ENTER)

def rk():
	type(Key.RIGHT)
def lk():
	type(Key.LEFT)
def uk():
	type(Key.UP)
def dk(n):
	for i in range(n): 
		type(Key.DOWN)

print "done"


viewArray = [ ["l",8], ["t",6], ["g",13], ["n",3], ["s",27]]

def View(viewKey,subitem,proof):
	App.focus("FieldWorks")
	print "viewing",viewKey,subitem
	alt("v") 
	click(findPattern("lexicon"))
	#type(viewKey)
	rk()
	click(findPattern("LexiconEdit"))
	#dk(subitem)
	#ek()
	findPattern(proof)

	
def test_views():
	for category in viewArray:
		for i in range(category[1]):
			View(category[0],i, "%s-%s-%d" % ("PAT",category[0],i))



def findPattern(filename):
	filename =  filename + ".png"
	print "access:", os.access(filename,os.R_OK) 
	if os.access(filename ,os.R_OK) == False:
		f = capture("Please outline the pattern you wish to search for")
		os.rename(f,filename )
		App.focus("FieldWorks")
	m = find(filename )
	return m
