Skip to content

Commit

Permalink
Remove custom Qt templates
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Jul 30, 2022
1 parent 3ee6127 commit 062830b
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 40 deletions.
23 changes: 3 additions & 20 deletions nbconvert/exporters/qt_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import tempfile

from jupyter_core.paths import jupyter_path
from traitlets import default

from .html import HTMLExporter
Expand All @@ -12,27 +11,14 @@ class QtExporter(HTMLExporter):

paginate = None

def __init__(self, *args, **kwargs):
self.format = self.output_mimetype.split("/")[-1]
super().__init__(*args, **kwargs)

@default("file_extension")
def _file_extension_default(self):
return "." + self.format

@default("template_name")
def _template_name_default(self):
return "qt" + self.format

@default("template_data_paths")
def _template_data_paths_default(self):
return jupyter_path("nbconvert", "templates", "qt" + self.format)
return ".html"

def _check_launch_reqs(self):
if sys.platform.startswith("win") and self.format == "png":
raise RuntimeError("Exporting to PNG using Qt is currently not supported on Windows.")
from .qt_screenshot import QT_INSTALLED

if not QT_INSTALLED:
raise RuntimeError(
f"PyQtWebEngine is not installed to support Qt {self.format.upper()} conversion. "
Expand All @@ -42,15 +28,12 @@ def _check_launch_reqs(self):

return QtScreenshot

def run_pyqtwebengine(self, html):
"""Run pyqtwebengine."""

def _run_pyqtwebengine(self, html):
ext = ".html"
temp_file = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
filename = f"{temp_file.name[:-len(ext)]}.{self.format}"
with temp_file:
temp_file.write(html.encode("utf-8"))

try:
QtScreenshot = self._check_launch_reqs()
s = QtScreenshot()
Expand All @@ -65,7 +48,7 @@ def from_notebook_node(self, nb, resources=None, **kw):
html, resources = super().from_notebook_node(nb, resources=resources, **kw)

self.log.info(f"Building {self.format.upper()}")
data = self.run_pyqtwebengine(html)
data = self._run_pyqtwebengine(html)
self.log.info(f"{self.format.upper()} successfully created")

# convert output extension
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/exporters/qtpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QtPDFExporter(QtExporter):
"""

export_from_notebook = "PDF via HTML"
format = "pdf"

paginate = Bool(
True,
Expand All @@ -27,5 +28,3 @@ class QtPDFExporter(QtExporter):
Set to True to match behavior of LaTeX based PDF generator
""",
).tag(config=True)

output_mimetype = "application/pdf"
3 changes: 1 addition & 2 deletions nbconvert/exporters/qtpng.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ class QtPNGExporter(QtExporter):
"""

export_from_notebook = "PNG via HTML"

output_mimetype = "image/png"
format = "png"
2 changes: 0 additions & 2 deletions nbconvert/exporters/webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class WebPDFExporter(HTMLExporter):
""",
).tag(config=True)

output_mimetype = "text/html"

@default("file_extension")
def _file_extension_default(self):
return ".html"
Expand Down
6 changes: 0 additions & 6 deletions share/templates/qtpdf/conf.json

This file was deleted.

1 change: 0 additions & 1 deletion share/templates/qtpdf/index.pdf.j2

This file was deleted.

6 changes: 0 additions & 6 deletions share/templates/qtpng/conf.json

This file was deleted.

1 change: 0 additions & 1 deletion share/templates/qtpng/index.png.j2

This file was deleted.

0 comments on commit 062830b

Please sign in to comment.