示例#1
0
 def resize(self):
     # on a choisi de remplacer la couv, redimesionnement et sauvegarde de la nouvelle image
     newcouv = QFileDialog.getOpenFileName(None, "Sélectionnez la nouvelle couverture :",
                                           QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation),
                                           "Images (*.png *.gif *.jpg *.jpeg *.bmp)")
     if not newcouv:
         return self.suppr_comm()
     log('\t remplacement de la couverture')
     newimg = Image.open(newcouv)
     im = Image.open(self.monepub.imagedecouv)
     oldwidth, oldheight = im.size
     newimg = newimg.resize((oldwidth, oldheight))
     newimg.save(self.monepub.imagedecouv)
     self.ccouv.close()
     return tatoo.suppr_tatoo(self.monepub)
示例#2
0
    def suppr_comm (self):
        self.ccouv.close()
        # on garde l'ancienne couv : suppression des commentaires
        log('\t suppression des commentaires des images')
        logtat('suppression des commentaires des images')
        for name in self.monepub.liste_fichiers:
            ext = name.rpartition('.')[2]

            if ext.lower() in ('jpg', 'jpeg'):
                im = Image.open(name)
                if im.mode == ('CMYK'):
                    im = im.convert('RGB')
                temp = name.rsplit('.', 4)[0] + '.png'
                im.save(temp)
                im2 = Image.open(temp).save(name, 'JPEG', quality=90)
                os.remove(temp)
        return tatoo.suppr_tatoo(self.monepub)
示例#3
0
 def setup_couv(self, monepub, epubname):
         if monepub.pagedecouv is None:
             msg = QtGui.QMessageBox(QtGui.QMessageBox.Warning, 'Problème avec ' + epubname,
                     'Impossible de déterminer la couverture de ce livre\nLe détatouage continue mais vérifiez la couverture',
                      QtGui.QMessageBox.Ok)
             icon = QtGui.QIcon()
             icon.addPixmap(QtGui.QPixmap(LECHEMIN + "/resources/PL128.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
             msg.setWindowIcon(icon)
             msg.exec_()
             return tatoo.suppr_tatoo(self.monepub)
         self.ccouv = QtGui.QDialog()
         self.ccouv = choixcouv.Ui_Dialog()
         self.ccouv.setupUi(self.ccouv)
         icon = QtGui.QIcon()
         icon.addPixmap(QtGui.QPixmap(os.path.normpath(LECHEMIN + '/resources/PL128.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
         self.ccouv.setWindowIcon(icon)
         QtCore.QMetaObject.connectSlotsByName(self)
         QtCore.QObject.connect(self.ccouv.pushButton, QtCore.SIGNAL("clicked()"), self.suppr_comm)
         QtCore.QObject.connect(self.ccouv.pushButton_2, QtCore.SIGNAL("clicked()"), self.resize)
         QtCore.QObject.connect(self.ccouv.pushButton, QtCore.SIGNAL("clicked()"), self.ccouv.hide)
         QtCore.QObject.connect(self.ccouv.pushButton_2, QtCore.SIGNAL("clicked()"), self.ccouv.hide)
         im = Image.open(monepub.imagedecouv)
         im2 = im.convert('RGB')
         output = os.path.splitext(monepub.imagedecouv)[0] + '.png'
         im2.save(output, 'PNG')
         anc_couv = QtGui.QImage(output)
         self.ccouv.pix = QtGui.QPixmap.fromImage(anc_couv.scaled(280, 380, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))  # ,
                                             # QtCore.Qt.DiffuseAlphaDither)
         self.ccouv.scene = QtGui.QGraphicsScene()
         self.ccouv.scene.clear()
         self.ccouv.scene.setSceneRect(0, 0, 280, 380)
         self.ccouv.scene.addPixmap(self.ccouv.pix)
         self.ccouv.graphicsView_couv.setScene(self.ccouv.scene)
         # self.ccouv.graphicsView_couv.fitInView(0, 0, w_img, h_img, QtCore.Qt.KeepAspectRatio)
         self.ccouv.setWindowModality(QtCore.Qt.ApplicationModal)
         self.ccouv.exec_()
         QtCore.QCoreApplication.processEvents()
         try:
             if im.format != 'PNG':
                 os.remove(output)
         except:
             pass