abstractfactory/maya-capture

Snap an image onto the clipboard

Closed this issue · 8 comments

Description

With the implementation of snap() for still images (#7) coming up through #11 it would be great to look into how we can make a quick screengrab of the viewport with snap() into your system's clipboard.

Goal

Simple way of snapping a single image onto your clipboard so it's ready for pasting into other software or explorer.

Example

import capture
capture.snap(clipboard=True)

And then CTRL + V in Photoshop!

This could be amazingly useful. +1

Just adding a reference.

Pyperclip could be used for cross-platform functionality of putting something into the clipboard with Python. It mentions only handling plaintext so might not work unless images can be encoded as plaintext?

Otherwise I do think Pyside has clipboard features. Since Pyside comes with Maya we could rely on that?

Yeah, I think PySide should suffice, it can do that. Any Maya prior to PySide being available can safely be ignored, at least for an initial release.

def image_to_clipboard(path):
    """Copies the image at path to the system's global clipboard.

    Reference: http://doc.qt.io/qt-4.8/qclipboard.html#setImage
    """
    import PySide.QtGui
    image = PySide.QtGui.QImage(path)
    clipboard = PySide.QtGui.QApplication.clipboard()
    clipboard.setImage(image, mode=PySide.QtGui.QClipboard.Clipboard)

if __name__ == '__main__':
    image_path = "C:/test.jpg"
    image_to_clipboard(image_path)

Seems to be pretty simple. Tested this and works nicely, would be great to have this in for snap()!

Yeah, that looks great!

BigRoy@563ff0f has this working correctly, for example:

import capture
capture.snap(clipboard=True)

Pastes correctly into applications like Photoshop and Paint.

Cool, put it in a pull-request and let's merge it

Solved with #18