11 # This code is a port of the C++ code found in SciTE 1.74 |
11 # This code is a port of the C++ code found in SciTE 1.74 |
12 # Original code: Copyright 1998-2006 by Neil Hodgson <neilh@scintilla.org> |
12 # Original code: Copyright 1998-2006 by Neil Hodgson <neilh@scintilla.org> |
13 |
13 |
14 import time |
14 import time |
15 |
15 |
16 from PyQt5.QtCore import Qt |
16 from PyQt5.QtGui import QFontInfo |
17 from PyQt5.QtGui import QCursor, QFontInfo |
|
18 from PyQt5.QtWidgets import QApplication |
|
19 from PyQt5.Qsci import QsciScintilla |
17 from PyQt5.Qsci import QsciScintilla |
20 |
18 |
21 from E5Gui import E5MessageBox |
19 from E5Gui import E5MessageBox |
|
20 from E5Gui.E5OverrideCursor import E5OverrideCursor |
22 |
21 |
23 from .ExporterBase import ExporterBase |
22 from .ExporterBase import ExporterBase |
24 |
23 |
25 import Preferences |
24 import Preferences |
26 |
25 |
118 """ |
117 """ |
119 filename = self._getFileName(self.tr("RTF Files (*.rtf)")) |
118 filename = self._getFileName(self.tr("RTF Files (*.rtf)")) |
120 if not filename: |
119 if not filename: |
121 return |
120 return |
122 |
121 |
|
122 self.editor.recolor(0, -1) |
|
123 lex = self.editor.getLexer() |
|
124 |
|
125 tabSize = self.editor.getEditorConfig("TabWidth") |
|
126 if tabSize == 0: |
|
127 tabSize = 4 |
|
128 wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG") |
|
129 if wysiwyg: |
|
130 if lex: |
|
131 defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT) |
|
132 else: |
|
133 defaultFont = Preferences.getEditorOtherFonts( |
|
134 "DefaultFont") |
|
135 else: |
|
136 defaultFont = Preferences.getEditorExporter("RTF/Font") |
|
137 fontface = defaultFont.family() |
|
138 fontsize = QFontInfo(defaultFont).pointSize() << 1 |
|
139 if fontsize == 0: |
|
140 fontsize = 10 << 1 |
|
141 characterset = QsciScintilla.SC_CHARSET_DEFAULT |
|
142 tabs = Preferences.getEditorExporter("RTF/UseTabs") |
|
143 |
|
144 if lex: |
|
145 fgColour = lex.color(QsciScintilla.STYLE_DEFAULT) |
|
146 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT) |
|
147 else: |
|
148 fgColour = self.editor.color() |
|
149 bgColour = self.editor.paper() |
|
150 |
123 try: |
151 try: |
124 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
152 with E5OverrideCursor(): |
125 QApplication.processEvents() |
|
126 |
|
127 self.editor.recolor(0, -1) |
|
128 lex = self.editor.getLexer() |
|
129 |
|
130 tabSize = self.editor.getEditorConfig("TabWidth") |
|
131 if tabSize == 0: |
|
132 tabSize = 4 |
|
133 wysiwyg = Preferences.getEditorExporter("RTF/WYSIWYG") |
|
134 if wysiwyg: |
|
135 if lex: |
|
136 defaultFont = lex.font(QsciScintilla.STYLE_DEFAULT) |
|
137 else: |
|
138 defaultFont = Preferences.getEditorOtherFonts( |
|
139 "DefaultFont") |
|
140 else: |
|
141 defaultFont = Preferences.getEditorExporter("RTF/Font") |
|
142 fontface = defaultFont.family() |
|
143 fontsize = QFontInfo(defaultFont).pointSize() << 1 |
|
144 if fontsize == 0: |
|
145 fontsize = 10 << 1 |
|
146 characterset = QsciScintilla.SC_CHARSET_DEFAULT |
|
147 tabs = Preferences.getEditorExporter("RTF/UseTabs") |
|
148 |
|
149 if lex: |
|
150 fgColour = lex.color(QsciScintilla.STYLE_DEFAULT) |
|
151 bgColour = lex.paper(QsciScintilla.STYLE_DEFAULT) |
|
152 else: |
|
153 fgColour = self.editor.color() |
|
154 bgColour = self.editor.paper() |
|
155 |
|
156 try: |
|
157 f = open(filename, "w", encoding="utf-8") |
153 f = open(filename, "w", encoding="utf-8") |
158 |
154 |
159 styles = {} |
155 styles = {} |
160 fonts = {} |
156 fonts = {} |
161 colors = {} |
157 colors = {} |
364 prevCR = ch == b'\r' |
360 prevCR = ch == b'\r' |
365 pos += 1 |
361 pos += 1 |
366 |
362 |
367 f.write(self.RTF_BODYCLOSE) |
363 f.write(self.RTF_BODYCLOSE) |
368 f.close() |
364 f.close() |
369 except IOError as err: |
365 except IOError as err: |
370 QApplication.restoreOverrideCursor() |
366 E5MessageBox.critical( |
371 E5MessageBox.critical( |
367 self.editor, |
372 self.editor, |
368 self.tr("Export source"), |
373 self.tr("Export source"), |
369 self.tr( |
374 self.tr( |
370 """<p>The source could not be exported to""" |
375 """<p>The source could not be exported to""" |
371 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") |
376 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") |
372 .format(filename, str(err))) |
377 .format(filename, str(err))) |
|
378 finally: |
|
379 QApplication.restoreOverrideCursor() |
|