New question #230737 on Sikuli:
https://answers.launchpad.net/sikuli/+question/230737

i would like to write a script using onAppear to take a screenshot every time a 
specified image (a popup with an error message to be exact) appears on the 
screen and then save the img to a dir on my computer.
i found some jython code on the web that gets an image from the system 
clipboard and modified it into a function. i would like to write a handler that 
uses this function ( or any technique that can get a screen shot really) but i 
need a way to uniquely name each screen shot and im stuck. here is what i have 
so far:

# type prntscr when a specified image appears on the screen
# save the image to a folder as a .png with a unique name

from java.io                import File
from java.awt               import Toolkit
from java.awt.datatransfer  import DataFlavor
from javax.imageio          import ImageIO

# getClipboardImg - get contents of system clipboard if it is an image
def getClipboardImg():
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
    contents = clipboard.getContents(None)
    if contents and contents.isDataFlavorSupported(DataFlavor.imageFlavor):
        return contents.getTransferData(DataFlavor.imageFlavor)

file = r'C:\Users\robert\Desktop\errors\a.png'
# create a search region
searchReg = Region(3,6,407,189)
HttpErr404 = "1371020138619.png" # image of the error code

# save screen shot 
def saveScreenShot(file):
    type(Key.PRINTSCREEN)    # take a screenshot
    ImageIO.write(getClipboardImg(),'png',File(file))   # write contents of 
clipboard to a .png

def myHandler(event):
    saveScreenShot(file)
    
# onAppear - wait for an error message to appear on the screen; call save 
screen shot
searchReg.onAppear(HttpErr404, myHandler(event))
searchReg,observe()

i have a feeling im missing something obvious and basic but im confused so any 
help is appreciated

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : sikuli-driver@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to