Improving testing of LaTeX configuration.
This commit is contained in:
parent
4b1cf2cd9d
commit
7b76a8fe08
3 changed files with 36 additions and 16 deletions
|
@ -142,7 +142,7 @@ def run():
|
||||||
|
|
||||||
# Check for LaTeX installation if LaTeX support is enabled
|
# Check for LaTeX installation if LaTeX support is enabled
|
||||||
if config.getSetting("enable_latex"):
|
if config.getSetting("enable_latex"):
|
||||||
latex.check_latex_install()
|
latex.checkLatexInstallation()
|
||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
if config.getSetting("check_for_updates"):
|
if config.getSetting("check_for_updates"):
|
||||||
|
|
|
@ -36,10 +36,12 @@ class EnableLatex extends BoolSetting {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if(!value || Latex.checkLatexInstallation()) {
|
||||||
super.set(value)
|
super.set(value)
|
||||||
Modules.Latex.enabled = value
|
Modules.Latex.enabled = value
|
||||||
Modules.Canvas.requestPaint()
|
Modules.Canvas.requestPaint()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
|
|
|
@ -64,23 +64,34 @@ class Latex(QObject):
|
||||||
QObject.__init__(self)
|
QObject.__init__(self)
|
||||||
self.tempdir = tempdir
|
self.tempdir = tempdir
|
||||||
|
|
||||||
def check_latex_install(self):
|
@Property(bool)
|
||||||
|
def latexSupported(self):
|
||||||
|
return LATEX_PATH is not None and DVIPNG_PATH is not None
|
||||||
|
|
||||||
|
@Slot(result=bool)
|
||||||
|
def checkLatexInstallation(self):
|
||||||
"""
|
"""
|
||||||
Checks if the current latex installation is valid.
|
Checks if the current latex installation is valid.
|
||||||
"""
|
"""
|
||||||
|
valid_install = True
|
||||||
if LATEX_PATH is None:
|
if LATEX_PATH is None:
|
||||||
print("No Latex installation found.")
|
print("No Latex installation found.")
|
||||||
if "--test-build" not in argv:
|
if "--test-build" not in argv:
|
||||||
QMessageBox.warning(None, "LogarithmPlotter - Latex setup",
|
QMessageBox.warning(None, "LogarithmPlotter - Latex setup",
|
||||||
QCoreApplication.translate("latex", "No Latex installation found.\nIf you already have a latex distribution installed, make sure it's installed on your path.\nOtherwise, you can download a Latex distribution like TeX Live at https://tug.org/texlive/."))
|
QCoreApplication.translate("latex", "No Latex installation found.\nIf you already have a latex distribution installed, make sure it's installed on your path.\nOtherwise, you can download a Latex distribution like TeX Live at https://tug.org/texlive/."))
|
||||||
|
valid_install = False
|
||||||
elif DVIPNG_PATH is None:
|
elif DVIPNG_PATH is None:
|
||||||
print("DVIPNG not found.")
|
print("DVIPNG not found.")
|
||||||
if "--test-build" not in argv:
|
if "--test-build" not in argv:
|
||||||
QMessageBox.warning(None, "LogarithmPlotter - Latex setup", QCoreApplication.translate("latex", "DVIPNG was not found. Make sure you include it from your Latex distribution."))
|
QMessageBox.warning(None, "LogarithmPlotter - Latex setup", QCoreApplication.translate("latex", "DVIPNG was not found. Make sure you include it from your Latex distribution."))
|
||||||
|
valid_install = False
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.render("", 14, QColor(0, 0, 0, 255))
|
||||||
|
except Exception as e:
|
||||||
|
valid_install = False # Should have sent an error message if failed to render
|
||||||
|
return valid_install
|
||||||
|
|
||||||
@Property(bool)
|
|
||||||
def latexSupported(self):
|
|
||||||
return LATEX_PATH is not None and DVIPNG_PATH is not None
|
|
||||||
|
|
||||||
@Slot(str, float, QColor, result=str)
|
@Slot(str, float, QColor, result=str)
|
||||||
def render(self, latex_markup: str, font_size: float, color: QColor) -> str:
|
def render(self, latex_markup: str, font_size: float, color: QColor) -> str:
|
||||||
|
@ -156,19 +167,26 @@ class Latex(QObject):
|
||||||
out, err = proc.communicate(timeout=2) # 2 seconds is already FAR too long.
|
out, err = proc.communicate(timeout=2) # 2 seconds is already FAR too long.
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
# Process errored
|
# Process errored
|
||||||
|
output = str(out, 'utf8') + "\n" + str(err, 'utf8')
|
||||||
QMessageBox.warning(None, "LogarithmPlotter - Latex",
|
QMessageBox.warning(None, "LogarithmPlotter - Latex",
|
||||||
QCoreApplication.translate("latex", "An exception occured within the creation of the latex formula.\nProcess '{}' ended with a non-zero return code {}:\n\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
QCoreApplication.translate("latex", "An exception occured within the creation of the latex formula.\nProcess '{}' ended with a non-zero return code {}:\n\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
||||||
.format(" ".join(process), proc.returncode,
|
.format(" ".join(process), proc.returncode, output))
|
||||||
str(out, 'utf8') + "\n" + str(err, 'utf8')))
|
|
||||||
raise Exception("{0} process exited with return code {1}:\n{2}\n{3}".format(" ".join(process), str(proc.returncode), str(out, 'utf8'), str(err, 'utf8')))
|
raise Exception("{0} process exited with return code {1}:\n{2}\n{3}".format(" ".join(process), str(proc.returncode), str(out, 'utf8'), str(err, 'utf8')))
|
||||||
except TimeoutExpired as e:
|
except TimeoutExpired as e:
|
||||||
# Process timed out
|
# Process timed out
|
||||||
proc.kill()
|
proc.kill()
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
|
output = str(out, 'utf8') + "\n" + str(err, 'utf8')
|
||||||
|
if 'calligra.sty' in output and 'not found' in output:
|
||||||
|
# Calligra package not installed.
|
||||||
|
QMessageBox.warning(None, "LogarithmPlotter - Latex",
|
||||||
|
QCoreApplication.translate("latex", "Your LaTeX installation does not include the '{}' package. Make sure said package is installed, or disable the LaTeX rendering in LogarithmPlotter.")
|
||||||
|
.format('calligra'))
|
||||||
|
else:
|
||||||
QMessageBox.warning(None, "LogarithmPlotter - Latex",
|
QMessageBox.warning(None, "LogarithmPlotter - Latex",
|
||||||
QCoreApplication.translate("latex", "An exception occured within the creation of the latex formula.\nProcess '{}' took too long to finish:\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
QCoreApplication.translate("latex", "An exception occured within the creation of the latex formula.\nProcess '{}' took too long to finish:\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
||||||
.format(" ".join(process), str(out, 'utf8') + "\n" + str(err, 'utf8')))
|
.format(" ".join(process), output))
|
||||||
raise Exception(" ".join(process) + " process timed out:\n" + str(out, 'utf8') + "\n" + str(err, 'utf8'))
|
raise Exception(" ".join(process) + " process timed out:\n" + output)
|
||||||
|
|
||||||
def cleanup(self, export_path):
|
def cleanup(self, export_path):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue