[Yt-svn] commit/yt: MatthewTurk: A new BETA sequence that puts pylab in the main namespace and turns on
Bitbucket
commits-noreply at bitbucket.org
Wed Apr 27 16:56:33 PDT 2011
1 new changeset in yt:
http://bitbucket.org/yt_analysis/yt/changeset/0e0ef5ed9506/
changeset: r4218:0e0ef5ed9506
branch: yt
user: MatthewTurk
date: 2011-04-28 01:54:20
summary: A new BETA sequence that puts pylab in the main namespace and turns on
interactivity, with images showing up in the cell results.
affected #: 2 files (1.8 KB)
--- a/yt/gui/reason/extdirect_repl.py Wed Apr 27 18:22:51 2011 -0400
+++ b/yt/gui/reason/extdirect_repl.py Wed Apr 27 19:54:20 2011 -0400
@@ -35,6 +35,10 @@
import urllib2
import pprint
import traceback
+import tempfile
+import base64
+import imp
+import threading
from yt.funcs import *
from yt.utilities.logger import ytLogger, ufstring
@@ -46,7 +50,6 @@
PayloadHandler
from .bottle import response, request, route
from .basic_repl import ProgrammaticREPL
-import threading
try:
import pygments
@@ -92,6 +95,52 @@
lockit = MethodLock()
+def deliver_image(im):
+ if hasattr(im, 'read'):
+ img_data = im.read()
+ elif isinstance(im, types.StringTypes) and \
+ im.endswith(".png"):
+ img_data = base64.b64encode(open(im).read())
+ elif isinstance(im, types.StringTypes):
+ img_data = im
+ else:
+ raise RuntimeError
+ ph = PayloadHandler()
+ payload = {'type':'png_string',
+ 'image_data':img_data}
+ ph.add_payload(payload)
+
+def reason_pylab():
+ def _canvas_deliver(canvas):
+ tf = tempfile.TemporaryFile()
+ canvas.print_png(tf)
+ tf.seek(0)
+ img_data = base64.b64encode(tf.read())
+ tf.close()
+ deliver_image(img_data)
+ def reason_draw_if_interactive():
+ if matplotlib.is_interactive():
+ figManager = Gcf.get_active()
+ if figManager is not None:
+ _canvas_deliver(figManager.canvas)
+ def reason_show(mainloop = True):
+ # We ignore mainloop here
+ for manager in Gcf.get_all_fig_managers():
+ _canvas_deliver(manager.canvas)
+ # Matplotlib has very nice backend overriding.
+ # We should really use that. This is just a hack.
+ new_agg = imp.new_module("reason_agg")
+ import matplotlib.backends.backend_agg as bagg
+ new_agg.__dict__.update(bagg.__dict__)
+ new_agg.__dict__.update(
+ {'show': reason_show,
+ 'draw_if_interactive': reason_draw_if_interactive})
+ sys.modules["reason_agg"] = new_agg
+ bagg.draw_if_interactive = reason_draw_if_interactive
+ from matplotlib._pylab_helpers import Gcf
+ import pylab, matplotlib
+ pylab.switch_backend("module://reason_agg")
+
class ExtDirectREPL(ProgrammaticREPL, BottleDirectRouter):
_skip_expose = ('index')
my_name = "ExtDirectREPL"
@@ -132,9 +181,11 @@
self.payload_handler = PayloadHandler()
# Now we load up all the yt.mods stuff, but only after we've finished
# setting up.
- self.execute("from yt.mods import *")
+ reason_pylab()
+ self.execute("from yt.mods import *\nimport pylab\npylab.ion()")
self.execute("from yt.data_objects.static_output import _cached_pfs", hide = True)
self.locals['load_script'] = ext_load_script
+ self.locals['deliver_image'] = deliver_image
self._setup_logging_handlers()
# Setup our heartbeat
--- a/yt/visualization/plot_window.py Wed Apr 27 18:22:51 2011 -0400
+++ b/yt/visualization/plot_window.py Wed Apr 27 19:54:20 2011 -0400
@@ -375,7 +375,6 @@
for v in tick_locs:
p = height - height * (v - mi)/(ma-mi)
ticks.append((p,v,"%0.3e" % (v)))
- print "Ticking: ", p, v, v
return ticks
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list