eric6/QScintilla/Exporters/ExporterODT.py

changeset 7771
787a6b3f8c9f
parent 7360
9190402e4505
child 7781
607a6098cb44
equal deleted inserted replaced
7770:49f3377aebf1 7771:787a6b3f8c9f
6 """ 6 """
7 Module implementing an exporter for ODT. 7 Module implementing an exporter for ODT.
8 """ 8 """
9 9
10 10
11 from PyQt5.QtCore import Qt 11 from PyQt5.QtGui import QTextDocument, QTextDocumentWriter
12 from PyQt5.QtGui import QCursor, QTextDocument, QTextDocumentWriter
13 from PyQt5.QtWidgets import QApplication
14 12
15 from E5Gui import E5MessageBox 13 from E5Gui import E5MessageBox
14 from E5Gui.E5OverrideCursor import E5OverrideCursor
16 15
17 from .ExporterBase import ExporterBase 16 from .ExporterBase import ExporterBase
18 from .ExporterHTML import HTMLGenerator 17 from .ExporterHTML import HTMLGenerator
19 18
20 import Preferences 19 import Preferences
39 """ 38 """
40 filename = self._getFileName(self.tr("ODT Files (*.odt)")) 39 filename = self._getFileName(self.tr("ODT Files (*.odt)"))
41 if not filename: 40 if not filename:
42 return 41 return
43 42
44 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
45 QApplication.processEvents()
46
47 tabSize = self.editor.getEditorConfig("TabWidth") 43 tabSize = self.editor.getEditorConfig("TabWidth")
48 if tabSize == 0: 44 if tabSize == 0:
49 tabSize = 4 45 tabSize = 4
50 wysiwyg = Preferences.getEditorExporter("ODT/WYSIWYG") 46 wysiwyg = Preferences.getEditorExporter("ODT/WYSIWYG")
51 onlyStylesUsed = Preferences.getEditorExporter("ODT/OnlyStylesUsed") 47 onlyStylesUsed = Preferences.getEditorExporter("ODT/OnlyStylesUsed")
52 tabs = Preferences.getEditorExporter("ODT/UseTabs") 48 tabs = Preferences.getEditorExporter("ODT/UseTabs")
53 49
54 # generate HTML of the source 50 with E5OverrideCursor():
55 generator = HTMLGenerator(self.editor) 51 # generate HTML of the source
56 html = generator.generate( 52 generator = HTMLGenerator(self.editor)
57 tabSize=tabSize, 53 html = generator.generate(
58 useTabs=tabs, 54 tabSize=tabSize,
59 wysiwyg=wysiwyg, 55 useTabs=tabs,
60 folding=False, 56 wysiwyg=wysiwyg,
61 onlyStylesUsed=onlyStylesUsed, 57 folding=False,
62 titleFullPath=False 58 onlyStylesUsed=onlyStylesUsed,
63 ) 59 titleFullPath=False
60 )
61
62 # convert HTML to ODT
63 doc = QTextDocument()
64 doc.setHtml(html)
65 writer = QTextDocumentWriter(filename)
66 ok = writer.write(doc)
64 67
65 # convert HTML to ODT
66 doc = QTextDocument()
67 doc.setHtml(html)
68 writer = QTextDocumentWriter(filename)
69 ok = writer.write(doc)
70 QApplication.restoreOverrideCursor()
71 if not ok: 68 if not ok:
72 E5MessageBox.critical( 69 E5MessageBox.critical(
73 self.editor, 70 self.editor,
74 self.tr("Export source"), 71 self.tr("Export source"),
75 self.tr( 72 self.tr(

eric ide

mercurial