I have a request from a customer to provide a button to do a screen capture and email the screen capture to an email address entered by the user.
I've done a button already to email pdf reports to an entered email address but I'm not sure if it would be possible to capture the screen as a jpg or bmp and email it.
I do this as a help function in my systems. Basically, when a user clicks the help button, it takes a screen shot then retargets into my help program.
Here is a subsection of that code that would reside in the script modules.
def takeScreenShot(event):
from system.gui import getParentWindow
from system.print import createImage
from system.net import sendEmail
from java.io import ByteArrayOutputStream
from javax.imageio import ImageIO
# Get an image of the entire screen as seen by the user.
# By using getParentWindow(event).parent, you are grabbing the entire session.
# This will include any docked windows.
# Is returned as a bufferedImage. Need to convert it to a byteArray.
# Instantiate an object of ByteArrayOutputStream.
baos = ByteArrayOutputStream(10000)
# Write the bufferedImage returned by the getParentWindow(event).parent as a ByteArrayOutputStream.
ImageIO.write(createImage(getParentWindow(event).parent), 'jpg', baos)
# Flush the stream.
baos.flush()
# Convert the ByteArrayOutputStream to a byteArray.
screenShot = baos.toByteArray()
# Close the stream.
baos.close()
# Send the email.
sendEmail(smtp, from, subject, body, html, to, ['screenShot.jpg'], [screenShot])
Will have to replace the variables in the sendEmail call with your specific values.
Could be converted to be used in an event handler as well.
Best is to not "convert it to an event handler". Just place that function in a project library script and call it from an event handler (passing it the event).
I am trying to use this code, but it seems I'm doing something wrong. My gateway logs tell me there is no module named gui... Am I missing something here? I created the code in the project library, called it from a button click in Perspective, but it doesn't like me, or I just don't know the magic words.