Commits

Matthew Turk  committed 08972af

Sort of works, but it's not AJAX-y yet.

  • Participants
  • Parent commits 8150998

Comments (0)

Files changed (5)

File disp_types.py

+from yt.mods import *
+from yt.utilities.amr_utils import write_png_to_string
+import base64
 from abc import ABCMeta, abstractmethod, abstractproperty
 
 class DisplayType(object):
 
 display_types = DisplayTypeContainer()
 
-class ImageDisplay(DisplayType):
-    name = "image"
+class FRBDisplay(DisplayType):
+    name = "frb"
 
-    def __init__(self, size = 512):
-        self.size = size
+    def __init__(self, field = "Density"):
+        self.field = field
 
     def transmit(self, value):
         return ""
 
-    def represent(self):
-        return "<IMG SRC='' WIDTH='%s' HEIGHT='%s'>" % (self.size, self.size)
+    def represent(self, value = None):
+        if value is None: return "<IMG SRC=''>"
+        to_plot = apply_colormap(value[self.field], func = na.log10)
+        pngs = write_png_to_string(to_plot)
+        img_data = base64.b64encode(pngs)
+        data = "data:image/png;base64,%s" % img_data
+        return "<IMG SRC='%s' WIDTH='%s' HEIGHT='%s'>" % (
+            data, value.buff_size[0], value.buff_size[1])
           <h2>Result</h2>
         </div>
         <div class="span8">
-          {{!return_value.represent()}}
+          {{!return_value.represent(func_value)}}
         </div>
       </div>
       <div class="row">
 
 class Interactor(object):
     _setup = False
+    _value = None
     def __init__(self, *args, **kwargs):
         self.setup_arguments(*args, **kwargs)
 
         return bottle.static_file(path, "bootstrap/")
 
     def respond(self):
+        arglist = {}
+        print "Hello, responding"
         for name in self.parameters:
-            print "NAME %s : %s" % (name, bottle.request.forms.get(name))
-        print "FOUND", bottle.request.params.keys()
-        print "FOUND", bottle.request.forms.keys()
+            fv = bottle.request.forms.get(name)
+            print "NAME %s : %s" % (name, fv)
+            arglist[name] = self.parameters[name].cast(fv)
+        print arglist
+        self._value = self.func(**arglist)
+        print self._value
+        bottle.redirect("/")
 
     def index(self):
         template = open("index.html").read()
         tpl = bottle.SimpleTemplate(template)
-        tr = tpl.render(return_value = self.returns, input_values = self.parameters)
+        tr = tpl.render(return_value = self.returns,
+                        input_values = self.parameters,
+                        func_value = self._value
+                        )
+        self._value = None
         return tr
 

File simple_test.py

 
 @Interactor(coord = vt['float_range'](0.0, 1.0),
             axis = vt['item_list']('x', 'y', 'z'),
-            return_value = dt['image'](size = 512))
+            return_value = dt['frb'](field = "Density"))
 def slice_image(coord, axis):
     ax = {'x':0,'y':1,'z':2}
     sl = pf.h.slice(ax[axis], coord)
-    return sl.to_frb(1.0, 512)
+    frb = sl.to_frb(1.0, 512)
+    return frb
 
 slice_image.serve()

File var_types.py

 
     def cast(self, val):
         if val not in self.items: raise KeyError
+        return val