Skip to content

Commit

Permalink
Fix ipython#11328 add height and width parameters to core.display.Video
Browse files Browse the repository at this point in the history
  • Loading branch information
Nestor Arias committed Oct 2, 2018
1 parent 194d1d7 commit d8b6f08
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions IPython/core/display.py
Expand Up @@ -268,12 +268,12 @@ def display(*objs, include=None, exclude=None, metadata=None, transient=None, di
"""
from IPython.core.interactiveshell import InteractiveShell

if not InteractiveShell.initialized():
# Directly print objects.
print(*objs)
return

raw = kwargs.pop('raw', False)
if transient is None:
transient = {}
Expand Down Expand Up @@ -353,10 +353,10 @@ def __repr__(self):

def display(self, obj, **kwargs):
"""Make a new display with my id, updating existing instances.
Parameters
----------
obj:
object to display
**kwargs:
Expand All @@ -366,10 +366,10 @@ def display(self, obj, **kwargs):

def update(self, obj, **kwargs):
"""Update existing displays with my id
Parameters
----------
obj:
object to display
**kwargs:
Expand Down Expand Up @@ -729,16 +729,16 @@ def data(self, svg):
pass
svg = cast_unicode(svg)
self._data = svg

def _repr_svg_(self):
return self._data_and_metadata()

class ProgressBar(DisplayObject):
"""Progressbar supports displaying a progressbar like element
"""Progressbar supports displaying a progressbar like element
"""
def __init__(self, total):
"""Creates a new progressbar
Parameters
----------
total : int
Expand Down Expand Up @@ -818,7 +818,7 @@ def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=
metadata: dict
Specify extra metadata to attach to the json display object.
root : str
The name of the root element of the JSON tree
The name of the root element of the JSON tree
"""
self.metadata = {
'expanded': expanded,
Expand Down Expand Up @@ -878,7 +878,7 @@ class GeoJSON(JSON):
Scalar types (None, number, string) are not allowed, only dict containers.
"""

def __init__(self, *args, **kwargs):
"""Create a GeoJSON display object given raw data.
Expand Down Expand Up @@ -927,7 +927,7 @@ def __init__(self, *args, **kwargs):
the GeoJSON object.
"""

super(GeoJSON, self).__init__(*args, **kwargs)


Expand Down Expand Up @@ -1159,7 +1159,7 @@ def __init__(self, data=None, url=None, filename=None, format=None,
self.height = height
self.retina = retina
self.unconfined = unconfined
super(Image, self).__init__(data=data, url=url, filename=filename,
super(Image, self).__init__(data=data, url=url, filename=filename,
metadata=metadata)

if self.width is None and self.metadata.get('width', {}):
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def _find_ext(self, s):

class Video(DisplayObject):

def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=None):
def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=None, width=None, height=None):
"""Create a video object given raw data or an URL.
When this object is returned by an input cell or passed to the
Expand Down Expand Up @@ -1314,16 +1314,23 @@ def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=Non

self.mimetype = mimetype
self.embed = embed
self.width = width
self.height = height
super(Video, self).__init__(data=data, url=url, filename=filename)

def _repr_html_(self):
width = height = ''
if self.width:
width = ' width="%d"' % self.width
if self.height:
height = ' height="%d"' % self.height
# External URLs and potentially local files are not embedded into the
# notebook output.
if not self.embed:
url = self.url if self.url is not None else self.filename
output = """<video src="{0}" controls>
output = """<video src="{0}"{1}{2} controls>
Your browser does not support the <code>video</code> element.
</video>""".format(url)
</video>""".format(url, width, height)
return output

# Embedded videos are base64-encoded.
Expand All @@ -1342,10 +1349,10 @@ def _repr_html_(self):
else:
b64_video = b2a_base64(video).decode('ascii').rstrip()

output = """<video controls>
output = """<video{2}{3} controls>
<source src="data:{0};base64,{1}" type="{0}">
Your browser does not support the video tag.
</video>""".format(mimetype, b64_video)
</video>""".format(mimetype, b64_video, width, height)
return output

def reload(self):
Expand Down

0 comments on commit d8b6f08

Please sign in to comment.