def get_icon(name, as_qicon=False): """Returns a `QPixmap` containing the given image, or a QIcon if `as_qicon` is True""" filename = name + ".png" icon = icons.get(filename) if not icon: path = os.path.dirname(__file__) path = os.path.join(path, "icons") filepath = os.path.join(path, filename) if not os.path.exists(filepath): filepath = os.path.join(path, "pink.png") icon = QtGui.QPixmap(filepath) icons[filename] = icon return QtGui.QIcon(icon) if as_qicon else icon
def __init__(self, image_file, parent=None): super(ImageViewerWidget, self).__init__(parent) self.fit = False self.prev_scale = 1.0 self.scene = QtGui.QGraphicsScene() image = QtGui.QPixmap(image_file) self.image_item = self.scene.addPixmap(image) self.image_item.setTransformationMode(QtCore.Qt.SmoothTransformation) npix = max(image.width(), image.height()) max_scale = npix / 200.0 self.view = GraphicsView(self.scene, max_scale=max_scale) create_pane([self.view], False, parent_widget=self) self.view.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) self.view.show() self._fit_in_view()