eric6/QScintilla/Exporters/ExporterODT.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing an exporter for ODT.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import Qt
13 from PyQt5.QtGui import QCursor, QTextDocument, QTextDocumentWriter
14 from PyQt5.QtWidgets import QApplication
15
16 from E5Gui import E5MessageBox
17
18 from .ExporterBase import ExporterBase
19 from .ExporterHTML import HTMLGenerator
20
21 import Preferences
22
23
24 class ExporterODT(ExporterBase):
25 """
26 Class implementing an exporter for ODT.
27 """
28 def __init__(self, editor, parent=None):
29 """
30 Constructor
31
32 @param editor reference to the editor object (QScintilla.Editor.Editor)
33 @param parent parent object of the exporter (QObject)
34 """
35 ExporterBase.__init__(self, editor, parent)
36
37 def exportSource(self):
38 """
39 Public method performing the export.
40 """
41 filename = self._getFileName(self.tr("ODT Files (*.odt)"))
42 if not filename:
43 return
44
45 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
46 QApplication.processEvents()
47
48 tabSize = self.editor.getEditorConfig("TabWidth")
49 if tabSize == 0:
50 tabSize = 4
51 wysiwyg = Preferences.getEditorExporter("ODT/WYSIWYG")
52 onlyStylesUsed = Preferences.getEditorExporter("ODT/OnlyStylesUsed")
53 tabs = Preferences.getEditorExporter("ODT/UseTabs")
54
55 # generate HTML of the source
56 generator = HTMLGenerator(self.editor)
57 html = generator.generate(
58 tabSize=tabSize,
59 useTabs=tabs,
60 wysiwyg=wysiwyg,
61 folding=False,
62 onlyStylesUsed=onlyStylesUsed,
63 titleFullPath=False
64 )
65
66 # convert HTML to ODT
67 doc = QTextDocument()
68 doc.setHtml(html)
69 writer = QTextDocumentWriter(filename)
70 ok = writer.write(doc)
71 QApplication.restoreOverrideCursor()
72 if not ok:
73 E5MessageBox.critical(
74 self.editor,
75 self.tr("Export source"),
76 self.tr(
77 """<p>The source could not be exported to"""
78 """ <b>{0}</b>.</p>""").format(filename))

eric ide

mercurial