Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Magic command to handle files
5"""
6from IPython.core.magic import magics_class, line_magic
7from pyquickhelper.ipythonhelper import MagicCommandParser, MagicClassWithHelpers
8from ..jsscripts.nbsnap import RenderSnap
11@magics_class
12class MagicScratch(MagicClassWithHelpers):
14 """
15 Defines magic commands to list the content of a folder
17 .. versionadded:: 1.1
18 """
20 @staticmethod
21 def snap_parser():
22 """
23 defines the way to parse the magic command ``%snap``
24 """
25 parser = MagicCommandParser(prog="snap",
26 description='insert a snap window inside a notebook')
27 parser.add_argument(
28 '-f',
29 '--file',
30 type=str,
31 default="",
32 help='scratch or snap file to display')
33 parser.add_argument(
34 '-d',
35 '--div',
36 type=str,
37 default="scratch_div_id",
38 help='id for the HTML div')
39 parser.add_argument(
40 '-W',
41 '--width',
42 type=int,
43 default=1000,
44 help='window width')
45 parser.add_argument(
46 '-H',
47 '--height',
48 type=int,
49 default=600,
50 help='window height')
51 return parser
53 @line_magic
54 def snap(self, line):
55 """
56 Defines ``%snap``
57 which inserts a :epkg:`snap` window inside a notebook.
58 """
59 parser = self.get_parser(MagicScratch.snap_parser, "snap")
60 args = self.get_args(line, parser)
62 if args is not None:
63 if args.file in [None, ""]:
64 #filename = None
65 pass
66 else:
67 raise NotImplementedError()
69 iddiv = args.div
70 h = str(args.height)
71 w = str(args.width)
72 return RenderSnap(h, w, iddiv)
73 return None
76def register_scratch_magics(ip):
77 """
78 register magics function, can be called from a notebook
80 @param ip ip
81 """
82 ip.register_magics(MagicScratch)