Macro Snip

Description
Use this macro to easily post screenshots to the FreeCAD forum.

Script
ToolBar icon

Macro_Snip.FCMacro

QtGui.QMessageBox.Cancel)  details = """ Move and resize this box to cover the part of the screen you wish to grab. If it succeeds an open file dialog will appear.  Drag and drop the file from the open file dialog to the forum.  The file will be deleted after you close the dialog.

If this fails you can still use this macro to handle screenshots you copied to the clipboard using other tools:

Windows snip tool: Window Key + Shift + S Mac snip tool: Command + Shift + 4 Linux: gnome-screenshot utility

If the macro finds there is already an image copied to the clipboard it uses that image instead of bringing up this dialog. Press Shift while invoking this macro to bypass the clipboard. Alternatively, you can clear the image from the clipboard by copying some text to it.

The Open button will open the file in the system default application for handling png files, e.g. Paint in windows. This can be useful if you wish to annotate the screenshot. But most of the time you will simply want to drag and drop the file to the forum, then Cancel to close the open file dialog afterwards.

If you wish to open the screenshot file with another application, right-click the file and select open with... option or drag/drop to that other application.

"""   mb.setWindowTitle("Snip macro")    mb.setDetailedText(details)    mb.setWindowOpacity(0.85)    result = mb.exec_    if result != QtGui.QMessageBox.Ok:        raise Exception("Snip Macro ungraceful exit message: User canceled\n")    rect = mb.frameGeometry    QtGui.QApplication.processEvents    time.sleep(.5) #give time for dialog to close before taking screenshot    screen = QtGui.QApplication.primaryScreen    image = screen.grabWindow(0,rect.x,rect.y,rect.width,rect.height).toImage    if not image:        raise Exception("Snip Macro Error: Unable to grab screen image\n") dir = QtCore.QTemporaryDir dir.setAutoRemove(True) #delete directory upon exiting filePath = dir.filePath(fname) if dir.isValid:    image.save(filePath)    fileName = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow,    "Drag the image to the forum, then Cancel will delete the temporary file", dir.path, "PNG (*.png)") if fileName[0]: #user selected Open or double-clicked file import subprocess, os, platform if platform.system == 'Darwin':      # macOS subprocess.call(('open', fileName[0])) elif platform.system == 'Windows':   # Windows os.startfile(fileName[0]) else:                                  # linux variants subprocess.call(('xdg-open', fileName[0])) else: raise Exception("Snip Macro Error: Unable to create temporary directory.\n")