Show More
@@ -6,7 +6,40 b' from os.path import exists, isfile, splitext, abspath, join, isdir' | |||||
6 | from os import walk, sep |
|
6 | from os import walk, sep | |
7 |
|
7 | |||
8 |
|
8 | |||
9 |
class |
|
9 | class IFrame(object): | |
|
10 | """ | |||
|
11 | Generic class to embed an iframe in an IPython notebook | |||
|
12 | """ | |||
|
13 | ||||
|
14 | iframe = """ | |||
|
15 | <iframe | |||
|
16 | width="{width}" | |||
|
17 | height={height}" | |||
|
18 | src="{src}{params}" | |||
|
19 | frameborder="0" | |||
|
20 | allowfullscreen | |||
|
21 | ></iframe> | |||
|
22 | """ | |||
|
23 | ||||
|
24 | def __init__(self, src, width, height, **kwargs): | |||
|
25 | self.src = src | |||
|
26 | self.width = width | |||
|
27 | self.height = height | |||
|
28 | self.params = kwargs | |||
|
29 | ||||
|
30 | def _repr_html_(self): | |||
|
31 | """return the embed iframe""" | |||
|
32 | if self.params: | |||
|
33 | from urllib import urlencode | |||
|
34 | params = "?" + urlencode(self.params) | |||
|
35 | else: | |||
|
36 | params = "" | |||
|
37 | return self.iframe.format(src=self.src, | |||
|
38 | width=self.width, | |||
|
39 | height=self.height, | |||
|
40 | params=params) | |||
|
41 | ||||
|
42 | class YouTubeVideo(IFrame): | |||
10 | """Class for embedding a YouTube Video in an IPython session, based on its video id. |
|
43 | """Class for embedding a YouTube Video in an IPython session, based on its video id. | |
11 |
|
44 | |||
12 | e.g. to embed the video on this page: |
|
45 | e.g. to embed the video on this page: | |
@@ -31,27 +64,33 b' class YouTubeVideo(object):' | |||||
31 | """ |
|
64 | """ | |
32 |
|
65 | |||
33 | def __init__(self, id, width=400, height=300, **kwargs): |
|
66 | def __init__(self, id, width=400, height=300, **kwargs): | |
34 | self.id = id |
|
67 | src = "http://www.youtube.com/embed/{0}".format(id) | |
35 | self.width = width |
|
68 | super(YouTubeVideo, self).__init__(src, width, height, **kwargs) | |
36 | self.height = height |
|
|||
37 | self.params = kwargs |
|
|||
38 |
|
69 | |||
39 | def _repr_html_(self): |
|
70 | class VimeoVideo(IFrame): | |
40 | """return YouTube embed iframe for this video id""" |
|
71 | """ | |
41 | if self.params: |
|
72 | Class for embedding a Vimeo video in an IPython session, based on its video id. | |
42 | from urllib import urlencode # Deferred import |
|
73 | """ | |
43 | params = "?" + urlencode(self.params) |
|
74 | ||
44 | else: |
|
75 | def __init__(self, id, width=400, height=300, **kwargs): | |
45 | params = "" |
|
76 | src="http://player.vimeo.com/video/{0}".format(id) | |
46 | return """ |
|
77 | super(VimeoVideo, self).__init__(src, width, height, **kwargs) | |
47 | <iframe |
|
78 | ||
48 | width="%i" |
|
79 | class ScribdDocument(IFrame): | |
49 | height="%i" |
|
80 | """ | |
50 | src="http://www.youtube.com/embed/%s%s" |
|
81 | Class for embedding a Scribd document in an IPython session | |
51 | frameborder="0" |
|
82 | ||
52 | allowfullscreen |
|
83 | Use the start_page params to specify a starting point in the document | |
53 | ></iframe> |
|
84 | Use the view_mode params to specify display type one off scroll | slideshow | book | |
54 | """ % (self.width, self.height, self.id, params) |
|
85 | ||
|
86 | e.g to Display Wes' foundational paper about PANDAS in book mode from page 3 | |||
|
87 | ||||
|
88 | ScribdDocument(71048089, width=800, height=400, start_page=3, view_mode="book") | |||
|
89 | """ | |||
|
90 | ||||
|
91 | def __init__(self, id, width=400, height=300, **kwargs): | |||
|
92 | src="http://www.scribd.com/embeds/{0}/content".format(id) | |||
|
93 | super(ScribdDocument, self).__init__(src, width, height, **kwargs) | |||
55 |
|
94 | |||
56 | class FileLink(object): |
|
95 | class FileLink(object): | |
57 | """Class for embedding a local file link in an IPython session, based on path |
|
96 | """Class for embedding a local file link in an IPython session, based on path |
General Comments 0
You need to be logged in to leave comments.
Login now