detect latex conversion error and print them in textview. Fixes #4439
This commit is contained in:
parent
e706e86c2e
commit
bf93cb76f1
|
@ -82,6 +82,15 @@ class Cancelled(Exception):
|
|||
'''The user cancelled an operation'''
|
||||
pass
|
||||
|
||||
class LatexError(Exception):
|
||||
'''sqlite2 raised pysqlite2.dbapi2.OperationalError'''
|
||||
def __init__(self, text=''):
|
||||
Exception.__init__(self)
|
||||
self.text = text
|
||||
|
||||
def __str__(self):
|
||||
return self.text
|
||||
|
||||
class GajimGeneralException(Exception):
|
||||
'''This exception is our general exception'''
|
||||
def __init__(self, text=''):
|
||||
|
|
|
@ -50,6 +50,7 @@ from common.fuzzyclock import FuzzyClock
|
|||
|
||||
from htmltextview import HtmlTextView
|
||||
from common.exceptions import GajimGeneralException
|
||||
from common.exceptions import LatexError
|
||||
|
||||
NOT_SHOWN = 0
|
||||
ALREADY_RECEIVED = 1
|
||||
|
@ -964,16 +965,27 @@ class ConversationTextview:
|
|||
file.flush()
|
||||
file.close()
|
||||
|
||||
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
|
||||
cwd=gettempdir())
|
||||
exitcode = p.wait()
|
||||
try:
|
||||
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
|
||||
cwd=gettempdir())
|
||||
exitcode = p.wait()
|
||||
except Exception, e:
|
||||
exitcode = _('Error executing "%(command)s": %(error)s') % {
|
||||
'command': 'latex --interaction=nonstopmode %s.tex' % tmpfile,
|
||||
'error': str(e)}
|
||||
|
||||
if exitcode == 0:
|
||||
latex_png_dpi = gajim.config.get('latex_png_dpi')
|
||||
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight', '-D',
|
||||
latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'],
|
||||
cwd=gettempdir())
|
||||
exitcode = p.wait()
|
||||
try:
|
||||
p = Popen(['dvipng', '-bg', 'rgb 1.0 1.0 1.0', '-T', 'tight', '-D',
|
||||
latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'],
|
||||
cwd=gettempdir())
|
||||
exitcode = p.wait()
|
||||
except Exception, e:
|
||||
exitcode = _('Error executing "%(command)s": %(error)s') % {
|
||||
'command': 'dvipng -bg rgb 1.0 1.0 1.0 -T tight -D %s %s.dvi -o %s.png' %\
|
||||
(latex_png_dpi, tmpfile, tmpfile),
|
||||
'error': str(e)}
|
||||
|
||||
extensions = ['.tex', '.log', '.aux', '.dvi']
|
||||
for ext in extensions:
|
||||
|
@ -982,6 +994,9 @@ class ConversationTextview:
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
if isinstance(exitcode, (unicode, str)):
|
||||
raise LatexError(exitcode)
|
||||
|
||||
if exitcode == 0:
|
||||
result = tmpfile + '.png'
|
||||
|
||||
|
@ -1076,7 +1091,12 @@ class ConversationTextview:
|
|||
if not show_ascii_formatting_chars:
|
||||
special_text = special_text[1:-1] # remove _ _
|
||||
elif special_text.startswith('$$') and special_text.endswith('$$'):
|
||||
imagepath = self.latex_to_image(special_text)
|
||||
try:
|
||||
imagepath = self.latex_to_image(special_text)
|
||||
except LatexError, e:
|
||||
# print the error after the line has been written
|
||||
gobject.idle_add(self.print_conversation_line, str(e), '', 'info', '', None)
|
||||
imagepath = None
|
||||
end_iter = buffer.get_end_iter()
|
||||
anchor = buffer.create_child_anchor(end_iter)
|
||||
if imagepath is not None:
|
||||
|
|
Loading…
Reference in New Issue