eric6/QScintilla/Exporters/ExporterRTF.py

changeset 7771
787a6b3f8c9f
parent 7360
9190402e4505
child 7781
607a6098cb44
--- a/eric6/QScintilla/Exporters/ExporterRTF.py	Fri Oct 09 17:19:29 2020 +0200
+++ b/eric6/QScintilla/Exporters/ExporterRTF.py	Sat Oct 10 12:20:51 2020 +0200
@@ -13,12 +13,11 @@
 
 import time
 
-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
 
@@ -120,40 +119,37 @@
         if not filename:
             return
         
+        self.editor.recolor(0, -1)
+        lex = self.editor.getLexer()
+        
+        tabSize = self.editor.getEditorConfig("TabWidth")
+        if tabSize == 0:
+            tabSize = 4
+        wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG")
+        if wysiwyg:
+            if lex:
+                defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT)
+            else:
+                defaultFont = Preferences.getEditorOtherFonts(
+                    "DefaultFont")
+        else:
+            defaultFont = Preferences.getEditorExporter("RTF/Font")
+        fontface = defaultFont.family()
+        fontsize = QFontInfo(defaultFont).pointSize() << 1
+        if fontsize == 0:
+            fontsize = 10 << 1
+        characterset = QsciScintilla.SC_CHARSET_DEFAULT
+        tabs = Preferences.getEditorExporter("RTF/UseTabs")
+        
+        if lex:
+            fgColour = lex.color(QsciScintilla.STYLE_DEFAULT)
+            bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT)
+        else:
+            fgColour = self.editor.color()
+            bgColour = self.editor.paper()
+        
         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
-            wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG")
-            if wysiwyg:
-                if lex:
-                    defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT)
-                else:
-                    defaultFont = Preferences.getEditorOtherFonts(
-                        "DefaultFont")
-            else:
-                defaultFont = Preferences.getEditorExporter("RTF/Font")
-            fontface = defaultFont.family()
-            fontsize = QFontInfo(defaultFont).pointSize() << 1
-            if fontsize == 0:
-                fontsize = 10 << 1
-            characterset = QsciScintilla.SC_CHARSET_DEFAULT
-            tabs = Preferences.getEditorExporter("RTF/UseTabs")
-            
-            if lex:
-                fgColour = lex.color(QsciScintilla.STYLE_DEFAULT)
-                bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT)
-            else:
-                fgColour = self.editor.color()
-                bgColour = self.editor.paper()
-            
-            try:
+            with E5OverrideCursor():
                 f = open(filename, "w", encoding="utf-8")
                 
                 styles = {}
@@ -366,14 +362,11 @@
                 
                 f.write(self.RTF_BODYCLOSE)
                 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)))

eric ide

mercurial