diff --git a/IPython/core/display.py b/IPython/core/display.py
index a45466e..e45f32a 100644
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -740,12 +740,24 @@ class ProgressBar(DisplayObject):
total : int
maximum size of the progressbar
"""
- self._display_id = hexlify(os.urandom(8)).decode('ascii')
self.total = total
self._progress = 0
+ self.html_width = '60ex'
+ self.text_width = 60
+ self._display_id = hexlify(os.urandom(8)).decode('ascii')
+
+ def __repr__(self):
+ fraction = self.progress / self.total
+ filled = '=' * int(fraction * self.text_width)
+ rest = ' ' * (self.text_width - len(filled))
+ return '[{}{}] {}/{}'.format(
+ filled, rest,
+ self.progress, self.total,
+ )
def _repr_html_(self):
- return "".format(self.total, self.progress)
+ return "".format(
+ self.html_width, self.total, self.progress)
def display(self):
display(self, display_id=self._display_id)
diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py
index ec7b5bc..05f4529 100644
--- a/IPython/core/tests/test_display.py
+++ b/IPython/core/tests/test_display.py
@@ -196,8 +196,7 @@ def test_displayobject_repr():
def test_progress():
p = display.ProgressBar(10)
- nt.assert_equal(repr(p), '')
- p._show_mem_addr = True
+ nt.assert_true('0/10' in repr(p))
nt.assert_equal(p._repr_html_(), "")
def test_json():
diff --git a/examples/IPython Kernel/Updating Displays.ipynb b/examples/IPython Kernel/Updating Displays.ipynb
index ad8d912..1ff75c4 100644
--- a/examples/IPython Kernel/Updating Displays.ipynb
+++ b/examples/IPython Kernel/Updating Displays.ipynb
@@ -222,21 +222,16 @@
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
- "\n",
- " 10 / 10\n",
- " "
+ ""
],
"text/plain": [
- "[============================================================] 10/10"
+ ""
]
},
"metadata": {},
@@ -244,43 +239,7 @@
}
],
"source": [
- "import os\n",
- "from binascii import hexlify\n",
- "\n",
- "class ProgressBar(object):\n",
- " def __init__(self, capacity):\n",
- " self.progress = 0\n",
- " self.capacity = capacity\n",
- " self.html_width = '60ex'\n",
- " self.text_width = 60\n",
- " self._display_id = hexlify(os.urandom(8)).decode('ascii')\n",
- " \n",
- " def __repr__(self):\n",
- " fraction = self.progress / self.capacity\n",
- " filled = '=' * int(fraction * self.text_width)\n",
- " rest = ' ' * (self.text_width - len(filled))\n",
- " return '[{}{}] {}/{}'.format(\n",
- " filled, rest,\n",
- " self.progress, self.capacity,\n",
- " )\n",
- " \n",
- " def _repr_html_(self):\n",
- " return \"\"\"\n",
- " {progress} / {capacity}\n",
- " \"\"\".format(\n",
- " progress=self.progress,\n",
- " capacity=self.capacity,\n",
- " width=self.html_width,\n",
- " )\n",
- " \n",
- " def display(self):\n",
- " display(self, display_id=self._display_id)\n",
- " \n",
- " def update(self):\n",
- " update_display(self, display_id=self._display_id)\n",
+ "from IPython.display import ProgressBar\n",
"\n",
"bar = ProgressBar(10)\n",
"bar.display()"
@@ -295,21 +254,16 @@
},
{
"cell_type": "code",
- "execution_count": 36,
+ "execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
- "\n",
- " 10 / 10\n",
- " "
+ ""
],
"text/plain": [
- "[============================================================] 10/10"
+ ""
]
},
"metadata": {},
@@ -351,7 +305,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.5.1"
+ "version": "3.6.2"
}
},
"nbformat": 4,