All pastes #49834 Raw Edit

Unnamed

public python v1 · immutable
#49834 ·published 2006-04-19 01:48 UTC
rendered paste body
_fileRepresentationMapping = {'.png': NSPNGFileType,'.gif': NSGIFFileType,'.jpg': NSJPEGFileType,'.jpeg': NSJPEGFileType,'.bmp': NSBMPFileType,'.tif': NSTIFFFileType,'.tiff': NSTIFFFileType,}	def _getFileRepresentationType(filepath):		base, ext = os.path.splitext(filepath)		return _fileRepresentationMapping[ext.lower()]	def screenshot(self, filepath):	    # Take screenshot	    rect = NSScreen.mainScreen().frame()	    image = NSImage.alloc().initWithSize_((rect.size.width, rect.size.height))	    screenRep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(rect)	    image.addRepresentation_(screenRep)	    # Save	    representation = _getFileRepresentationType(filepath)	    data = image_rep.representationUsingType_properties_(representation, None)	    data.writeToFile_atomically_(filepath, False)