def view_image(self, name): path = get_path_for_name(name) if path: pmap = QPixmap() if pmap.load(path): self.image_popup.current_img = pmap self.image_popup.current_url = QUrl.fromLocalFile(path) self.image_popup() else: error_dialog(self, _('Invalid image'), _( "Failed to load the image {}").format(name), show=True) else: error_dialog(self, _('Image not found'), _( "Failed to find the image {}").format(name), show=True)
def copy_image(self, name): path = get_path_for_name(name) if not path: return error_dialog(self, _('Image not found'), _( "Failed to find the image {}").format(name), show=True) try: img = image_from_path(path) except Exception: return error_dialog(self, _('Invalid image'), _( "Failed to load the image {}").format(name), show=True) url = QUrl.fromLocalFile(path) md = QMimeData() md.setImageData(img) md.setUrls([url]) QApplication.instance().clipboard().setMimeData(md)