simetri.notebook

This module contains the functions to display the output of the canvas in the Jupyter notebook.

 1"""This module contains the functions to display the output of the canvas
 2in the Jupyter notebook."""
 3
 4import tempfile
 5import shutil
 6import os
 7
 8import fitz
 9from IPython.display import Image
10from IPython.display import display as ipy_display
11
12
13def display(canvas):
14    """Show the output of the canvas in the Jupyter notebook.
15
16    Args:
17        canvas: The canvas object to be displayed.
18
19    """
20    # open a temporary directory
21    with tempfile.TemporaryDirectory(
22        ignore_cleanup_errors=True, delete=True
23    ) as tmpdirname:
24        file_name = next(tempfile._get_candidate_names())
25        file_path = os.path.join(tmpdirname, file_name + ".png")
26        canvas.save(file_path, show=False, print_output=False)
27        ipy_display(Image(file_path))
28
29    shutil.rmtree(tmpdirname, ignore_errors=True)
def display(canvas):
14def display(canvas):
15    """Show the output of the canvas in the Jupyter notebook.
16
17    Args:
18        canvas: The canvas object to be displayed.
19
20    """
21    # open a temporary directory
22    with tempfile.TemporaryDirectory(
23        ignore_cleanup_errors=True, delete=True
24    ) as tmpdirname:
25        file_name = next(tempfile._get_candidate_names())
26        file_path = os.path.join(tmpdirname, file_name + ".png")
27        canvas.save(file_path, show=False, print_output=False)
28        ipy_display(Image(file_path))
29
30    shutil.rmtree(tmpdirname, ignore_errors=True)

Show the output of the canvas in the Jupyter notebook.

Arguments:
  • canvas: The canvas object to be displayed.