diff -r 49f3377aebf1 -r 787a6b3f8c9f eric6/QScintilla/Exporters/ExporterPDF.py --- a/eric6/QScintilla/Exporters/ExporterPDF.py Fri Oct 09 17:19:29 2020 +0200 +++ b/eric6/QScintilla/Exporters/ExporterPDF.py Sat Oct 10 12:20:51 2020 +0200 @@ -11,12 +11,11 @@ # This code is a port of the C++ code found in SciTE 1.74 # Original code: Copyright 1998-2006 by Neil Hodgson <neilh@scintilla.org> -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QCursor, QFontInfo -from PyQt5.QtWidgets import QApplication +from PyQt5.QtGui import QFontInfo from PyQt5.Qsci import QsciScintilla from E5Gui import E5MessageBox +from E5Gui.E5OverrideCursor import E5OverrideCursor from .ExporterBase import ExporterBase @@ -437,116 +436,113 @@ if not filename: return + self.editor.recolor(0, -1) + lex = self.editor.getLexer() + + tabSize = self.editor.getEditorConfig("TabWidth") + if tabSize == 0: + tabSize = 4 + + # get magnification value to add to default screen font size + self.pr.fontSize = Preferences.getEditorExporter( + "PDF/Magnification") + + # set font family according to face name + fontName = Preferences.getEditorExporter("PDF/Font") + self.pr.fontSet = PDF_FONT_DEFAULT + if fontName == "Courier": + self.pr.fontSet = 0 + elif fontName == "Helvetica": + self.pr.fontSet = 1 + elif fontName == "Times": + self.pr.fontSet = 2 + + # page size: height, width, + pageSize = Preferences.getEditorExporter("PDF/PageSize") try: - QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) - QApplication.processEvents() - - self.editor.recolor(0, -1) - lex = self.editor.getLexer() - - tabSize = self.editor.getEditorConfig("TabWidth") - if tabSize == 0: - tabSize = 4 - - # get magnification value to add to default screen font size - self.pr.fontSize = Preferences.getEditorExporter( - "PDF/Magnification") - - # set font family according to face name - fontName = Preferences.getEditorExporter("PDF/Font") - self.pr.fontSet = PDF_FONT_DEFAULT - if fontName == "Courier": - self.pr.fontSet = 0 - elif fontName == "Helvetica": - self.pr.fontSet = 1 - elif fontName == "Times": - self.pr.fontSet = 2 + pageDimensions = PDFpageSizes[pageSize] + except KeyError: + pageDimensions = PDFpageSizes["A4"] + self.pr.pageHeight = pageDimensions[0] + self.pr.pageWidth = pageDimensions[1] + + # page margins: left, right, top, bottom + # < 0 to use PDF default values + val = Preferences.getEditorExporter("PDF/MarginLeft") + if val < 0: + self.pr.pageMargins["left"] = PDF_MARGIN_DEFAULT + else: + self.pr.pageMargins["left"] = val + val = Preferences.getEditorExporter("PDF/MarginRight") + if val < 0: + self.pr.pageMargins["right"] = PDF_MARGIN_DEFAULT + else: + self.pr.pageMargins["right"] = val + val = Preferences.getEditorExporter("PDF/MarginTop") + if val < 0: + self.pr.pageMargins["top"] = PDF_MARGIN_DEFAULT + else: + self.pr.pageMargins["top"] = val + val = Preferences.getEditorExporter("PDF/MarginBottom") + if val < 0: + self.pr.pageMargins["bottom"] = PDF_MARGIN_DEFAULT + else: + self.pr.pageMargins["bottom"] = val + + # collect all styles available for that 'language' + # or the default style if no language is available... + if lex: + istyle = 0 + while istyle <= QsciScintilla.STYLE_MAX: + if (istyle <= QsciScintilla.STYLE_DEFAULT or + istyle > QsciScintilla.STYLE_LASTPREDEFINED): + if ( + lex.description(istyle) or + istyle == QsciScintilla.STYLE_DEFAULT + ): + style = PDFStyle() + + font = lex.font(istyle) + if font.italic(): + style.font |= 2 + if font.bold(): + style.font |= 1 + + colour = lex.color(istyle) + style.fore = self.__getPDFRGB(colour) + self.pr.style[istyle] = style + + # grab font size from default style + if istyle == QsciScintilla.STYLE_DEFAULT: + fontSize = QFontInfo(font).pointSize() + if fontSize > 0: + self.pr.fontSize += fontSize + else: + self.pr.fontSize = PDF_FONTSIZE_DEFAULT + + istyle += 1 + else: + style = PDFStyle() - # page size: height, width, - pageSize = Preferences.getEditorExporter("PDF/PageSize") - try: - pageDimensions = PDFpageSizes[pageSize] - except KeyError: - pageDimensions = PDFpageSizes["A4"] - self.pr.pageHeight = pageDimensions[0] - self.pr.pageWidth = pageDimensions[1] + font = Preferences.getEditorOtherFonts("DefaultFont") + if font.italic(): + style.font |= 2 + if font.bold(): + style.font |= 1 - # page margins: left, right, top, bottom - # < 0 to use PDF default values - val = Preferences.getEditorExporter("PDF/MarginLeft") - if val < 0: - self.pr.pageMargins["left"] = PDF_MARGIN_DEFAULT - else: - self.pr.pageMargins["left"] = val - val = Preferences.getEditorExporter("PDF/MarginRight") - if val < 0: - self.pr.pageMargins["right"] = PDF_MARGIN_DEFAULT - else: - self.pr.pageMargins["right"] = val - val = Preferences.getEditorExporter("PDF/MarginTop") - if val < 0: - self.pr.pageMargins["top"] = PDF_MARGIN_DEFAULT - else: - self.pr.pageMargins["top"] = val - val = Preferences.getEditorExporter("PDF/MarginBottom") - if val < 0: - self.pr.pageMargins["bottom"] = PDF_MARGIN_DEFAULT + colour = self.editor.color() + style.fore = self.__getPDFRGB(colour) + self.pr.style[0] = style + self.pr.style[QsciScintilla.STYLE_DEFAULT] = style + + fontSize = QFontInfo(font).pointSize() + if fontSize > 0: + self.pr.fontSize += fontSize else: - self.pr.pageMargins["bottom"] = val - - # collect all styles available for that 'language' - # or the default style if no language is available... - if lex: - istyle = 0 - while istyle <= QsciScintilla.STYLE_MAX: - if (istyle <= QsciScintilla.STYLE_DEFAULT or - istyle > QsciScintilla.STYLE_LASTPREDEFINED): - if ( - lex.description(istyle) or - istyle == QsciScintilla.STYLE_DEFAULT - ): - style = PDFStyle() - - font = lex.font(istyle) - if font.italic(): - style.font |= 2 - if font.bold(): - style.font |= 1 - - colour = lex.color(istyle) - style.fore = self.__getPDFRGB(colour) - self.pr.style[istyle] = style - - # grab font size from default style - if istyle == QsciScintilla.STYLE_DEFAULT: - fontSize = QFontInfo(font).pointSize() - if fontSize > 0: - self.pr.fontSize += fontSize - else: - self.pr.fontSize = PDF_FONTSIZE_DEFAULT - - istyle += 1 - else: - style = PDFStyle() - - font = Preferences.getEditorOtherFonts("DefaultFont") - if font.italic(): - style.font |= 2 - if font.bold(): - style.font |= 1 - - colour = self.editor.color() - style.fore = self.__getPDFRGB(colour) - self.pr.style[0] = style - self.pr.style[QsciScintilla.STYLE_DEFAULT] = style - - fontSize = QFontInfo(font).pointSize() - if fontSize > 0: - self.pr.fontSize += fontSize - else: - self.pr.fontSize = PDF_FONTSIZE_DEFAULT - - try: + self.pr.fontSize = PDF_FONTSIZE_DEFAULT + + try: + with E5OverrideCursor(): # save file in win ansi using cp1250 f = open(filename, "w", encoding="cp1250", errors="backslashreplace") @@ -616,14 +612,11 @@ # write required stuff and close the PDF file self.pr.endPDF() f.close() - except IOError as err: - QApplication.restoreOverrideCursor() - E5MessageBox.critical( - self.editor, - self.tr("Export source"), - self.tr( - """<p>The source could not be exported to""" - """ <b>{0}</b>.</p><p>Reason: {1}</p>""") - .format(filename, str(err))) - finally: - QApplication.restoreOverrideCursor() + except IOError as err: + E5MessageBox.critical( + self.editor, + self.tr("Export source"), + self.tr( + """<p>The source could not be exported to""" + """ <b>{0}</b>.</p><p>Reason: {1}</p>""") + .format(filename, str(err)))