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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

#-*- coding: utf-8 -*- 

""" 

@file 

@brief Magic command to handle files 

""" 

from IPython.core.magic import magics_class, line_magic 

from pyquickhelper.ipythonhelper import MagicCommandParser, MagicClassWithHelpers 

from ..jsscripts.nbsnap import RenderSnap 

 

 

@magics_class 

class MagicScratch(MagicClassWithHelpers): 

 

""" 

Defines magic commands to list the content of a folder 

 

.. versionadded:: 1.1 

""" 

 

@staticmethod 

def snap_parser(): 

""" 

defines the way to parse the magic command ``%snap`` 

""" 

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 

 

@line_magic 

def snap(self, line): 

""" 

defines ``%snap`` 

which inserts a snap window inside a notebook 

""" 

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) 

 

 

def register_scratch_magics(ip): 

""" 

register magics function, can be called from a notebook 

 

@param ip ip 

""" 

ip.register_magics(MagicScratch)