eric6/QScintilla/Exporters/ExporterTEX.py

changeset 7771
787a6b3f8c9f
parent 7360
9190402e4505
child 7781
607a6098cb44
equal deleted inserted replaced
7770:49f3377aebf1 7771:787a6b3f8c9f
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 os 14 import os
15 15
16 from PyQt5.QtCore import Qt
17 from PyQt5.QtGui import QCursor
18 from PyQt5.QtWidgets import QApplication
19 from PyQt5.Qsci import QsciScintilla 16 from PyQt5.Qsci import QsciScintilla
20 17
21 from E5Gui import E5MessageBox 18 from E5Gui import E5MessageBox
19 from E5Gui.E5OverrideCursor import E5OverrideCursor
22 20
23 from .ExporterBase import ExporterBase 21 from .ExporterBase import ExporterBase
24 22
25 import Preferences 23 import Preferences
26 24
113 """ 111 """
114 filename = self._getFileName(self.tr("TeX Files (*.tex)")) 112 filename = self._getFileName(self.tr("TeX Files (*.tex)"))
115 if not filename: 113 if not filename:
116 return 114 return
117 115
116 self.editor.recolor(0, -1)
117
118 tabSize = self.editor.getEditorConfig("TabWidth")
119 if tabSize == 0:
120 tabSize = 4
121
122 onlyStylesUsed = Preferences.getEditorExporter(
123 "TeX/OnlyStylesUsed")
124 titleFullPath = Preferences.getEditorExporter(
125 "TeX/FullPathAsTitle")
126
127 lex = self.editor.getLexer()
128 self.defaultPaper = (
129 lex and
130 lex.paper(QsciScintilla.STYLE_DEFAULT) or
131 self.editor.paper().name()
132 )
133 self.defaultColor = (
134 lex and
135 lex.color(QsciScintilla.STYLE_DEFAULT) or
136 self.editor.color().name()
137 )
138 self.defaultFont = (
139 lex and
140 lex.color(QsciScintilla.STYLE_DEFAULT) or
141 Preferences.getEditorOtherFonts("DefaultFont")
142 )
143
144 lengthDoc = self.editor.length()
145 styleIsUsed = {}
146 if onlyStylesUsed:
147 for index in range(QsciScintilla.STYLE_MAX + 1):
148 styleIsUsed[index] = False
149 # check the used styles
150 pos = 0
151 while pos < lengthDoc:
152 styleIsUsed[self.editor.styleAt(pos) & 0x7F] = True
153 pos += 1
154 else:
155 for index in range(QsciScintilla.STYLE_MAX + 1):
156 styleIsUsed[index] = True
157 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True
158
118 try: 159 try:
119 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 160 with E5OverrideCursor():
120 QApplication.processEvents()
121
122 self.editor.recolor(0, -1)
123
124 tabSize = self.editor.getEditorConfig("TabWidth")
125 if tabSize == 0:
126 tabSize = 4
127
128 onlyStylesUsed = Preferences.getEditorExporter(
129 "TeX/OnlyStylesUsed")
130 titleFullPath = Preferences.getEditorExporter(
131 "TeX/FullPathAsTitle")
132
133 lex = self.editor.getLexer()
134 self.defaultPaper = (
135 lex and
136 lex.paper(QsciScintilla.STYLE_DEFAULT) or
137 self.editor.paper().name()
138 )
139 self.defaultColor = (
140 lex and
141 lex.color(QsciScintilla.STYLE_DEFAULT) or
142 self.editor.color().name()
143 )
144 self.defaultFont = (
145 lex and
146 lex.color(QsciScintilla.STYLE_DEFAULT) or
147 Preferences.getEditorOtherFonts("DefaultFont")
148 )
149
150 lengthDoc = self.editor.length()
151 styleIsUsed = {}
152 if onlyStylesUsed:
153 for index in range(QsciScintilla.STYLE_MAX + 1):
154 styleIsUsed[index] = False
155 # check the used styles
156 pos = 0
157 while pos < lengthDoc:
158 styleIsUsed[self.editor.styleAt(pos) & 0x7F] = True
159 pos += 1
160 else:
161 for index in range(QsciScintilla.STYLE_MAX + 1):
162 styleIsUsed[index] = True
163 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True
164
165 try:
166 f = open(filename, "w", encoding="utf-8") 161 f = open(filename, "w", encoding="utf-8")
167 162
168 f.write("\\documentclass[a4paper]{article}\n") 163 f.write("\\documentclass[a4paper]{article}\n")
169 f.write("\\usepackage[a4paper,margin=1.5cm]{geometry}\n") 164 f.write("\\usepackage[a4paper,margin=1.5cm]{geometry}\n")
170 f.write("\\usepackage[T1]{fontenc}\n") 165 f.write("\\usepackage[T1]{fontenc}\n")
277 pos += 1 272 pos += 1
278 273
279 # close last empty style macros and document too 274 # close last empty style macros and document too
280 f.write("}\n} %end tiny\n\n\\end{document}\n") 275 f.write("}\n} %end tiny\n\n\\end{document}\n")
281 f.close() 276 f.close()
282 except IOError as err: 277 except IOError as err:
283 QApplication.restoreOverrideCursor() 278 E5MessageBox.critical(
284 E5MessageBox.critical( 279 self.editor,
285 self.editor, 280 self.tr("Export source"),
286 self.tr("Export source"), 281 self.tr(
287 self.tr( 282 """<p>The source could not be exported to"""
288 """<p>The source could not be exported to""" 283 """ <b>{0}</b>.</p><p>Reason: {1}</p>""")
289 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") 284 .format(filename, str(err)))
290 .format(filename, str(err)))
291 finally:
292 QApplication.restoreOverrideCursor()

eric ide

mercurial