Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable sliders #426

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .ipynb_checkpoints/TestNotebook-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import vcs\n",
"import cdms2\n",
"vcs.download_sample_data_files()\n",
"f=cdms2.open(vcs.sample_data+\"/clt.nc\")\n",
"s=f(\"clt\")\n",
"x=vcs.init(bg=True)\n",
"x.plot(s)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
40 changes: 40 additions & 0 deletions TestNotebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import vcs\n",
"import cdms2\n",
"vcs.download_sample_data_files()\n",
"f=cdms2.open(vcs.sample_data+\"/clt.nc\")\n",
"s=f(\"clt\")\n",
"x=vcs.init(bg=True)\n",
"x.plot(s)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
35 changes: 21 additions & 14 deletions vcs/displayplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def get_update_array_kw(disp, array, widgets, debug_target=None):
return kw


class IPythonDisplay(object):
def __init__(self, png):
self.png = png

def _repr_png_(self):
return self.png


class Dp(vcs.bestMatch):

"""
Expand Down Expand Up @@ -306,10 +314,16 @@ def generate_sliders(self, debug):
return widgets

def _repr_png_(self):
SLIDERS_ENABLED = False
st = None
debug = False
if not HAVE_IPYWIDGETS:
debug = False
tmp = tempfile.mktemp() + ".png"
self._parent.png(tmp)
f = open(tmp, "rb")
st = f.read()
f.close()
if HAVE_IPY:
sidecar_on = True
if HAVE_SIDECAR:
Expand All @@ -329,9 +343,13 @@ def _repr_png_(self):
layout={'border': '1px solid black'})
else:
self._parent._display_target_out = None
widgets = self.generate_sliders(debug)
vbox = ipywidgets.VBox(
widgets + [self._parent._display_target_image])
if SLIDERS_ENABLED:
widgets = self.generate_sliders(debug)
self._parent._display_target_image.value = st
vbox = ipywidgets.VBox(
widgets + [self._parent._display_target_image])
else:
vbox = IPythonDisplay(st)
if HAVE_SIDECAR and sidecar_on:
with self._parent._display_target:
IPython.display.clear_output()
Expand All @@ -341,18 +359,7 @@ def _repr_png_(self):
IPython.display.display(vbox)
else:
IPython.display.clear_output()
tmp = tempfile.mktemp() + ".png"
self._parent.png(tmp)
f = open(tmp, "rb")
st = f.read()
f.close()
self._parent._display_target_image.value = st
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this line outside of the SLIDERS_ENABLED section above.

return None
tmp = tempfile.mktemp() + ".png"
self._parent.png(tmp)
f = open(tmp, "rb")
st = f.read()
f.close()
return st
# TODO: html,json,jpeg,png,svg,latex

Expand Down