def __init__(self, filename, fileobj, **kwargs):
super(FileView, self).__init__(disabled=True)
self.filename = filename
self._string = None
self._current_pos = 0
self.load_more_button = None
self.textarea = None
self._fileobj = fileobj
# For files that need to be fetched, make a download button
if hasattr(fileobj, '_fetched') and not fileobj._fetched:
self.download_button = ipy.Button(description='Download')
self.children = [self.download_button]
self.download_button.on_click(self.handle_download_click)
# if it's file-like, get the _contents
elif hasattr(fileobj, 'read'):
try:
self._string = fileobj.read()
except UnicodeDecodeError:
self._string = '[NOT SHOWN - UNABLE TO DECODE FILE]'
self.render_string()
# Just display a string
else:
self._string = fileobj
self.render_string()
评论列表
文章目录