def METHOD_NAME( widget, imagePath ) :
	if not GafferUI.EventLoop.mainEventLoop().running() :
		# This is a hack to try to give Qt time to
		# finish processing any events needed to get
		# the widget ready for capture. Really we need
		# a rock solid way that _guarantees_ this, and which
		# we can also use when the event loop is running.
		GafferUI.EventLoop.waitForIdle()
	imageDir = os.path.dirname( imagePath )
	if imageDir and not os.path.isdir( imageDir ) :
		os.makedirs( imageDir )
	# Qt 5
	screen = QtWidgets.QApplication.primaryScreen()
	windowHandle = widget._qtWidget().windowHandle()
	if windowHandle :
		screen = windowHandle.screen()
	pixmap = screen.grabWindow( widget._qtWidget().winId() )
	if sys.platform == "darwin" and pixmap.size() == screen.size() * screen.devicePixelRatio() :
		# A bug means that the entire screen will have been captured,
		# not just the widget we requested. Copy out just the widget.
		topLeft = widget._qtWidget().mapToGlobal( QtCore.QPoint( 0, 0 ) )
		bottomRight = widget._qtWidget().mapToGlobal( QtCore.QPoint( widget._qtWidget().width(), widget._qtWidget().height() ) )
		size = bottomRight - topLeft
		pixmap = pixmap.copy(
			QtCore.QRect(
				topLeft * screen.devicePixelRatio(),
				QtCore.QSize( size.x(), size.y() ) * screen.devicePixelRatio()
			)
		)
	pixmap.save( imagePath )