QScintilla/Exporters/ExporterTEX.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
14 14
15 from PyQt4.QtCore import * 15 from PyQt4.QtCore import *
16 from PyQt4.QtGui import * 16 from PyQt4.QtGui import *
17 from PyQt4.Qsci import QsciScintilla 17 from PyQt4.Qsci import QsciScintilla
18 18
19 from ExporterBase import ExporterBase 19 from .ExporterBase import ExporterBase
20 20
21 import Preferences 21 import Preferences
22 22
23 class ExporterTEX(ExporterBase): 23 class ExporterTEX(ExporterBase):
24 """ 24 """
50 # avoid breakage due to locale setting 50 # avoid breakage due to locale setting
51 r = int(rf * 10 + 0.5) 51 r = int(rf * 10 + 0.5)
52 g = int(gf * 10 + 0.5) 52 g = int(gf * 10 + 0.5)
53 b = int(bf * 10 + 0.5) 53 b = int(bf * 10 + 0.5)
54 54
55 return "%d.%d, %d.%d, %d.%d" % (r / 10, r % 10, g / 10, g % 10, b / 10, b % 10) 55 return "%d.%d, %d.%d, %d.%d" % (r // 10, r % 10, g // 10, g % 10, b // 10, b % 10)
56 56
57 def __texStyle(self, style): 57 def __texStyle(self, style):
58 """ 58 """
59 Private method to calculate a style name string for a given style number. 59 Private method to calculate a style name string for a given style number.
60 60
143 for index in range(QsciScintilla.STYLE_MAX + 1): 143 for index in range(QsciScintilla.STYLE_MAX + 1):
144 styleIsUsed[index] = True 144 styleIsUsed[index] = True
145 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True 145 styleIsUsed[QsciScintilla.STYLE_DEFAULT] = True
146 146
147 try: 147 try:
148 f = open(filename, "wb") 148 f = open(filename, "w")
149 149
150 f.write("\\documentclass[a4paper]{article}\n") 150 f.write("\\documentclass[a4paper]{article}\n")
151 f.write("\\usepackage[a4paper,margin=1.5cm]{geometry}\n") 151 f.write("\\usepackage[a4paper,margin=1.5cm]{geometry}\n")
152 f.write("\\usepackage[T1]{fontenc}\n") 152 f.write("\\usepackage[T1]{fontenc}\n")
153 f.write("\\usepackage{color}\n") 153 f.write("\\usepackage{color}\n")
229 pos += 1 229 pos += 1
230 230
231 # close last empty style macros and document too 231 # close last empty style macros and document too
232 f.write("}\n} %end tiny\n\n\\end{document}\n") 232 f.write("}\n} %end tiny\n\n\\end{document}\n")
233 f.close() 233 f.close()
234 except IOError, err: 234 except IOError as err:
235 QApplication.restoreOverrideCursor() 235 QApplication.restoreOverrideCursor()
236 QMessageBox.critical(self.editor, 236 QMessageBox.critical(self.editor,
237 self.trUtf8("Export source"), 237 self.trUtf8("Export source"),
238 self.trUtf8(\ 238 self.trUtf8(\
239 """<p>The source could not be exported to <b>{0}</b>.</p>""" 239 """<p>The source could not be exported to <b>{0}</b>.</p>"""
240 """<p>Reason: {1}</p>""")\ 240 """<p>Reason: {1}</p>""")\
241 .format(filename, unicode(err)), 241 .format(filename, str(err)),
242 QMessageBox.StandardButtons(\ 242 QMessageBox.StandardButtons(\
243 QMessageBox.Ok)) 243 QMessageBox.Ok))
244 finally: 244 finally:
245 QApplication.restoreOverrideCursor() 245 QApplication.restoreOverrideCursor()

eric ide

mercurial