def make_image(path, src, fail_ok=False): """relative to path (if needed), make a QGraphicsPixmapItem for the image named in src, returning None if not available, or an 'No Image' image if fail_ok == False""" if '//' not in src or src.startswith('file://'): testpath = src if '//' in testpath: testpath = testpath.split('//', 1)[-1] # # file on local file system testpath = g.os_path_finalize_join(path, testpath) if g.os_path_exists(testpath): return QtWidgets.QGraphicsPixmapItem(QtGui.QPixmap(testpath)) # # explicit file://, but no such file exists if src.startswith('file://'): return None if fail_ok else GetImage._no_image() # # no explict file://, so try other protocols testpath = src if '//' in src else 'http://%s' % (src) data = GetImage.get_url(testpath) if data: img = QtGui.QPixmap() if img.loadFromData(data): return QtWidgets.QGraphicsPixmapItem(img) return None if fail_ok else GetImage._no_image()
def _no_image(): """return QGraphicsPixmapItem with "No Image" image loaded""" testpath = g.os_path_abspath( g.os_path_join(g.app.loadDir, '../plugins/GraphCanvas/no_image.png')) return QtWidgets.QGraphicsPixmapItem(QtGui.QPixmap(testpath))