QScintilla/Exporters/ExporterODT.py

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

eric ide

mercurial