detect latex conversion error and print them in textview. Fixes #4439

This commit is contained in:
Yann Leboulanger 2008-11-03 10:33:14 +00:00
parent e706e86c2e
commit bf93cb76f1
2 changed files with 37 additions and 8 deletions

View File

@ -82,6 +82,15 @@ class Cancelled(Exception):
'''The user cancelled an operation''' '''The user cancelled an operation'''
pass 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): class GajimGeneralException(Exception):
'''This exception is our general exception''' '''This exception is our general exception'''
def __init__(self, text=''): def __init__(self, text=''):

View File

@ -50,6 +50,7 @@ from common.fuzzyclock import FuzzyClock
from htmltextview import HtmlTextView from htmltextview import HtmlTextView
from common.exceptions import GajimGeneralException from common.exceptions import GajimGeneralException
from common.exceptions import LatexError
NOT_SHOWN = 0 NOT_SHOWN = 0
ALREADY_RECEIVED = 1 ALREADY_RECEIVED = 1
@ -964,16 +965,27 @@ class ConversationTextview:
file.flush() file.flush()
file.close() file.close()
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], try:
cwd=gettempdir()) p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
exitcode = p.wait() 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: if exitcode == 0:
latex_png_dpi = gajim.config.get('latex_png_dpi') latex_png_dpi = gajim.config.get('latex_png_dpi')
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight', '-D', try:
latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'], p = Popen(['dvipng', '-bg', 'rgb 1.0 1.0 1.0', '-T', 'tight', '-D',
cwd=gettempdir()) latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'],
exitcode = p.wait() 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'] extensions = ['.tex', '.log', '.aux', '.dvi']
for ext in extensions: for ext in extensions:
@ -982,6 +994,9 @@ class ConversationTextview:
except Exception: except Exception:
pass pass
if isinstance(exitcode, (unicode, str)):
raise LatexError(exitcode)
if exitcode == 0: if exitcode == 0:
result = tmpfile + '.png' result = tmpfile + '.png'
@ -1076,7 +1091,12 @@ class ConversationTextview:
if not show_ascii_formatting_chars: if not show_ascii_formatting_chars:
special_text = special_text[1:-1] # remove _ _ special_text = special_text[1:-1] # remove _ _
elif special_text.startswith('$$') and special_text.endswith('$$'): 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() end_iter = buffer.get_end_iter()
anchor = buffer.create_child_anchor(end_iter) anchor = buffer.create_child_anchor(end_iter)
if imagepath is not None: if imagepath is not None: