Hide keyboard shortcuts

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 

9 

10 

11@magics_class 

12class MagicScratch(MagicClassWithHelpers): 

13 

14 """ 

15 Defines magic commands to list the content of a folder 

16 

17 .. versionadded:: 1.1 

18 """ 

19 

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 

52 

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) 

61 

62 if args is not None: 

63 if args.file in [None, ""]: 

64 #filename = None 

65 pass 

66 else: 

67 raise NotImplementedError() 

68 

69 iddiv = args.div 

70 h = str(args.height) 

71 w = str(args.width) 

72 return RenderSnap(h, w, iddiv) 

73 return None 

74 

75 

76def register_scratch_magics(ip): 

77 """ 

78 register magics function, can be called from a notebook 

79 

80 @param ip ip 

81 """ 

82 ip.register_magics(MagicScratch)