def _changeAuthorImage(self, authorImage):
        if authorImage:
            pixmap = QtGui.QPixmap()
            pixmap.loadFromData(authorImage.toBytes())
            self.authorImage.setPixmap(pixmap)

        self.ediAuthorImageButton.setEnabled(self._author.image is not None and settings_store.SettingsStore().allowImageProcessing)
Beispiel #2
0
    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.editor = self.editorInput.text().strip()
        settings.sigilPath = self.sigilPathInput.text().strip()
        settings.allowImageProcessing = self.allowImageProcessingInput.isChecked(
        )
    def _readAutoCloseSetting(self):
        settings = settings_store.SettingsStore()
        settings.beginGroup(EpubGeneration._SETTINGS_GROUP)
        autoCloseValue = settings.value(EpubGeneration._AUTO_CLOSE_DIALOG_SETTING, False, bool)
        settings.endGroup()

        self.closeDialogInput.setCheckState(QtCore.Qt.Checked if autoCloseValue else QtCore.Qt.Unchecked)
    def _openImageSelectionDialog(self):
        settings = settings_store.SettingsStore()

        allowedFormatsToOpen = ("*.{0}".format(f) for f in images.AuthorImage.allowedFormatsToOpen(settings.allowImageProcessing))
        imagesFilter = "Imágenes ({0})".format(" ".join(allowedFormatsToOpen))

        imageName = QtGui.QFileDialog.getOpenFileName(self, "Seleccionar Imagen", filter=imagesFilter)

        if imageName:
            try:
                image = images.AuthorImage(imageName, allowProcessing=settings.allowImageProcessing)
            except images.InvalidDimensionsError:
                gui_utils.displayStdErrorDialog("La imagen de autor seleccionada no tiene las dimensiones requeridas, que deben ser "
                                                "de {0}px de ancho y {1}px de alto. Si desea que la imagen se redimensione "
                                                "automáticamente, habilite la opción para permitir el procesamiento de las imágenes desde el "
                                                "menú Preferencias.".format(images.AuthorImage.WIDTH, images.AuthorImage.HEIGHT))
                return
            except images.MaxSizeExceededError:
                gui_utils.displayStdErrorDialog("La imagen de autor excede el tamaño máximo permitido, que debe "
                                                "ser menor o igual a {0} kB. Si desea que la calidad de la imagen se ajuste automáticamente para "
                                                "reducir su tamaño, habilite la opción para permitir el procesamiento de las imágenes desde "
                                                "el menú Preferencias.".format(images.AuthorImage.MAX_SIZE_IN_BYTES // 1000))
                return
            except images.ProgressiveImageError:
                gui_utils.displayStdErrorDialog("La imagen de autor no puede ser abierta porque fue guardada en modo progresivo. Guárdela de "
                                                "manera normal y vuelva a abrirla, o habilite la opción para permitir el procesamiento de las "
                                                "imágenes desde el menú Preferencias.")
                return

            self._author.image = image
            self._changeAuthorImage(image)
Beispiel #5
0
    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.editorInput.setText(settings.editor)
        self.sigilPathInput.setText(settings.sigilPath)
        self.allowImageProcessingInput.setCheckState(
            QtCore.Qt.Checked if settings.allowImageProcessing else QtCore.Qt.
            Unchecked)
Beispiel #6
0
    def _epubGenerationFinished(self, fileName, warnings):
        self._epubGenerationThread.quit()

        self._epubGenerationDialog.ok(warnings)
        settings = settings_store.SettingsStore()

        if settings.sigilPath:
            if self._openInSigil(settings.sigilPath, fileName):
                self._showMessageOnStatusBar("Abriendo Sigil...", 5000)
Beispiel #7
0
    def _writeSettings(self):
        settings = settings_store.SettingsStore()
        settings.beginGroup(MainWindow._SETTINGS_GROUP)

        settings.setValue(MainWindow._MAINWINDOW_GEOMETRY_SETTING,
                          self.saveGeometry())
        settings.setValue(MainWindow._MAINWINDOW_STATE_SETTING,
                          self.saveState())
        settings.setValue(MainWindow._LAST_FOLDER_OPEN_SETTING,
                          self._lastFolderOpen)
        settings.setValue(MainWindow._LAST_EMPTY_EPUB_OUTPUT_FOLDER_SETTING,
                          self._lastEmptyEpubOutputFolder)

        settings.endGroup()
Beispiel #8
0
    def _readSettings(self):
        settings = settings_store.SettingsStore()
        settings.beginGroup(MainWindow._SETTINGS_GROUP)

        mainWindowGeometry = settings.value(
            MainWindow._MAINWINDOW_GEOMETRY_SETTING)
        mainWindowState = settings.value(MainWindow._MAINWINDOW_STATE_SETTING)
        self._lastFolderOpen = settings.value(
            MainWindow._LAST_FOLDER_OPEN_SETTING)
        self._lastEmptyEpubOutputFolder = settings.value(
            MainWindow._LAST_EMPTY_EPUB_OUTPUT_FOLDER_SETTING)

        settings.endGroup()

        if mainWindowGeometry:
            self.restoreGeometry(mainWindowGeometry)

        if mainWindowState:
            self.restoreState(mainWindowState)
Beispiel #9
0
    def _generateEpub(self):
        metadata = self.metadataTabManager.getEbookMetadata()

        if metadata:
            # Por defecto guardo el epub en el mismo directorio donde se encuentra
            # el archivo de origen.
            if self._workingFilePath:
                outputDir = os.path.dirname(self._workingFilePath)
            else:
                # Si no estoy trabajando con ningún archivo, debo pedirle al usuario
                # el path donde guardar el epub.
                outputDir = QtGui.QFileDialog.getExistingDirectory(
                    self, "", self._lastEmptyEpubOutputFolder)

            if outputDir:
                if not self._workingFilePath:
                    self._lastEmptyEpubOutputFolder = outputDir

                settings = settings_store.SettingsStore()
                metadata.editor = settings.editor

                self._epubGenerationThread = QtCore.QThread()
                self._epubGenerationRunner = EpubGenerationRunner(
                    metadata, outputDir, self._workingFilePath)
                self._epubGenerationRunner.moveToThread(
                    self._epubGenerationThread)
                self._epubGenerationRunner.finished.connect(
                    self._epubGenerationFinished)
                self._epubGenerationRunner.error.connect(
                    self._epubGenerationError)
                self._epubGenerationThread.started.connect(
                    self._epubGenerationRunner.run)
                self._epubGenerationThread.start()

                self._epubGenerationDialog = epub_generation.EpubGeneration(
                    self)
                self._epubGenerationDialog.exec()
Beispiel #10
0
    def _run(self):
        try:
            settings = settings_store.SettingsStore()

            ebookData = None
            rawText = None

            if self._inputFile:
                fileType = os.path.splitext(self._inputFile)[1][1:]
                options = settings.getAllSettingsForConverter(fileType)

                converter = converter_factory.ConverterFactory.getConverter(
                    self._inputFile, **options)

                ebookData = converter.convert()
                rawText = converter.getRawText()

            eebook = ebook.Ebook(ebookData, self._metadata,
                                 **settings.getAllSettingsForEbook())
            warnings = []

            if ebookData:
                if self._checkForMissingText(ebookData, rawText):
                    warnings.append(
                        "Se ha perdido texto en la conversión. Por favor, repórtalo a los desarrolladores y adjunta el "
                        "documento fuente.")
                warnings += ebookData.warnings()

            fileName = eebook.save(self._outputDir)

            if settings.allowImageProcessing:
                self._saveCoverForWeb()

            self.finished.emit(fileName, warnings)
        except Exception:
            self.error.emit(sys.exc_info())
Beispiel #11
0
    def _showPreferencesDialog(self):
        settings = settings_store.SettingsStore()
        previousAllowImageProcessing = settings.allowImageProcessing

        if preferences.Preferences(self).exec() == QtGui.QDialog.Accepted:
            if previousAllowImageProcessing != settings.allowImageProcessing:
                coverImage = self.metadataTabManager.basicMetadata.getCoverImage(
                )
                authors = self.metadataTabManager.basicMetadata.getAuthors()
                wasAuthorWithImage = False

                if coverImage:
                    self.metadataTabManager.basicMetadata.setCoverImage(None)

                for author in authors:
                    if author.image:
                        wasAuthorWithImage = True
                    author.image = None

                if coverImage or wasAuthorWithImage:
                    gui_utils.displayInformationDialog(
                        "La opción para permitir el procesamiento de las imágenes del ePub base ha cambiado de "
                        "valor. Debe cargar nuevamente las imágenes de cubierta y autores."
                    )
Beispiel #12
0
    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.ignoreEmptyParagraphsInput.setCheckState(
            QtCore.Qt.Checked if settings.
            docxIgnoreEmptyParagraphs else QtCore.Qt.Unchecked)
Beispiel #13
0
    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.docxIgnoreEmptyParagraphs = self.ignoreEmptyParagraphsInput.isChecked(
        )
Beispiel #14
0
    def _loadSettings(self):
        settings = settings_store.SettingsStore()

        self.includeOptionalFilesInput.setCheckState(
            QtCore.Qt.Checked if settings.
            epubOutputIncludeOptionalFiles else QtCore.Qt.Unchecked)
Beispiel #15
0
    def saveSettings(self):
        settings = settings_store.SettingsStore()

        settings.epubOutputIncludeOptionalFiles = self.includeOptionalFilesInput.isChecked(
        )
 def _writeAutoCloseSetting(self):
     settings = settings_store.SettingsStore()
     settings.beginGroup(EpubGeneration._SETTINGS_GROUP)
     settings.setValue(EpubGeneration._AUTO_CLOSE_DIALOG_SETTING, self.closeDialogInput.isChecked())
     settings.endGroup()