Code source de code_beatrix.ipythonhelper.magic_scratch

# -*- coding: utf-8 -*-
"""
Magic command to handle files


:githublink:`%|py|6`
"""
from IPython.core.magic import magics_class, line_magic
from pyquickhelper.ipythonhelper import MagicCommandParser, MagicClassWithHelpers
from ..jsscripts.nbsnap import RenderSnap


[docs]@magics_class class MagicScratch(MagicClassWithHelpers): """ Defines magic commands to list the content of a folder .. versionadded:: 1.1 :githublink:`%|py|18` """
[docs] @staticmethod def snap_parser(): """ defines the way to parse the magic command ``%snap`` :githublink:`%|py|24` """ parser = MagicCommandParser(prog="snap", description='insert a snap window inside a notebook') parser.add_argument( '-f', '--file', type=str, default="", help='scratch or snap file to display') parser.add_argument( '-d', '--div', type=str, default="scratch_div_id", help='id for the HTML div') parser.add_argument( '-W', '--width', type=int, default=1000, help='window width') parser.add_argument( '-H', '--height', type=int, default=600, help='window height') return parser
[docs] @line_magic def snap(self, line): """ Defines ``%snap`` which inserts a :epkg:`snap` window inside a notebook. :githublink:`%|py|58` """ parser = self.get_parser(MagicScratch.snap_parser, "snap") args = self.get_args(line, parser) if args is not None: if args.file in [None, ""]: #filename = None pass else: raise NotImplementedError() iddiv = args.div h = str(args.height) w = str(args.width) return RenderSnap(h, w, iddiv) return None
[docs]def register_scratch_magics(ip): """ register magics function, can be called from a notebook :param ip: ip :githublink:`%|py|81` """ ip.register_magics(MagicScratch)